Skip to content

Commit 7e3162d

Browse files
committed
Switch a separate entry in the return value named "criticalExtensions" which contains the names of any critical extensions
1 parent c678cca commit 7e3162d

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

ext/openssl/openssl.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ PHP_FUNCTION(openssl_x509_parse)
10031003
bool useshortnames = 1;
10041004
char * tmpstr;
10051005
zval subitem;
1006+
zval critext;
1007+
int critcount = 0;
10061008
X509_EXTENSION *extension;
10071009
X509_NAME *subject_name;
10081010
char *cert_name;
@@ -1014,8 +1016,6 @@ PHP_FUNCTION(openssl_x509_parse)
10141016
char *str_serial;
10151017
char *hex_serial;
10161018
char buf[256];
1017-
char *crit_name = NULL;
1018-
int crit_len = 0;
10191019

10201020
ZEND_PARSE_PARAMETERS_START(1, 2)
10211021
Z_PARAM_OBJ_OF_CLASS_OR_STR(cert_obj, php_openssl_certificate_ce, cert_str)
@@ -1117,6 +1117,7 @@ PHP_FUNCTION(openssl_x509_parse)
11171117
add_assoc_zval(return_value, "purposes", &subitem);
11181118

11191119
array_init(&subitem);
1120+
array_init(&critext);
11201121

11211122
for (i = 0; i < X509_get_ext_count(cert); i++) {
11221123
int nid;
@@ -1129,19 +1130,8 @@ PHP_FUNCTION(openssl_x509_parse)
11291130
extname = buf;
11301131
}
11311132
if (X509_EXTENSION_get_critical(extension)) {
1132-
int new_len = strlen(extname) + 10;
1133-
if (new_len > crit_len) {
1134-
if (crit_name) {
1135-
efree(crit_name);
1136-
}
1137-
crit_len = new_len;
1138-
crit_name = emalloc(crit_len);
1139-
}
1140-
if (crit_name) {
1141-
strcpy(crit_name, extname);
1142-
strcat(crit_name, ":critical");
1143-
add_assoc_bool(&subitem, crit_name, 1);
1144-
}
1133+
add_next_index_string(&critext, extname);
1134+
critcount++;
11451135
}
11461136

11471137
bio_out = BIO_new(BIO_s_mem());
@@ -1167,8 +1157,8 @@ PHP_FUNCTION(openssl_x509_parse)
11671157
BIO_free(bio_out);
11681158
}
11691159
add_assoc_zval(return_value, "extensions", &subitem);
1170-
if (crit_name) {
1171-
efree(crit_name);
1160+
if (critcount > 0) {
1161+
add_assoc_zval(return_value, "criticalExtensions", &critext);
11721162
}
11731163
if (cert_str) {
11741164
X509_free(cert);
@@ -1179,9 +1169,6 @@ PHP_FUNCTION(openssl_x509_parse)
11791169
zval_ptr_dtor(&subitem);
11801170
err:
11811171
zend_array_destroy(Z_ARR_P(return_value));
1182-
if (crit_name) {
1183-
efree(crit_name);
1184-
}
11851172
if (cert_str) {
11861173
X509_free(cert);
11871174
}

ext/openssl/tests/openssl_x509_parse_basic.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,14 @@ array(16) {
158158
string(59) "DB:7E:40:72:BD:5C:35:85:EC:29:29:81:12:E8:62:68:6A:B7:3F:7D"
159159
["authorityKeyIdentifier"]=>
160160
string(%d) "DB:7E:40:72:BD:5C:35:85:EC:29:29:81:12:E8:62:68:6A:B7:3F:7D"
161-
["basicConstraints:critical"]=>
162-
bool(true)
163161
["basicConstraints"]=>
164162
string(7) "CA:TRUE"
165163
}
164+
["criticalExtensions"]=>
165+
array(1) {
166+
[0]=>
167+
string(16) "basicConstraints"
168+
}
166169
}
167170
array(16) {
168171
["name"]=>

0 commit comments

Comments
 (0)