mirror of
https://github.com/php/php-src.git
synced 2024-12-26 10:19:53 +08:00
Adds test cases for openssl EC improvements
This commit is contained in:
parent
e795675845
commit
17e98661c6
52
ext/openssl/tests/027.phpt
Normal file
52
ext/openssl/tests/027.phpt
Normal file
@ -0,0 +1,52 @@
|
||||
--TEST--
|
||||
openssl_pkey_export() with EC key
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("openssl")) die("skip");
|
||||
if (!defined('OPENSSL_KEYTYPE_EC')) die("skip no EC available");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$key = openssl_pkey_get_private('file://' . dirname(__FILE__) . '/private_ec.key');
|
||||
var_dump($key);
|
||||
|
||||
var_dump(openssl_pkey_export($key, $output));
|
||||
echo $output;
|
||||
|
||||
// Load the private key from the exported pem string
|
||||
$details = openssl_pkey_get_details(openssl_pkey_get_private($output));
|
||||
var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
|
||||
|
||||
// Export key with passphrase
|
||||
openssl_pkey_export($key, $output, 'passphrase');
|
||||
|
||||
$details = openssl_pkey_get_details(openssl_pkey_get_private($output, 'passphrase'));
|
||||
var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
|
||||
|
||||
// Read public key
|
||||
$pKey = openssl_pkey_get_public('file://' . dirname(__FILE__) . '/public_ec.key');
|
||||
var_dump($pKey);
|
||||
// The details are the same for a public or private key
|
||||
var_dump($details === openssl_pkey_get_details($pKey));
|
||||
|
||||
|
||||
// Export to file
|
||||
$tempname = tempnam(sys_get_temp_dir(), 'openssl_ec');
|
||||
var_dump(openssl_pkey_export_to_file($key, $tempname));
|
||||
$details = openssl_pkey_get_details(openssl_pkey_get_private('file://' . $tempname));
|
||||
var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
|
||||
|
||||
// Clean the temporary file
|
||||
@unlink($tempname);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
resource(%d) of type (OpenSSL key)
|
||||
bool(true)
|
||||
-----BEGIN EC PRIVATE KEY-----%a-----END EC PRIVATE KEY-----
|
||||
bool(true)
|
||||
bool(true)
|
||||
resource(%d) of type (OpenSSL key)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
28
ext/openssl/tests/028.phpt
Normal file
28
ext/openssl/tests/028.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
openssl_pkey_get_details() with EC key
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded("openssl")) die("skip");
|
||||
if (!defined('OPENSSL_KEYTYPE_EC')) die("skip no EC available");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$key = openssl_pkey_get_private('file://' . dirname(__FILE__) . '/private_ec.key');
|
||||
|
||||
print_r(openssl_pkey_get_details($key));
|
||||
?>
|
||||
--EXPECTF--
|
||||
Array
|
||||
(
|
||||
[bits] => 256
|
||||
[key] => -----BEGIN PUBLIC KEY-----%a
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
[ec] => Array
|
||||
(
|
||||
[curve_name] => prime256v1
|
||||
[curve_oid] => 1.2.840.10045.3.1.7
|
||||
)
|
||||
|
||||
[type] => 3
|
||||
)
|
5
ext/openssl/tests/private_ec.key
Normal file
5
ext/openssl/tests/private_ec.key
Normal file
@ -0,0 +1,5 @@
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEILPkqoeyM7XgwYkuSj3077lrsrfWJK5LqMolv+m2oOjZoAoGCCqGSM49
|
||||
AwEHoUQDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNWVugYFtPg/xLQw0mHkIPZ4DvK
|
||||
sqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug==
|
||||
-----END EC PRIVATE KEY-----
|
4
ext/openssl/tests/public_ec.key
Normal file
4
ext/openssl/tests/public_ec.key
Normal file
@ -0,0 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNW
|
||||
VugYFtPg/xLQw0mHkIPZ4DvKsqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug==
|
||||
-----END PUBLIC KEY-----
|
Loading…
Reference in New Issue
Block a user