com php-src: Adds test cases for openssl EC improvements: ext/openssl/tests/027.phpt ext/openssl/tests/028.phpt ext/openssl/tests/private_ec.key
ext/openssl/tests/public _ec.key
| From: | Stanislav Malyshev | Date: | Mon, 24 Nov 2014 01:31:19 +0000 |
| Subject: | com php-src: Adds test cases for openssl EC improvements: ext/openssl/tests/027.phpt ext/openssl/tests/028.phpt ext/openssl/tests/private_ec.key ext/openssl/tests/public _ec.key |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83411@lists.php.net to get a copy of this message | ||
Commit: 17e98661c6c8c7a30611c94b552ac4da8e4c92c6
Author: Dominic Luechinger <doldev@snowgarden.ch> Mon, 24 Nov 2014 02:31:19 +0100
Parents: e795675845849ef004e855f5cb1d8065c9cd96c9
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=17e98661c6c8c7a30611c94b552ac4da8e4c92c6
Log:
Adds test cases for openssl EC improvements
Changed paths:
A ext/openssl/tests/027.phpt
A ext/openssl/tests/028.phpt
A ext/openssl/tests/private_ec.key
A ext/openssl/tests/public_ec.key
Diff:
diff --git a/ext/openssl/tests/027.phpt b/ext/openssl/tests/027.phpt
new file mode 100644
index 0000000..8311ab1
--- /dev/null
+++ b/ext/openssl/tests/027.phpt
@@ -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)
diff --git a/ext/openssl/tests/028.phpt b/ext/openssl/tests/028.phpt
new file mode 100644
index 0000000..8e0cef4
--- /dev/null
+++ b/ext/openssl/tests/028.phpt
@@ -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
+)
diff --git a/ext/openssl/tests/private_ec.key b/ext/openssl/tests/private_ec.key
new file mode 100644
index 0000000..51cdcb7
--- /dev/null
+++ b/ext/openssl/tests/private_ec.key
@@ -0,0 +1,5 @@
+-----BEGIN EC PRIVATE KEY-----
+MHcCAQEEILPkqoeyM7XgwYkuSj3077lrsrfWJK5LqMolv+m2oOjZoAoGCCqGSM49
+AwEHoUQDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNWVugYFtPg/xLQw0mHkIPZ4DvK
+sqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug==
+-----END EC PRIVATE KEY-----
diff --git a/ext/openssl/tests/public_ec.key b/ext/openssl/tests/public_ec.key
new file mode 100644
index 0000000..a93b2c8
--- /dev/null
+++ b/ext/openssl/tests/public_ec.key
@@ -0,0 +1,4 @@
+-----BEGIN PUBLIC KEY-----
+MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNW
+VugYFtPg/xLQw0mHkIPZ4DvKsqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug==
+-----END PUBLIC KEY-----