]> granicus.if.org Git - php/commitdiff
MFB 25614 "fix"
authorWez Furlong <wez@php.net>
Tue, 23 Sep 2003 16:05:52 +0000 (16:05 +0000)
committerWez Furlong <wez@php.net>
Tue, 23 Sep 2003 16:05:52 +0000 (16:05 +0000)
ext/openssl/openssl.c
ext/openssl/tests/bug25614.phpt [new file with mode: 0644]

index b01e78aea61a0c7adaadc2d32928c1ad21f05887..acb11ea0e52a786fdb18db71313bf3341175f5dd 100644 (file)
@@ -1738,14 +1738,23 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char *
                        cert = (X509*)what;
                        free_cert = 0;
                } else if (type == le_key) {
+                       int is_priv;
+
+                       is_priv = php_openssl_is_private_key((EVP_PKEY*)what TSRMLS_CC);
+
                        /* check whether it is actually a private key if requested */
-                       if (!public_key && !php_openssl_is_private_key((EVP_PKEY*)what TSRMLS_CC)) {
+                       if (!public_key && !ispriv) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "supplied key param is a public key");
                                return NULL;
                        }
-                       
-                       /* got the key - return it */
-                       return (EVP_PKEY*)what;
+
+                       if (public_key && is_priv) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Don't know how to get public key from this private key");
+                               return NULL;
+                       } else {
+                               /* got the key - return it */
+                               return (EVP_PKEY*)what;
+                       }
                }
 
                /* other types could be used here - eg: file pointers and read in the data from them */
diff --git a/ext/openssl/tests/bug25614.phpt b/ext/openssl/tests/bug25614.phpt
new file mode 100644 (file)
index 0000000..ce57ea7
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+openssl: get public key from generated private key
+--SKIPIF--
+<?php if (!extension_loaded("openssl")) print "skip"; ?>
+--FILE--
+<?php 
+$priv = openssl_pkey_new();
+$pub = openssl_pkey_get_public($priv);
+?>
+--EXPECTF--
+Warning: openssl_pkey_get_public(): Don't know how to get public key from this private key (the documentation lied) %s