From: Michael Wallner Date: Tue, 10 Mar 2015 10:38:16 +0000 (+0100) Subject: release v2.0.1 X-Git-Tag: v2.0.1 X-Git-Url: https://git.m6w6.name/?p=pharext%2Fpharext;a=commitdiff_plain;h=e3ff870fe1f8a3b3eb8f55eea68f6f61d99e640c release v2.0.1 --- diff --git a/bin/pharext b/bin/pharext index 857729d..1c9fdea 100755 Binary files a/bin/pharext and b/bin/pharext differ diff --git a/src/pharext/Openssl/PrivateKey.php b/src/pharext/Openssl/PrivateKey.php index 470983d..35c596a 100644 --- a/src/pharext/Openssl/PrivateKey.php +++ b/src/pharext/Openssl/PrivateKey.php @@ -5,10 +5,16 @@ namespace pharext\Openssl; class PrivateKey { /** - * OpenSSL pkey resource - * @var resource + * Private key + * @var string */ private $key; + + /** + * Public key + * @var string + */ + private $pub; /** * Read a private key @@ -17,10 +23,16 @@ class PrivateKey * @throws \Exception */ function __construct($file, $password) { - $this->key = openssl_pkey_get_private("file://$file", $password); - if (!is_resource($this->key)) { + /* there appears to be a bug with refcount handling of this + * resource; when the resource is stored as property, it cannot be + * "coerced to a private key" on openssl_sign() alter in another method + */ + $key = openssl_pkey_get_private("file://$file", $password); + if (!is_resource($key)) { throw new \Exception("Could not load private key"); } + openssl_pkey_export($key, $this->key); + $this->pub = openssl_pkey_get_details($key)["key"]; } /** @@ -37,9 +49,7 @@ class PrivateKey * @throws \Exception */ function exportPublicKey($file) { - if (!file_put_contents("$file.tmp", openssl_pkey_get_details($this->key)["key"]) - || !rename("$file.tmp", $file) - ) { + if (!file_put_contents("$file.tmp", $this->pub) || !rename("$file.tmp", $file)) { throw new \Exception(error_get_last()["message"]); } } diff --git a/src/pharext/Packager.php b/src/pharext/Packager.php index f268765..4d432ed 100644 --- a/src/pharext/Packager.php +++ b/src/pharext/Packager.php @@ -159,7 +159,7 @@ class Packager implements Command $this->info("Creating phar %s ...%s", $pkgtemp, $this->args->verbose ? "\n" : " "); try { $package = new Phar($pkgtemp); - + if ($this->args->sign) { $this->info("\nUsing private key to sign phar ... \n"); $privkey = new Openssl\PrivateKey(realpath($this->args->sign), $this->askpass()); diff --git a/src/pharext/Version.php b/src/pharext/Version.php index 50a2875..747aec6 100644 --- a/src/pharext/Version.php +++ b/src/pharext/Version.php @@ -2,4 +2,4 @@ namespace pharext; -const VERSION = "@PHAREXT_VERSION@"; +const VERSION = "2.0.1";