@@ -113,6 +113,8 @@ zend_function_entry openssl_functions[] = {
113
113
PHP_FE (openssl_csr_export , second_arg_force_ref )
114
114
PHP_FE (openssl_csr_export_to_file , NULL )
115
115
PHP_FE (openssl_csr_sign , NULL )
116
+ PHP_FE (openssl_csr_get_subject , NULL )
117
+ PHP_FE (openssl_csr_get_public_key , NULL )
116
118
117
119
PHP_FE (openssl_sign , second_arg_force_ref )
118
120
PHP_FE (openssl_verify , NULL )
@@ -248,9 +250,13 @@ static void add_assoc_name_entry(zval * val, char * key, X509_NAME * name, int s
248
250
ASN1_STRING * str = NULL ;
249
251
ASN1_OBJECT * obj ;
250
252
251
- MAKE_STD_ZVAL (subitem );
252
- array_init (subitem );
253
-
253
+ if (key != NULL ) {
254
+ MAKE_STD_ZVAL (subitem );
255
+ array_init (subitem );
256
+ } else {
257
+ subitem = val ;
258
+ }
259
+
254
260
for (i = 0 ; i < X509_NAME_entry_count (name ); i ++ ) {
255
261
ne = X509_NAME_get_entry (name , i );
256
262
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
291
297
}
292
298
}
293
299
}
294
- zend_hash_update (HASH_OF (val ), key , strlen (key ) + 1 , (void * )& subitem , sizeof (subitem ), NULL );
300
+ if (key != NULL ) {
301
+ zend_hash_update (HASH_OF (val ), key , strlen (key ) + 1 , (void * )& subitem , sizeof (subitem ), NULL );
302
+ }
295
303
}
296
304
/* }}} */
297
305
@@ -1527,8 +1535,6 @@ PHP_FUNCTION(openssl_csr_export_to_file)
1527
1535
}
1528
1536
/* }}} */
1529
1537
1530
-
1531
-
1532
1538
/* {{{ proto bool openssl_csr_export(resource csr, string &out [, bool notext=true])
1533
1539
Exports a CSR to file or a var */
1534
1540
PHP_FUNCTION (openssl_csr_export )
@@ -1789,6 +1795,61 @@ PHP_FUNCTION(openssl_csr_new)
1789
1795
}
1790
1796
/* }}} */
1791
1797
1798
+ /* {{{ proto mixed openssl_csr_get_subject(mixed csr)
1799
+ Returns the subject of a CERT or FALSE on error */
1800
+ PHP_FUNCTION (openssl_csr_get_subject )
1801
+ {
1802
+ zval * zcsr ;
1803
+ zend_bool use_shortnames = 1 ;
1804
+ long csr_resource ;
1805
+ X509_NAME * subject ;
1806
+ X509_REQ * csr ;
1807
+
1808
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "z|b" , & zcsr , & use_shortnames ) == FAILURE ) {
1809
+ return ;
1810
+ }
1811
+
1812
+ csr = php_openssl_csr_from_zval (& zcsr , 0 , & csr_resource TSRMLS_CC );
1813
+
1814
+ if (csr == NULL ) {
1815
+ RETURN_FALSE ;
1816
+ }
1817
+
1818
+ subject = X509_REQ_get_subject_name (csr );
1819
+
1820
+ array_init (return_value );
1821
+ add_assoc_name_entry (return_value , NULL , subject , use_shortnames TSRMLS_CC );
1822
+ return ;
1823
+ }
1824
+ /* }}} */
1825
+
1826
+ /* {{{ proto mixed openssl_csr_get_public_key(mixed csr)
1827
+ Returns the subject of a CERT or FALSE on error */
1828
+ PHP_FUNCTION (openssl_csr_get_public_key )
1829
+ {
1830
+ zval * zcsr ;
1831
+ zend_bool use_shortnames = 1 ;
1832
+ long csr_resource ;
1833
+
1834
+ X509_REQ * csr ;
1835
+ EVP_PKEY * tpubkey ;
1836
+
1837
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "z|b" , & zcsr , & use_shortnames ) == FAILURE ) {
1838
+ return ;
1839
+ }
1840
+
1841
+ csr = php_openssl_csr_from_zval (& zcsr , 0 , & csr_resource TSRMLS_CC );
1842
+
1843
+ if (csr == NULL ) {
1844
+ RETURN_FALSE ;
1845
+ }
1846
+
1847
+ tpubkey = X509_REQ_get_pubkey (csr );
1848
+ RETVAL_RESOURCE (zend_list_insert (tpubkey , le_key ));
1849
+ return ;
1850
+ }
1851
+ /* }}} */
1852
+
1792
1853
/* }}} */
1793
1854
1794
1855
/* {{{ EVP Public/Private key functions */
0 commit comments