]> granicus.if.org Git - php/commitdiff
- add openssl_csr_get_subject() and openssl_csr_get_public_key()
authorPierre Joye <pajoye@php.net>
Tue, 15 Aug 2006 20:27:22 +0000 (20:27 +0000)
committerPierre Joye <pajoye@php.net>
Tue, 15 Aug 2006 20:27:22 +0000 (20:27 +0000)
NEWS
ext/openssl/openssl.c
ext/openssl/php_openssl.h

diff --git a/NEWS b/NEWS
index 3279cf2abe4dd8af361da441fb0ad67c55431863..49954b00ac9b2e5245ce734c7b93f81b2b14baca 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ PHP                                                                        NEWS
   . Added openssl_pkey_get_details, returns the details of a key
   . Added x509 v3 extensions support
   . Added a new constant OPENSSL_KEYTYPE_EC
+  . Added openssl_csr_get_subject() and openssl_csr_get_public_key()
 
 - Fixed overflow on 64bit systems in str_repeat() and wordwrap(). (Stefan E.)
 - Disabled CURLOPT_FOLLOWLOCATION in curl when open_basedir or safe_mode are
index ad2fca4b4ad689ed4cd87d3bb28813c8e14201f1..fe13cc7714e835cd7e86a2b6fa2172cc719c6f6d 100644 (file)
@@ -113,6 +113,8 @@ zend_function_entry openssl_functions[] = {
        PHP_FE(openssl_csr_export,                      second_arg_force_ref)
        PHP_FE(openssl_csr_export_to_file,      NULL)
        PHP_FE(openssl_csr_sign,                        NULL)
+       PHP_FE(openssl_csr_get_subject,         NULL)
+       PHP_FE(openssl_csr_get_public_key,      NULL)
 
        PHP_FE(openssl_sign,            second_arg_force_ref)
        PHP_FE(openssl_verify,          NULL)
@@ -248,9 +250,13 @@ static void add_assoc_name_entry(zval * val, char * key, X509_NAME * name, int s
        ASN1_STRING * str = NULL;
        ASN1_OBJECT * obj;
 
-       MAKE_STD_ZVAL(subitem);
-       array_init(subitem);
-
+       if (key != NULL) {
+               MAKE_STD_ZVAL(subitem);
+               array_init(subitem);
+       } else {
+               subitem = val;
+       }
+       
        for (i = 0; i < X509_NAME_entry_count(name); i++) {
                ne  = X509_NAME_get_entry(name, i);
                obj = X509_NAME_ENTRY_get_object(ne);
@@ -291,7 +297,9 @@ static void add_assoc_name_entry(zval * val, char * key, X509_NAME * name, int s
                        }
                }
        }
-       zend_hash_update(HASH_OF(val), key, strlen(key) + 1, (void *)&subitem, sizeof(subitem), NULL);
+       if (key != NULL) {
+               zend_hash_update(HASH_OF(val), key, strlen(key) + 1, (void *)&subitem, sizeof(subitem), NULL);
+       }
 }
 /* }}} */
 
@@ -1527,8 +1535,6 @@ PHP_FUNCTION(openssl_csr_export_to_file)
 }
 /* }}} */
 
-
-
 /* {{{ proto bool openssl_csr_export(resource csr, string &out [, bool notext=true])
    Exports a CSR to file or a var */
 PHP_FUNCTION(openssl_csr_export)
@@ -1789,6 +1795,61 @@ PHP_FUNCTION(openssl_csr_new)
 }
 /* }}} */
 
+/* {{{ proto mixed openssl_csr_get_subject(mixed csr)
+   Returns the subject of a CERT or FALSE on error */
+PHP_FUNCTION(openssl_csr_get_subject)
+{
+       zval * zcsr;
+       zend_bool use_shortnames = 1;
+       long csr_resource;
+       X509_NAME * subject;
+       X509_REQ * csr;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zcsr, &use_shortnames) == FAILURE) {
+               return;
+       }
+
+       csr = php_openssl_csr_from_zval(&zcsr, 0, &csr_resource TSRMLS_CC);
+
+       if (csr == NULL) {
+               RETURN_FALSE;
+       }
+
+       subject = X509_REQ_get_subject_name(csr);
+
+       array_init(return_value);
+       add_assoc_name_entry(return_value, NULL, subject, use_shortnames TSRMLS_CC);
+       return;
+}
+/* }}} */
+
+/* {{{ proto mixed openssl_csr_get_public_key(mixed csr)
+       Returns the subject of a CERT or FALSE on error */
+PHP_FUNCTION(openssl_csr_get_public_key)
+{
+       zval * zcsr;
+       zend_bool use_shortnames = 1;
+       long csr_resource;
+
+       X509_REQ * csr;
+       EVP_PKEY *tpubkey;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zcsr, &use_shortnames) == FAILURE) {
+               return;
+       }
+
+       csr = php_openssl_csr_from_zval(&zcsr, 0, &csr_resource TSRMLS_CC);
+
+       if (csr == NULL) {
+               RETURN_FALSE;
+       }
+
+       tpubkey=X509_REQ_get_pubkey(csr);
+       RETVAL_RESOURCE(zend_list_insert(tpubkey, le_key));
+       return;
+}
+/* }}} */
+
 /* }}} */
 
 /* {{{ EVP Public/Private key functions */
index 789f576f66ddbf5fbb54e98bbeb67ab36f9972fe..7cc6d68f1ab1102fc54d5ac5ce07f035e77e867e 100644 (file)
@@ -67,7 +67,8 @@ PHP_FUNCTION(openssl_csr_new);
 PHP_FUNCTION(openssl_csr_export);
 PHP_FUNCTION(openssl_csr_export_to_file);
 PHP_FUNCTION(openssl_csr_sign);
-
+PHP_FUNCTION(openssl_csr_get_subject);
+PHP_FUNCTION(openssl_csr_get_public_key);
 #else
 
 #define phpext_openssl_ptr NULL