Skip to content

Commit

Permalink
Fix for bug66501 - "key type not supported in this PHP build"
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-j authored and rdlowrey committed Feb 15, 2014
1 parent 35101e9 commit 19524fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,15 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC)
return 0;
}
break;
#endif
#ifdef EVP_PKEY_EC
case EVP_PKEY_EC:
assert(pkey->pkey.ec != NULL);

if ( NULL == EC_KEY_get0_private_key(pkey->pkey.ec)) {
return 0;
}
break;
#endif
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "key type not supported in this PHP build!");
Expand Down
21 changes: 21 additions & 0 deletions ext/openssl/tests/bug66501.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #66501: EC private key support in openssl_sign
--SKIPIF--
<?php
if (!extension_loaded("openssl")) die("skip");
--FILE--
<?php
$pkey = 'ASN1 OID: prime256v1
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEILPkqoeyM7XgwYkuSj3077lrsrfWJK5LqMolv+m2oOjZoAoGCCqGSM49
AwEHoUQDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNWVugYFtPg/xLQw0mHkIPZ4DvK
sqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug==
-----END EC PRIVATE KEY-----';
$key = openssl_pkey_get_private($pkey);
$res = openssl_sign($data ='alpha', $sign, $key, 'ecdsa-with-SHA1');
var_dump($res);
--EXPECTF--
bool(true)

0 comments on commit 19524fc

Please sign in to comment.