1--TEST--
2Phar::setSupportedSignatures() with hash, zip-based
3--EXTENSIONS--
4phar
5--SKIPIF--
6<?php
7$arr = Phar::getSupportedSignatures();
8if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
9--INI--
10phar.require_hash=0
11phar.readonly=0
12--FILE--
13<?php
14$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip';
15$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
16$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.3.phar.zip';
17$fname4 = __DIR__ . '/' . basename(__FILE__, '.php') . '.4.phar.zip';
18$fname5 = __DIR__ . '/' . basename(__FILE__, '.php') . '.5.phar.zip';
19$fname6 = __DIR__ . '/' . 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 = __DIR__ . '/../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--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(7) "SHA-256"
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