I apologize - it helps when I actually attach the patch.
--- ext/openssl/php_openssl.h.orig      2004-10-08 15:32:52.000000000 -0400
+++ ext/openssl/php_openssl.h   2004-10-07 17:40:13.000000000 -0400
@@ -78,6 +78,7 @@
 PHP_FUNCTION(openssl_csr_export);
 PHP_FUNCTION(openssl_csr_export_to_file);
 PHP_FUNCTION(openssl_csr_sign);
+PHP_FUNCTION(openssl_csr_subject);

 #include <openssl/ssl.h>
 int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stream 
TSRMLS_DC);
--- ext/openssl/openssl.c.orig  2004-10-08 15:30:58.000000000 -0400
+++ ext/openssl/openssl.c       2004-10-08 15:34:08.000000000 -0400
@@ -88,6 +88,7 @@
        PHP_FE(openssl_csr_export,                      arg2_force_ref)
        PHP_FE(openssl_csr_export_to_file,      NULL)
        PHP_FE(openssl_csr_sign,                        NULL)
+       PHP_FE(openssl_csr_subject,                     NULL)


        PHP_FE(openssl_sign,               arg2_force_ref)
@@ -1424,6 +1425,35 @@
 }
 /* }}} */

+/* {{{ proto string openssl_csr_subject(mixed csr)
+   Returns the subject of a CERT */
+PHP_FUNCTION(openssl_csr_subject)
+{
+       zval * zcsr;
+       long csr_resource;
+       X509_NAME * subject;
+       X509_REQ * csr;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcsr) == FAILURE)
+               return;
+
+       RETVAL_EMPTY_STRING();
+
+       csr = php_openssl_csr_from_zval(&zcsr, 0, &csr_resource TSRMLS_CC);
+       if (csr == NULL) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot get CSR from 
parameter 1");
+               return;
+       }
+
+       subject = X509_REQ_get_subject_name(csr);
+
+       RETVAL_STRING(X509_NAME_oneline(subject,0,0),1);
+
+       if (csr_resource == -1 && csr)
+               X509_REQ_free(csr);
+
+}
+
 /* {{{ proto resource openssl_csr_sign(mixed csr, mixed x509, mixed priv_key, long 
days [, array config_args [, long serial]])
    Signs a cert with another CERT */
 PHP_FUNCTION(openssl_csr_sign)
@@ -1550,7 +1580,7 @@
        if (new_cert)
                X509_free(new_cert);
 }
-/* }}} */
+/* }}}  */

 /* {{{ proto bool openssl_csr_new(array dn, resource &privkey [, array configargs, 
array extraattribs])
    Generates a privkey and CSR */
--- Begin Message --- Quick patch to add a function openssl_csr_subject() that allows you to see the subject of a CSR. Uses the same CSR handling routines as openssl_csr_sign() etc, so it can take a string in PEM format, a file, whatever.

Prototype: string openssl_csr_subject(mixed csr)

Sample return value:

string(99) "/C=CA/ST=Ontario/L=Kingston/O=Greg MacLellan/OU=PHP/CN=CSR Test/[EMAIL PROTECTED]"





--- End Message ---
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to