]> granicus.if.org Git - php/commitdiff
mproced openssl_x509_parse() to return extensions in readable form
authorDmitry Stogov <dmitry@php.net>
Wed, 11 Jul 2007 12:18:14 +0000 (12:18 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 11 Jul 2007 12:18:14 +0000 (12:18 +0000)
NEWS
ext/openssl/openssl.c
ext/openssl/tests/bug28382.phpt

diff --git a/NEWS b/NEWS
index ccf610c838faf17f9a9eb33e1e148450d3e00c83..404059920d4fededc0024c7e1a1980b0a8a6f345 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ PHP                                                                        NEWS
 - Upgraded PCRE to version 7.2 (Nuno)
 - Updated timezone database to version 2007.6. (Derick)
 
+- Improced openssl_x509_parse() to return extensions in readable form. (Dmitry)
 - Improved fix for MOPB-03-2007. (Ilia)
 - Corrected fix for CVE-2007-2872. (Ilia)
 - Enabled statement cache for non-persistent OCI8 connections.
@@ -30,6 +31,7 @@ PHP                                                                        NEWS
 - Added CURLOPT_PRIVATE & CURLINFO_PRIVATE constants. 
   (Andrey A. Belashkov, Tony)
 
+- Fixed crash in OpenSSL extension because of non-strin passphrase. (Dmitry)
 - Fixed var_export() to use the new H modifier so that it can generate
   parseable PHP code for floats, independent of the locale. (Derick)
 - Fixed regression introduced by the fix for the libgd bug #74. (Pierre)
index d33bd384095c8a226aa0c9959eb5443a73c09652..032c9c25c6c759b30fdc279d113dc9e93c671802 100644 (file)
@@ -999,8 +999,10 @@ PHP_FUNCTION(openssl_x509_parse)
        char * tmpstr;
        zval * subitem;
        X509_EXTENSION *extension;
-       ASN1_OCTET_STRING *extdata;
        char *extname;
+       BIO  *bio_out;
+       BUF_MEM *bio_buf;
+       char buf[256];
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|b", &zcert, &useshortnames) == FAILURE) {
                return;
@@ -1082,9 +1084,20 @@ PHP_FUNCTION(openssl_x509_parse)
 
        for (i = 0; i < X509_get_ext_count(cert); i++) {
                extension = X509_get_ext(cert, i);
-               extdata = X509_EXTENSION_get_data(extension);
-               extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension)));
-               add_assoc_asn1_string(subitem, extname, extdata);
+               if (OBJ_obj2nid(X509_EXTENSION_get_object(extension)) != NID_undef) {
+                       extname = (char *)OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(extension)));
+               } else {
+                       OBJ_obj2txt(buf, sizeof(buf)-1, X509_EXTENSION_get_object(extension), 1);
+                       extname = buf;
+               }
+               bio_out = BIO_new(BIO_s_mem());
+               if (X509V3_EXT_print(bio_out, extension, 0, 0)) {
+                       BIO_get_mem_ptr(bio_out, &bio_buf);
+                       add_assoc_stringl(subitem, extname, bio_buf->data, bio_buf->length, 1);
+               } else {
+                       add_assoc_asn1_string(subitem, extname, X509_EXTENSION_get_data(extension));
+               }
+               BIO_free(bio_out);
        }
        add_assoc_zval(return_value, "extensions", subitem);
 
index 255f0304125f8dc60ef8e7c419dd75b83f378436..dab510121db670a75d5759833a741b6cfd2c4ec9 100644 (file)
@@ -14,25 +14,28 @@ var_dump($ext['extensions']);
 --EXPECTF--
 array(11) {
   ["basicConstraints"]=>
-  string(2) "%s"
+  string(8) "CA:FALSE"
   ["nsComment"]=>
-  string(40) "%s"
+  string(38) "For Grid use only; request tag userTag"
   ["nsCertType"]=>
-  string(4) "%s"
+  string(30) "SSL Client, SSL Server, S/MIME"
   ["crlDistributionPoints"]=>
-  string(56) "%s"
+  string(51) "URI:http://mobile.blue-software.ro:90/ca/crl.shtml
+"
   ["nsCaPolicyUrl"]=>
-  string(40) "%s"
+  string(38) "http://mobile.blue-software.ro:90/pub/"
   ["subjectAltName"]=>
-  string(26) "%s"
+  string(28) "email:sergiu@bluesoftware.ro"
   ["subjectKeyIdentifier"]=>
-  string(22) "%s"
+  string(59) "B0:A7:FF:F9:41:15:DE:23:39:BD:DD:31:0F:97:A0:B2:A2:74:E0:FC"
   ["authorityKeyIdentifier"]=>
-  string(159) "%s"
+  string(115) "DirName:/C=RO/ST=Romania/L=Craiova/O=Sergiu/OU=Sergiu SRL/CN=Sergiu CA/emailAddress=n_sergiu@hotmail.com
+serial:00
+"
   ["keyUsage"]=>
-  string(4) "%s"
+  string(71) "Digital Signature, Non Repudiation, Key Encipherment, Data Encipherment"
   ["nsBaseUrl"]=>
-  string(22) "%s"
-  ["UNDEF"]=>
+  string(20) "http://62.231.98.52/"
+  ["1.2.3.4"]=>
   string(4) "%s"
 }