Skip to content

Commit 7e3a8ef

Browse files
committed
Merge branch 'pull-request/1755'
* pull-request/1755: Fix bug #71519 Add 'serialNumberHex' variable to openssl_x509_parse
2 parents aea1fd2 + 2854f32 commit 7e3a8ef

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ PHP NEWS
7171
. Fixed bug #73800 (sporadic segfault with MYSQLI_OPT_INT_AND_FLOAT_NATIVE).
7272
(vanviegen)
7373

74+
- OpenSSL:
75+
. Fixed bug #71519 (add serial hex to return value array). (xrobau)
76+
7477
- PCRE:
7578
. Fixed bug #61780 (Inconsistent PCRE captures in match results). (cmb)
7679

ext/openssl/openssl.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,7 @@ PHP_FUNCTION(openssl_x509_parse)
22652265
char *extname;
22662266
BIO *bio_out;
22672267
BUF_MEM *bio_buf;
2268+
char * hexserial;
22682269
char buf[256];
22692270

22702271
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &zcert, &useshortnames) == FAILURE) {
@@ -2294,6 +2295,18 @@ PHP_FUNCTION(openssl_x509_parse)
22942295

22952296
add_assoc_string(return_value, "serialNumber", i2s_ASN1_INTEGER(NULL, X509_get_serialNumber(cert)));
22962297

2298+
/* Return the hex representation of the serial number, as defined by OpenSSL */
2299+
hexserial = BN_bn2hex(ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), NULL));
2300+
2301+
/* If we received null back from BN_bn2hex, there was a critical error in openssl,
2302+
* and we should not continue.
2303+
*/
2304+
if (!hexserial) {
2305+
RETURN_FALSE;
2306+
}
2307+
add_assoc_string(return_value, "serialNumberHex", hexserial);
2308+
OPENSSL_free(hexserial);
2309+
22972310
add_assoc_asn1_string(return_value, "validFrom", X509_get_notBefore(cert));
22982311
add_assoc_asn1_string(return_value, "validTo", X509_get_notAfter(cert));
22992312

ext/openssl/tests/openssl_x509_parse_basic.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var_dump(openssl_x509_parse($cert));
2020
var_dump(openssl_x509_parse($cert, false));
2121
?>
2222
--EXPECTF--
23-
array(15) {
23+
array(16) {
2424
["name"]=>
2525
string(96) "/C=BR/ST=Rio Grande do Sul/L=Porto Alegre/CN=Henrique do N. Angelo/[email protected]"
2626
["subject"]=>
@@ -55,6 +55,8 @@ array(15) {
5555
int(2)
5656
["serialNumber"]=>
5757
string(20) "12593567369101004962"
58+
["serialNumberHex"]=>
59+
string(16) "AEC556CC723750A2"
5860
["validFrom"]=>
5961
string(13) "080630102843Z"
6062
["validTo"]=>
@@ -166,7 +168,7 @@ serial:AE:C5:56:CC:72:37:50:A2
166168
string(7) "CA:TRUE"
167169
}
168170
}
169-
array(15) {
171+
array(16) {
170172
["name"]=>
171173
string(96) "/C=BR/ST=Rio Grande do Sul/L=Porto Alegre/CN=Henrique do N. Angelo/[email protected]"
172174
["subject"]=>
@@ -201,6 +203,8 @@ array(15) {
201203
int(2)
202204
["serialNumber"]=>
203205
string(20) "12593567369101004962"
206+
["serialNumberHex"]=>
207+
string(16) "AEC556CC723750A2"
204208
["validFrom"]=>
205209
string(13) "080630102843Z"
206210
["validTo"]=>

0 commit comments

Comments
 (0)