Skip to content

Commit 2d42423

Browse files
committed
Merge branch 'pull-request/1755'
* pull-request/1755: Fix bug #71519 Add 'serialNumberHex' variable to openssl_x509_parse
1 parent 3a79f35 commit 2d42423

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

NEWS

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2017 PHP 7.0.16
44

5+
- OpenSSL:
6+
. Fixed bug #71519 (add serial hex to return value array). (xrobau)
7+
58
- Phar:
69
. Fixed bug #70417 (PharData::compress() doesn't close temp file). (cmb)
710

8-
- ZIP:
9-
. Fixed bug #70103 (ZipArchive::addGlob ignores remove_all_path option). (cmb)
10-
1111
- Session:
1212
. Fixed bug #69582 (session not readable by root in CLI). (EvgeniySpinov)
1313

1414
- Standard:
1515
. Fixed bug #69442 (closing of fd incorrect when PTS enabled). (jaytaph)
1616

17+
- ZIP:
18+
. Fixed bug #70103 (ZipArchive::addGlob ignores remove_all_path option). (cmb)
19+
1720
19 Jan 2017 PHP 7.0.15
1821

1922
- Core:

ext/openssl/openssl.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ PHP_FUNCTION(openssl_x509_parse)
20042004
char *extname;
20052005
BIO *bio_out;
20062006
BUF_MEM *bio_buf;
2007+
char * hexserial;
20072008
char buf[256];
20082009

20092010
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &zcert, &useshortnames) == FAILURE) {
@@ -2033,6 +2034,18 @@ PHP_FUNCTION(openssl_x509_parse)
20332034

20342035
add_assoc_string(return_value, "serialNumber", i2s_ASN1_INTEGER(NULL, X509_get_serialNumber(cert)));
20352036

2037+
/* Return the hex representation of the serial number, as defined by OpenSSL */
2038+
hexserial = BN_bn2hex(ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), NULL));
2039+
2040+
/* If we received null back from BN_bn2hex, there was a critical error in openssl,
2041+
* and we should not continue.
2042+
*/
2043+
if (!hexserial) {
2044+
RETURN_FALSE;
2045+
}
2046+
add_assoc_string(return_value, "serialNumberHex", hexserial);
2047+
OPENSSL_free(hexserial);
2048+
20362049
add_assoc_asn1_string(return_value, "validFrom", X509_get_notBefore(cert));
20372050
add_assoc_asn1_string(return_value, "validTo", X509_get_notAfter(cert));
20382051

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/emailAddress=hnangelo@php.net"
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/emailAddress=hnangelo@php.net"
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)