wez             Tue Sep 23 10:52:27 2003 EDT

  Added files:                 (Branch: PHP_4_3)
    /php-src/ext/openssl/tests  bug25614.phpt 

  Modified files:              
    /php-src/ext/openssl        openssl.c 
  Log:
  "Fix" for bug #25614.
  The openssl_pkey_get_public() doesn't work as advertized in the docs; it can't
  get a public key from a private key (because a key is a key), but would return
  the private key anyway.  The function was originally designed to get the public
  key from a certificate.
  
  
  
Index: php-src/ext/openssl/openssl.c
diff -u php-src/ext/openssl/openssl.c:1.52.2.15 php-src/ext/openssl/openssl.c:1.52.2.16
--- php-src/ext/openssl/openssl.c:1.52.2.15     Sun Jul 13 06:13:19 2003
+++ php-src/ext/openssl/openssl.c       Tue Sep 23 10:52:25 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: openssl.c,v 1.52.2.15 2003/07/13 10:13:19 sr Exp $ */
+/* $Id: openssl.c,v 1.52.2.16 2003/09/23 14:52:25 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1689,15 +1689,21 @@
                        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 && !is_priv) {
                                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 (the documentation lied)");
+                               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 */

Index: php-src/ext/openssl/tests/bug25614.phpt
+++ php-src/ext/openssl/tests/bug25614.phpt

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to