2002-03-26 00:03:11 +00:00
|
|
|
--TEST--
|
|
|
|
OpenSSL private key functions
|
|
|
|
--SKIPIF--
|
2002-08-09 20:56:52 +00:00
|
|
|
<?php // vim600:syn=php
|
|
|
|
include('skipif.inc'); ?>
|
2002-03-26 00:03:11 +00:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
echo "Creating private key\n";
|
|
|
|
|
2002-12-12 15:50:11 +00:00
|
|
|
/* stack up some entropy; performance is not critical,
|
|
|
|
* and being slow will most likely even help the test.
|
|
|
|
*/
|
|
|
|
for ($z = "", $i = 0; $i < 1024; $i++) {
|
|
|
|
$z .= $i * $i;
|
|
|
|
if (function_exists("usleep"))
|
|
|
|
usleep($i);
|
|
|
|
}
|
|
|
|
|
2002-03-26 00:03:11 +00:00
|
|
|
$privkey = openssl_pkey_new();
|
|
|
|
|
|
|
|
if ($privkey === false)
|
|
|
|
die("failed to create private key");
|
|
|
|
|
|
|
|
$passphrase = "banana";
|
|
|
|
$key_file_name = tempnam("/tmp", "ssl");
|
|
|
|
if ($key_file_name === false)
|
|
|
|
die("failed to get a temporary filename!");
|
|
|
|
|
|
|
|
echo "Export key to file\n";
|
|
|
|
|
|
|
|
openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase) or die("failed to export to file $key_file_name");
|
|
|
|
|
|
|
|
echo "Load key from file - array syntax\n";
|
|
|
|
|
|
|
|
$loaded_key = openssl_pkey_get_private(array("file://$key_file_name", $passphrase));
|
|
|
|
|
|
|
|
if ($loaded_key === false)
|
|
|
|
die("failed to load key using array syntax");
|
|
|
|
|
|
|
|
openssl_pkey_free($loaded_key);
|
|
|
|
|
|
|
|
echo "Load key using direct syntax\n";
|
|
|
|
|
|
|
|
$loaded_key = openssl_pkey_get_private("file://$key_file_name", $passphrase);
|
|
|
|
|
|
|
|
if ($loaded_key === false)
|
|
|
|
die("failed to load key using direct syntax");
|
|
|
|
|
|
|
|
openssl_pkey_free($loaded_key);
|
|
|
|
|
|
|
|
echo "Load key manually and use string syntax\n";
|
|
|
|
|
2002-03-28 00:56:19 +00:00
|
|
|
$key_content = file_get_contents($key_file_name);
|
2002-03-26 00:03:11 +00:00
|
|
|
$loaded_key = openssl_pkey_get_private($key_content, $passphrase);
|
|
|
|
|
|
|
|
if ($loaded_key === false)
|
|
|
|
die("failed to load key using string syntax");
|
|
|
|
|
|
|
|
openssl_pkey_free($loaded_key);
|
|
|
|
|
|
|
|
echo "OK!\n";
|
|
|
|
|
2002-03-28 00:56:19 +00:00
|
|
|
@unlink($key_file_name);
|
|
|
|
|
2002-03-26 00:03:11 +00:00
|
|
|
?>
|
|
|
|
--EXPECT--
|
|
|
|
Creating private key
|
|
|
|
Export key to file
|
|
|
|
Load key from file - array syntax
|
|
|
|
Load key using direct syntax
|
|
|
|
Load key manually and use string syntax
|
|
|
|
OK!
|