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?> 10--INI-- 11phar.require_hash=0 12phar.readonly=0 13--FILE-- 14<?php 15$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip'; 16$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.zip'; 17$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.3.phar.zip'; 18$fname4 = __DIR__ . '/' . basename(__FILE__, '.php') . '.4.phar.zip'; 19$fname5 = __DIR__ . '/' . basename(__FILE__, '.php') . '.5.phar.zip'; 20$fname6 = __DIR__ . '/' . basename(__FILE__, '.php') . '.6.phar.zip'; 21$p = new Phar($fname); 22$p['file1.txt'] = 'hi'; 23var_dump($p->getSignature()); 24$p->setSignatureAlgorithm(Phar::MD5); 25 26copy($fname, $fname2); 27$p = new Phar($fname2); 28var_dump($p->getSignature()); 29 30$p->setSignatureAlgorithm(Phar::SHA1); 31 32copy($fname2, $fname3); 33$p = new Phar($fname3); 34var_dump($p->getSignature()); 35 36try { 37$p->setSignatureAlgorithm(Phar::SHA256); 38copy($fname3, $fname4); 39$p = new Phar($fname4); 40var_dump($p->getSignature()); 41} catch (Exception $e) { 42echo $e->getMessage(); 43} 44try { 45$p->setSignatureAlgorithm(Phar::SHA512); 46copy($fname4, $fname5); 47$p = new Phar($fname5); 48var_dump($p->getSignature()); 49} catch (Exception $e) { 50echo $e->getMessage(); 51} 52try { 53$config = __DIR__ . '/../files/openssl.cnf'; 54$config_arg = array('config' => $config); 55$keys=openssl_pkey_new($config_arg); 56openssl_pkey_export($keys, $privkey, NULL, $config_arg); 57$pubkey=openssl_pkey_get_details($keys); 58$p->setSignatureAlgorithm(Phar::OPENSSL, $privkey); 59 60copy($fname5, $fname6); 61file_put_contents($fname6 . '.pubkey', $pubkey['key']); 62$p = new Phar($fname6); 63var_dump($p->getSignature()); 64} catch (Exception $e) { 65echo $e->getMessage(); 66} 67?> 68--CLEAN-- 69<?php 70unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); 71unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip'); 72unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip'); 73unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.4.phar.zip'); 74unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.5.phar.zip'); 75unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip'); 76unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip.pubkey'); 77?> 78--EXPECTF-- 79array(2) { 80 ["hash"]=> 81 string(%d) "%s" 82 ["hash_type"]=> 83 string(7) "SHA-256" 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