#25614 [Sus->Asn]: openssl_pkey_get_public() fails when given a private key

From: Date: Mon, 09 Feb 2009 10:08:02 +0000
Subject: #25614 [Sus->Asn]: openssl_pkey_get_public() fails when given a private key
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-133623@lists.php.net to get a copy of this message
ID: 25614 Updated by: pajoye@php.net Reported By: six at t0x dot net -Status: Suspended +Status: Assigned Bug Type: OpenSSL related Operating System: Linux 2.4 PHP Version: 6CVS, 5CVS, 4CVS -Assigned To: wez +Assigned To: pajoye New Comment: take the hand on this one, related to an issue I'm trying to solve as well. Previous Comments: ------------------------------------------------------------------------ [2006-06-01 14:33:59] tony2001@php.net Unified diff against the current CVS, of course. ------------------------------------------------------------------------ [2006-06-01 14:33:17] tony2001@php.net Please provide unified diff. And no C++, thank you. ------------------------------------------------------------------------ [2006-06-01 14:27:57] andrey dot gladilin at gmail dot com Sorry, it's a c++ code. Hope this wont prevent you from a fix. ------------------------------------------------------------------------ [2006-06-01 14:22:33] andrey dot gladilin at gmail dot com To fix this bug you have to change file php-4.4.0/ext/openssl/openssl.c. php-4.4.0 is just my source distributive of PHP. In file openssl.c replace string key = PEM_read_bio_PUBKEY(in, NULL,NULL, NULL); with another code RSA * rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL); BIO_free(in); if(NULL == rsa) { throw Exc("Error while processing the Public Key."); } pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, rsa); Unsusccessfully I have no time to test it, but this must work. Hope to see this bugfix in a new release. ------------------------------------------------------------------------ [2003-09-23 12:10:32] wez@php.net The documentation for openssl_pkey_new() is incorrect. It doesn't generate a pair of keys at all. openssl_pkey_get_public() was also slightly broken, in that it didn't detect that it couldn't get the public key from the private key. You can use it to get the public key out of an x509 certificate though (yeah, it sounds weird). I've added a "fix" for this problem to the CVS that will now warn you about not being able to get the public key from a private key. This fix will be in 4.3.4. This stuff is a little bit messy, and its been a while since anyone did any real work on the openssl extension. The openssl stuff could probably benefit from a review, but this won't happen for PHP 4.3.x, so I'm going to suspend this report until PHP 5 or PHP 5.1 when I get more time. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/25614 -- Edit this bug report at http://bugs.php.net/?id=25614&edit=1

« previous php.bugs (#133623) next »