Skip to content

Commit 334387b

Browse files
committed
Fix #52093: openssl_csr_sign truncates $serial
We use `ASN1_INTEGER_set_int64()` if supported[1], to avoid the truncation of the integer. [1] <https://www.openssl.org/docs/man1.1.0/man3/ASN1_INTEGER_set_int64.html#HISTORY> Closes GH-7209.
1 parent d7db570 commit 334387b

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ PHP NEWS
1717
(cmb)
1818
. Fixed bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone). (cmb)
1919

20+
- OpenSSL:
21+
. Fixed bug #52093 (openssl_csr_sign truncates $serial). (cmb)
22+
2023
- PCRE:
2124
. Fixed bug #81101 (PCRE2 10.37 shows unexpected result). (Anatol)
2225

ext/openssl/openssl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,8 +3524,11 @@ PHP_FUNCTION(openssl_csr_sign)
35243524
goto cleanup;
35253525
}
35263526

3527-
3528-
ASN1_INTEGER_set(X509_get_serialNumber(new_cert), (long)serial);
3527+
#if PHP_OPENSSL_API_VERSION >= 0x10100
3528+
ASN1_INTEGER_set_int64(X509_get_serialNumber(new_cert), serial);
3529+
#else
3530+
ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial);
3531+
#endif
35293532

35303533
X509_set_subject_name(new_cert, X509_REQ_get_subject_name(csr));
35313534

ext/openssl/tests/bug52093.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #52093 (openssl_csr_sign truncates $serial)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("openssl")) print "skip";
6+
if (PHP_INT_SIZE !== 8) die("skip this test is for 64bit platforms only");
7+
?>
8+
--FILE--
9+
<?php
10+
$dn = array(
11+
"countryName" => "BR",
12+
"stateOrProvinceName" => "Rio Grande do Sul",
13+
"localityName" => "Porto Alegre",
14+
"commonName" => "Henrique do N. Angelo",
15+
"emailAddress" => "[email protected]"
16+
);
17+
18+
$privkey = openssl_pkey_new();
19+
$csr = openssl_csr_new($dn, $privkey);
20+
$cert = openssl_csr_sign($csr, null, $privkey, 365, [], PHP_INT_MAX);
21+
var_dump(openssl_x509_parse($cert)['serialNumber']);
22+
?>
23+
--EXPECT--
24+
string(19) "9223372036854775807"

0 commit comments

Comments
 (0)