Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13244 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99483 invoked by uid 1010); 8 Oct 2004 20:04:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 99455 invoked from network); 8 Oct 2004 20:04:18 -0000 Received: from unknown (HELO websrv.digitalorphans.org) (199.246.2.129) by pb1.pair.com with SMTP; 8 Oct 2004 20:04:18 -0000 Received: (qmail 29696 invoked from network); 8 Oct 2004 19:45:38 -0000 Received: from da-66201251.039.trytel.com (HELO gregmaclellan.com) (66.201.251.39) by websrv.digitalorphans.org with SMTP; 8 Oct 2004 19:45:38 -0000 Message-ID: <4166EF12.8090107@gregmaclellan.com> Date: Fri, 08 Oct 2004 15:48:34 -0400 User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------080500090800030609040406" Subject: Fwd: [PATCH] added: openssl_csr_subject() From: greg@gregmaclellan.com (Greg MacLellan) --------------080500090800030609040406 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit I apologize - it helps when I actually attach the patch. --------------080500090800030609040406 Content-Type: text/plain; name="openssl.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="openssl.patch.txt" --- 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 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 */ --------------080500090800030609040406 Content-Type: message/rfc822; name="[PATCH] added: openssl_csr_subject()" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="[PATCH] added: openssl_csr_subject()" Message-ID: <4166EDEA.20300@gregmaclellan.com> Date: Fri, 08 Oct 2004 15:43:38 -0400 From: Greg MacLellan User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net Subject: [PATCH] added: openssl_csr_subject() Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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/emailAddress=greg@gregmaclellan.com" --------------080500090800030609040406--