]> granicus.if.org Git - php/commitdiff
- add OPENSSL_KEYTYPE_EC constant
authorPierre Joye <pajoye@php.net>
Tue, 15 Aug 2006 00:38:05 +0000 (00:38 +0000)
committerPierre Joye <pajoye@php.net>
Tue, 15 Aug 2006 00:38:05 +0000 (00:38 +0000)
- openssl_pkey_get_details(), returns the key details

NEWS
ext/openssl/openssl.c
ext/openssl/php_openssl.h

diff --git a/NEWS b/NEWS
index 07a52b0a5bd000c0661c787fc13e27748d577087..386d891e9b1993b81a086e81890317012c3af6f9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,9 +26,9 @@ PHP                                                                        NEWS
 
 - Improved OpenSSL extension: (Pierre)
   . Added support for all supported algorithms in openssl_verify
-  . Implement #36732 (req/x509 extensions support for openssl_csr_new and
-    openssl_csr_sign) (ben at psc dot edu, Pierre)
-  . Implement #28382 (openssl_x509_parse() extensions support)
+  . Added openssl_pkey_get_details, returns the details of a key
+  . Added x509 v3 extensions support
+  . Added a new constant OPENSSL_KEYTYPE_EC
 
 - Fixed overflow on 64bit systems in str_repeat() and wordwrap(). (Stefan E.)
 - Disabled CURLOPT_FOLLOWLOCATION in curl when open_basedir or safe_mode are
@@ -106,8 +106,11 @@ PHP                                                                        NEWS
   destruction). (Ilia)
 - Fixed bug #37265 (Added missing safe_mode & open_basedir checks to
   imap_body()). (Ilia)
+- Implement #36732 (req/x509 extensions support for openssl_csr_new and
+  openssl_csr_sign) (ben at psc dot edu, Pierre)
 - Fixed bug #35973 (Error ORA-24806 occurs when trying to fetch a NCLOB 
   field). (Tony)
+- Implement #28382 (openssl_x509_parse() extensions support) (Pierre)
 
 24 Jul 2006, PHP 5.2.0RC1
 - Updated bundled MySQL client library to version 5.0.22 in the Windows
index 9291843cd77a7032bc18f1b85b33a084a6f628c5..ad2fca4b4ad689ed4cd87d3bb28813c8e14201f1 100644 (file)
@@ -60,11 +60,17 @@ static
                ZEND_ARG_PASS_INFO(1)
        ZEND_END_ARG_INFO();
 
+/* FIXME: Use the openssl constants instead of
+ * enum. It is now impossible to match real values
+ * against php constants. Also sorry to break the
+ * enum principles here, BC...
+ */
 enum php_openssl_key_type {
        OPENSSL_KEYTYPE_RSA,
        OPENSSL_KEYTYPE_DSA,
        OPENSSL_KEYTYPE_DH,
-       OPENSSL_KEYTYPE_DEFAULT = OPENSSL_KEYTYPE_RSA
+       OPENSSL_KEYTYPE_DEFAULT = OPENSSL_KEYTYPE_RSA,
+       OPENSSL_KEYTYPE_EC = OPENSSL_KEYTYPE_DH +1
 };
 
 enum php_openssl_cipher_type {
@@ -87,6 +93,7 @@ zend_function_entry openssl_functions[] = {
        PHP_FE(openssl_pkey_export_to_file,     NULL)
        PHP_FE(openssl_pkey_get_private,        NULL)
        PHP_FE(openssl_pkey_get_public,         NULL)
+       PHP_FE(openssl_pkey_get_details,        NULL)
 
        PHP_FALIAS(openssl_free_key,            openssl_pkey_free,                      NULL)
        PHP_FALIAS(openssl_get_privatekey,      openssl_pkey_get_private,       NULL)
@@ -680,6 +687,7 @@ PHP_MINIT_FUNCTION(openssl)
        REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_DSA", OPENSSL_KEYTYPE_DSA, CONST_CS|CONST_PERSISTENT);
 #endif
        REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_DH", OPENSSL_KEYTYPE_DH, CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("OPENSSL_KEYTYPE_EC", OPENSSL_KEYTYPE_EC, CONST_CS|CONST_PERSISTENT);
 
        /* Determine default SSL configuration file */
        config_filename = getenv("OPENSSL_CONF");
@@ -2216,6 +2224,61 @@ PHP_FUNCTION(openssl_pkey_get_private)
 
 /* }}} */
 
+/* {{{ proto resource openssl_pkey_get_details(resource key)
+       returns an array with the key details (bits, pkey, type)*/
+PHP_FUNCTION(openssl_pkey_get_details)
+{
+       zval *key;
+       EVP_PKEY *pkey;
+       BIO *out;
+       unsigned int pbio_len;
+       char *pbio;
+       long ktype;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &key) == FAILURE) {
+               return;
+       }
+       ZEND_FETCH_RESOURCE(pkey, EVP_PKEY *, &key, -1, "OpenSSL key", le_key);
+       if (!pkey) {
+               RETURN_FALSE;
+       }
+       out = BIO_new(BIO_s_mem());
+       PEM_write_bio_PUBKEY(out, pkey);
+       pbio_len = BIO_get_mem_data(out, &pbio);
+
+       array_init(return_value);
+       add_assoc_long(return_value, "bits", EVP_PKEY_bits(pkey));
+       add_assoc_stringl(return_value, "key", pbio, pbio_len, 1);
+       /*TODO: Use the real values once the openssl constants are used 
+        * See the enum at the top of this file
+        */
+       switch (EVP_PKEY_type(pkey->type)) {
+               case EVP_PKEY_RSA:
+               case EVP_PKEY_RSA2:
+                       ktype = OPENSSL_KEYTYPE_RSA;
+                       break;  
+               case EVP_PKEY_DSA:
+               case EVP_PKEY_DSA2:
+               case EVP_PKEY_DSA3:
+               case EVP_PKEY_DSA4:
+                       ktype = OPENSSL_KEYTYPE_DSA;
+                       break;
+               case EVP_PKEY_DH:
+                       ktype = OPENSSL_KEYTYPE_DH;
+                       break;
+               case EVP_PKEY_EC:
+                       ktype = OPENSSL_KEYTYPE_EC;
+                       break;
+               default:
+                       ktype = -1;
+                       break;
+       }
+       add_assoc_long(return_value, "type", ktype);
+
+       BIO_free(out);
+}
+/* }}} */
+
 /* }}} */
 
 /* {{{ PKCS7 S/MIME functions */
index bf8c548837fdf479fea017c8d7475bc0595084db..789f576f66ddbf5fbb54e98bbeb67ab36f9972fe 100644 (file)
@@ -38,6 +38,7 @@ PHP_FUNCTION(openssl_pkey_free);
 PHP_FUNCTION(openssl_pkey_new);
 PHP_FUNCTION(openssl_pkey_export);
 PHP_FUNCTION(openssl_pkey_export_to_file);
+PHP_FUNCTION(openssl_pkey_get_details);
 
 PHP_FUNCTION(openssl_sign);
 PHP_FUNCTION(openssl_verify);