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===DONE===
67--CLEAN--
68<?php
69unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
70unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
71unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip');
72unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.4.phar.zip');
73unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.5.phar.zip');
74unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip');
75unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip.pubkey');
76?>
77--EXPECTF--
78array(2) {
79  ["hash"]=>
80  string(%d) "%s"
81  ["hash_type"]=>
82  string(5) "SHA-1"
83}
84array(2) {
85  ["hash"]=>
86  string(%d) "%s"
87  ["hash_type"]=>
88  string(3) "MD5"
89}
90array(2) {
91  ["hash"]=>
92  string(%d) "%s"
93  ["hash_type"]=>
94  string(5) "SHA-1"
95}
96array(2) {
97  ["hash"]=>
98  string(%d) "%s"
99  ["hash_type"]=>
100  string(7) "SHA-256"
101}
102array(2) {
103  ["hash"]=>
104  string(%d) "%s"
105  ["hash_type"]=>
106  string(7) "SHA-512"
107}
108array(2) {
109  ["hash"]=>
110  string(%d) "%s"
111  ["hash_type"]=>
112  string(7) "OpenSSL"
113}
114===DONE===
115