1--TEST--
2Phar::setSupportedSignatures() with hash, zip-based
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("hash")) die("skip extension hash required");
6$arr = Phar::getSupportedSignatures();
7if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
8if (!in_array('SHA-256', $arr)) die("skip hash extension loaded shared"); ?>
9--INI--
10phar.require_hash=0
11phar.readonly=0
12--FILE--
13<?php
14$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
15$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
16$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar.zip';
17$fname4 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.4.phar.zip';
18$fname5 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.5.phar.zip';
19$fname6 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.6.phar.zip';
20$p = new Phar($fname);
21$p['file1.txt'] = 'hi';
22var_dump($p->getSignature());
23$p->setSignatureAlgorithm(Phar::MD5);
24
25copy($fname, $fname2);
26$p = new Phar($fname2);
27var_dump($p->getSignature());
28
29$p->setSignatureAlgorithm(Phar::SHA1);
30
31copy($fname2, $fname3);
32$p = new Phar($fname3);
33var_dump($p->getSignature());
34
35try {
36$p->setSignatureAlgorithm(Phar::SHA256);
37copy($fname3, $fname4);
38$p = new Phar($fname4);
39var_dump($p->getSignature());
40} catch (Exception $e) {
41echo $e->getMessage();
42}
43try {
44$p->setSignatureAlgorithm(Phar::SHA512);
45copy($fname4, $fname5);
46$p = new Phar($fname5);
47var_dump($p->getSignature());
48} catch (Exception $e) {
49echo $e->getMessage();
50}
51try {
52$config = dirname(__FILE__) . '/../files/openssl.cnf';
53$config_arg = array('config' => $config);
54$keys=openssl_pkey_new($config_arg);
55openssl_pkey_export($keys, $privkey, NULL, $config_arg);
56$pubkey=openssl_pkey_get_details($keys);
57$p->setSignatureAlgorithm(Phar::OPENSSL, $privkey);
58
59copy($fname5, $fname6);
60file_put_contents($fname6 . '.pubkey', $pubkey['key']);
61$p = new Phar($fname6);
62var_dump($p->getSignature());
63} catch (Exception $e) {
64echo $e->getMessage();
65}
66?>
67===DONE===
68--CLEAN--
69<?php
70unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
71unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
72unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip');
73unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.4.phar.zip');
74unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.5.phar.zip');
75unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip');
76unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip.pubkey');
77?>
78--EXPECTF--
79array(2) {
80  ["hash"]=>
81  string(%d) "%s"
82  ["hash_type"]=>
83  string(5) "SHA-1"
84}
85array(2) {
86  ["hash"]=>
87  string(%d) "%s"
88  ["hash_type"]=>
89  string(3) "MD5"
90}
91array(2) {
92  ["hash"]=>
93  string(%d) "%s"
94  ["hash_type"]=>
95  string(5) "SHA-1"
96}
97array(2) {
98  ["hash"]=>
99  string(%d) "%s"
100  ["hash_type"]=>
101  string(7) "SHA-256"
102}
103array(2) {
104  ["hash"]=>
105  string(%d) "%s"
106  ["hash_type"]=>
107  string(7) "SHA-512"
108}
109array(2) {
110  ["hash"]=>
111  string(%d) "%s"
112  ["hash_type"]=>
113  string(7) "OpenSSL"
114}
115===DONE===
116