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