@@ -9,37 +9,43 @@ if (!@openssl_pkey_new()) die("skip cannot create private key");
9
9
<?php
10
10
echo "Creating private key \n" ;
11
11
12
- $ conf = array ('config ' => dirname ( __FILE__ ) . DIRECTORY_SEPARATOR . 'openssl.cnf ' );
12
+ $ conf = array ('config ' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf ' );
13
13
$ privkey = openssl_pkey_new ($ conf );
14
14
15
- if ($ privkey === false )
16
- die ("failed to create private key " );
15
+ if ($ privkey === false ) {
16
+ die ("failed to create private key " );
17
+ }
17
18
18
19
$ passphrase = "banana " ;
19
- $ key_file_name = tempnam (sys_get_temp_dir (), "ssl " );
20
- if ($ key_file_name === false )
21
- die ("failed to get a temporary filename! " );
20
+ $ key_file_name = __DIR__ . '/001-tmp.key ' ;
21
+ if ($ key_file_name === false ) {
22
+ die ("failed to get a temporary filename! " );
23
+ }
22
24
23
25
echo "Export key to file \n" ;
24
26
25
- openssl_pkey_export_to_file ($ privkey , $ key_file_name , $ passphrase , $ conf ) or die ("failed to export to file $ key_file_name " );
27
+ if (!openssl_pkey_export_to_file ($ privkey , $ key_file_name , $ passphrase , $ conf )) {
28
+ die ("failed to export to file $ key_file_name " );
29
+ }
26
30
var_dump (is_resource ($ privkey ));
27
31
28
32
echo "Load key from file - array syntax \n" ;
29
33
30
34
$ loaded_key = openssl_pkey_get_private (array ("file:// $ key_file_name " , $ passphrase ));
31
35
32
- if ($ loaded_key === false )
33
- die ("failed to load key using array syntax " );
36
+ if ($ loaded_key === false ) {
37
+ die ("failed to load key using array syntax " );
38
+ }
34
39
35
40
openssl_pkey_free ($ loaded_key );
36
41
37
42
echo "Load key using direct syntax \n" ;
38
43
39
44
$ loaded_key = openssl_pkey_get_private ("file:// $ key_file_name " , $ passphrase );
40
45
41
- if ($ loaded_key === false )
42
- die ("failed to load key using direct syntax " );
46
+ if ($ loaded_key === false ) {
47
+ die ("failed to load key using direct syntax " );
48
+ }
43
49
44
50
openssl_pkey_free ($ loaded_key );
45
51
@@ -48,15 +54,13 @@ echo "Load key manually and use string syntax\n";
48
54
$ key_content = file_get_contents ($ key_file_name );
49
55
$ loaded_key = openssl_pkey_get_private ($ key_content , $ passphrase );
50
56
51
- if ($ loaded_key === false )
52
- die ("failed to load key using string syntax " );
53
-
57
+ if ($ loaded_key === false ) {
58
+ die ("failed to load key using string syntax " );
59
+ }
54
60
openssl_pkey_free ($ loaded_key );
55
61
56
62
echo "OK! \n" ;
57
63
58
- @unlink ($ key_file_name );
59
-
60
64
?>
61
65
--EXPECT--
62
66
Creating private key
@@ -66,3 +70,8 @@ Load key from file - array syntax
66
70
Load key using direct syntax
67
71
Load key manually and use string syntax
68
72
OK!
73
+ --CLEAN--
74
+ <?php
75
+ $ key_file_name = __DIR__ . DIRECTORY_SEPARATOR . '001-tmp.key ' ;
76
+ @unlink ($ key_file_name );
77
+ ?>
0 commit comments