Annotation of embedaddon/php/ext/openssl/tests/001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: OpenSSL private key functions
3: --SKIPIF--
4: <?php
5: if (!extension_loaded("openssl")) die("skip");
6: if (!@openssl_pkey_new()) die("skip cannot create private key");
7: ?>
8: --FILE--
9: <?php
10: echo "Creating private key\n";
11:
12: /* stack up some entropy; performance is not critical,
13: * and being slow will most likely even help the test.
14: */
15: for ($z = "", $i = 0; $i < 1024; $i++) {
16: $z .= $i * $i;
17: if (function_exists("usleep"))
18: usleep($i);
19: }
20:
21: $privkey = openssl_pkey_new();
22:
23: if ($privkey === false)
24: die("failed to create private key");
25:
26: $passphrase = "banana";
27: $key_file_name = tempnam("/tmp", "ssl");
28: if ($key_file_name === false)
29: die("failed to get a temporary filename!");
30:
31: echo "Export key to file\n";
32:
33: openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase) or die("failed to export to file $key_file_name");
34:
35: echo "Load key from file - array syntax\n";
36:
37: $loaded_key = openssl_pkey_get_private(array("file://$key_file_name", $passphrase));
38:
39: if ($loaded_key === false)
40: die("failed to load key using array syntax");
41:
42: openssl_pkey_free($loaded_key);
43:
44: echo "Load key using direct syntax\n";
45:
46: $loaded_key = openssl_pkey_get_private("file://$key_file_name", $passphrase);
47:
48: if ($loaded_key === false)
49: die("failed to load key using direct syntax");
50:
51: openssl_pkey_free($loaded_key);
52:
53: echo "Load key manually and use string syntax\n";
54:
55: $key_content = file_get_contents($key_file_name);
56: $loaded_key = openssl_pkey_get_private($key_content, $passphrase);
57:
58: if ($loaded_key === false)
59: die("failed to load key using string syntax");
60:
61: openssl_pkey_free($loaded_key);
62:
63: echo "OK!\n";
64:
65: @unlink($key_file_name);
66:
67: ?>
68: --EXPECT--
69: Creating private key
70: Export key to file
71: Load key from file - array syntax
72: Load key using direct syntax
73: Load key manually and use string syntax
74: OK!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>