<?php /** * Exemplary file - download a signed phar archive from any location, verifying its public key * * This file is part of the Remote-Phar library. * @author Krzysztof Kotowicz <kkotowicz at gmail dot com> * @package PharUtil */ // manually add .. to include_path in case you don't have the PEAR package installed (yet) set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../'); require_once 'PharUtil/RemotePharVerifier.php'; $d = new PharUtil_RemotePharVerifier('./tmp', './verified', './cert/pub.pem'); // here the local URI is used, but it could be any remote, e.g. http:// location $path = dirname(__FILE__) . '/build/test.phar'; $local_phar = $d->fetch($path, true); echo $path, ' => ', $local_phar, PHP_EOL; require_once $local_phar; echo test() . PHP_EOL;
$parser->displayError($exc->getMessage()); } $options = $result->options; $args = $result->args; echo $parser->name . ' ' . $parser->version . PHP_EOL . PHP_EOL; // validate parameters if (substr($args['phar'], -5) !== '.phar') { $parser->displayError("Input Phar must have .phar extension, {$args['phar']} given.", 2); } if ($options['nosign']) { $options['public'] = null; // no public key } if ($options['public']) { if (!file_exists($options['public']) || !is_readable($options['public'])) { $parser->displayError("Public key in '{$options['public']}' does not exist or is not readable.", 4); } } if (!$options['temp']) { $options['temp'] = sys_get_temp_dir(); } try { echo "Verifying Phar archive: {$args['phar']}..." . PHP_EOL; $v = new PharUtil_RemotePharVerifier($options['temp'], $options['temp'], $options['public']); $v->verify($args['phar']); echo "Phar archive successfully verified." . PHP_EOL; } catch (Exception $e) { echo "Error: " . $e->getMessage() . PHP_EOL; exit(1); } echo PHP_EOL . "All done, exiting." . PHP_EOL;
public function testVerifyingUsuallyKeepsFilenames() { $v = new PharUtil_RemotePharVerifier($this->fetch_dir, $this->verified_dir, $this->getPubKey()); $ok = $v->fetch($this->remote_dir . 'test.phar'); $this->assertEquals('test.phar', basename($ok)); }