diff options
author | Pierre Joye <pajoye@php.net> | 2006-08-15 20:27:22 +0000 |
---|---|---|
committer | Pierre Joye <pajoye@php.net> | 2006-08-15 20:27:22 +0000 |
commit | 8dc61360c6a63ca7b34d8e26e74c78ec64c3d87d (patch) | |
tree | 2df9a7692d9a52f6edfffc8ef370db3e45d5ddfe | |
parent | 118a6a94e1b408b9ea5c758bd92fcb8fc70c64f1 (diff) | |
download | php-git-8dc61360c6a63ca7b34d8e26e74c78ec64c3d87d.tar.gz |
- add openssl_csr_get_subject() and openssl_csr_get_public_key()
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/openssl/openssl.c | 73 | ||||
-rw-r--r-- | ext/openssl/php_openssl.h | 3 |
3 files changed, 70 insertions, 7 deletions
@@ -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 diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index ad2fca4b4a..fe13cc7714 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -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 */ diff --git a/ext/openssl/php_openssl.h b/ext/openssl/php_openssl.h index 789f576f66..7cc6d68f1a 100644 --- a/ext/openssl/php_openssl.h +++ b/ext/openssl/php_openssl.h @@ -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 |