From 4efa260e22648741cb25f2d8d51418c3491c46a9 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 15 Feb 2021 08:23:56 +0100 Subject: Update to 1.5.0RC1 open https://github.com/php-gnupg/php-gnupg/pull/25 missing files in pecl archive open https://github.com/php-gnupg/php-gnupg/pull/26 also cleanup socket files open https://github.com/php-gnupg/php-gnupg/pull/27 fix build with old libgpgme 1.3 use gnupg version 2 (Fedora and EL-8) --- .gitignore | 2 + PHPINFO | 6 + REFLECTION | 371 ++++++++++++++++++++++++++++++++++++++++++++-------- gnupg-build.patch | 73 +++++++++++ gnupgt.inc | 211 ++++++++++++++++++++++++++++++ php-pecl-gnupg.spec | 74 +++++------ vars.inc | 69 ++++++++++ 7 files changed, 714 insertions(+), 92 deletions(-) create mode 100644 PHPINFO create mode 100644 gnupg-build.patch create mode 100644 gnupgt.inc create mode 100644 vars.inc diff --git a/.gitignore b/.gitignore index 1ab5c4f..01f0400 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +clog package-*.xml *.tgz +*.tar.bz2 *.tar.gz *.tar.xz *.tar.xz.asc diff --git a/PHPINFO b/PHPINFO new file mode 100644 index 0000000..c81c7ec --- /dev/null +++ b/PHPINFO @@ -0,0 +1,6 @@ + +gnupg + +gnupg support => enabled +GPGme Version => 1.14.0 +Extension Version => 1.5.0RC1 diff --git a/REFLECTION b/REFLECTION index 970733d..33e0a7e 100644 --- a/REFLECTION +++ b/REFLECTION @@ -1,39 +1,65 @@ -Extension [ extension #86 gnupg version 1.4.0 ] { - - - Constants [25] { - Constant [ integer GNUPG_SIG_MODE_NORMAL ] { 0 } - Constant [ integer GNUPG_SIG_MODE_DETACH ] { 1 } - Constant [ integer GNUPG_SIG_MODE_CLEAR ] { 2 } - Constant [ integer GNUPG_VALIDITY_UNKNOWN ] { 0 } - Constant [ integer GNUPG_VALIDITY_UNDEFINED ] { 1 } - Constant [ integer GNUPG_VALIDITY_NEVER ] { 2 } - Constant [ integer GNUPG_VALIDITY_MARGINAL ] { 3 } - Constant [ integer GNUPG_VALIDITY_FULL ] { 4 } - Constant [ integer GNUPG_VALIDITY_ULTIMATE ] { 5 } - Constant [ integer GNUPG_PROTOCOL_OpenPGP ] { 0 } - Constant [ integer GNUPG_PROTOCOL_CMS ] { 1 } - Constant [ integer GNUPG_SIGSUM_VALID ] { 1 } - Constant [ integer GNUPG_SIGSUM_GREEN ] { 2 } - Constant [ integer GNUPG_SIGSUM_RED ] { 4 } - Constant [ integer GNUPG_SIGSUM_KEY_REVOKED ] { 16 } - Constant [ integer GNUPG_SIGSUM_KEY_EXPIRED ] { 32 } - Constant [ integer GNUPG_SIGSUM_SIG_EXPIRED ] { 64 } - Constant [ integer GNUPG_SIGSUM_KEY_MISSING ] { 128 } - Constant [ integer GNUPG_SIGSUM_CRL_MISSING ] { 256 } - Constant [ integer GNUPG_SIGSUM_CRL_TOO_OLD ] { 512 } - Constant [ integer GNUPG_SIGSUM_BAD_POLICY ] { 1024 } - Constant [ integer GNUPG_SIGSUM_SYS_ERROR ] { 2048 } - Constant [ integer GNUPG_ERROR_WARNING ] { 1 } - Constant [ integer GNUPG_ERROR_EXCEPTION ] { 2 } - Constant [ integer GNUPG_ERROR_SILENT ] { 3 } +Extension [ extension #120 gnupg version 1.5.0RC1 ] { + + - Constants [36] { + Constant [ int GNUPG_SIG_MODE_NORMAL ] { 0 } + Constant [ int GNUPG_SIG_MODE_DETACH ] { 1 } + Constant [ int GNUPG_SIG_MODE_CLEAR ] { 2 } + Constant [ int GNUPG_VALIDITY_UNKNOWN ] { 0 } + Constant [ int GNUPG_VALIDITY_UNDEFINED ] { 1 } + Constant [ int GNUPG_VALIDITY_NEVER ] { 2 } + Constant [ int GNUPG_VALIDITY_MARGINAL ] { 3 } + Constant [ int GNUPG_VALIDITY_FULL ] { 4 } + Constant [ int GNUPG_VALIDITY_ULTIMATE ] { 5 } + Constant [ int GNUPG_PROTOCOL_OpenPGP ] { 0 } + Constant [ int GNUPG_PROTOCOL_CMS ] { 1 } + Constant [ int GNUPG_SIGSUM_VALID ] { 1 } + Constant [ int GNUPG_SIGSUM_GREEN ] { 2 } + Constant [ int GNUPG_SIGSUM_RED ] { 4 } + Constant [ int GNUPG_SIGSUM_KEY_REVOKED ] { 16 } + Constant [ int GNUPG_SIGSUM_KEY_EXPIRED ] { 32 } + Constant [ int GNUPG_SIGSUM_SIG_EXPIRED ] { 64 } + Constant [ int GNUPG_SIGSUM_KEY_MISSING ] { 128 } + Constant [ int GNUPG_SIGSUM_CRL_MISSING ] { 256 } + Constant [ int GNUPG_SIGSUM_CRL_TOO_OLD ] { 512 } + Constant [ int GNUPG_SIGSUM_BAD_POLICY ] { 1024 } + Constant [ int GNUPG_SIGSUM_SYS_ERROR ] { 2048 } + Constant [ int GNUPG_ERROR_WARNING ] { 1 } + Constant [ int GNUPG_ERROR_EXCEPTION ] { 2 } + Constant [ int GNUPG_ERROR_SILENT ] { 3 } + Constant [ int GNUPG_PK_RSA ] { 1 } + Constant [ int GNUPG_PK_RSA_E ] { 2 } + Constant [ int GNUPG_PK_RSA_S ] { 3 } + Constant [ int GNUPG_PK_DSA ] { 17 } + Constant [ int GNUPG_PK_ELG ] { 20 } + Constant [ int GNUPG_PK_ELG_E ] { 16 } + Constant [ int GNUPG_PK_ECC ] { 18 } + Constant [ int GNUPG_PK_ECDSA ] { 301 } + Constant [ int GNUPG_PK_ECDH ] { 302 } + Constant [ int GNUPG_PK_EDDSA ] { 303 } + Constant [ string GNUPG_GPGME_VERSION ] { 1.14.0 } } - Functions { Function [ function gnupg_init ] { + + - Parameters [1] { + Parameter #0 [ $options ] + } } Function [ function gnupg_keyinfo ] { + + - Parameters [3] { + Parameter #0 [ $res ] + Parameter #1 [ $pattern ] + Parameter #2 [ $secret_only ] + } } Function [ function gnupg_sign ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $text ] + } } Function [ function gnupg_verify ] { @@ -45,26 +71,83 @@ Extension [ extension #86 gnupg version 1.4.0 ] { } } Function [ function gnupg_clearsignkeys ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } } Function [ function gnupg_clearencryptkeys ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } } Function [ function gnupg_cleardecryptkeys ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } } Function [ function gnupg_setarmor ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $armor ] + } } Function [ function gnupg_encrypt ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $text ] + } } Function [ function gnupg_decrypt ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $enctext ] + } } Function [ function gnupg_export ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $pattern ] + } } Function [ function gnupg_import ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $kye ] + } + } + Function [ function gnupg_getengineinfo ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } } Function [ function gnupg_getprotocol ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } } Function [ function gnupg_setsignmode ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $signmode ] + } } Function [ function gnupg_encryptsign ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $text ] + } } Function [ function gnupg_decryptverify ] { @@ -75,52 +158,110 @@ Extension [ extension #86 gnupg version 1.4.0 ] { } } Function [ function gnupg_geterror ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } + } + Function [ function gnupg_geterrorinfo ] { + + - Parameters [1] { + Parameter #0 [ $res ] + } } Function [ function gnupg_addsignkey ] { + + - Parameters [3] { + Parameter #0 [ $res ] + Parameter #1 [ $kye ] + Parameter #2 [ $passphrase ] + } } Function [ function gnupg_addencryptkey ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $kye ] + } } Function [ function gnupg_adddecryptkey ] { + + - Parameters [3] { + Parameter #0 [ $res ] + Parameter #1 [ $kye ] + Parameter #2 [ $passphrase ] + } } Function [ function gnupg_deletekey ] { + + - Parameters [3] { + Parameter #0 [ $res ] + Parameter #1 [ $kye ] + Parameter #2 [ $allow_secret ] + } } Function [ function gnupg_gettrustlist ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $pattern ] + } } Function [ function gnupg_listsignatures ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $kyeid ] + } } Function [ function gnupg_seterrormode ] { + + - Parameters [2] { + Parameter #0 [ $res ] + Parameter #1 [ $errnmode ] + } } } - Classes [2] { Class [ class gnupg ] { - - Constants [25] { - Constant [ integer SIG_MODE_NORMAL ] { 0 } - Constant [ integer SIG_MODE_DETACH ] { 1 } - Constant [ integer SIG_MODE_CLEAR ] { 2 } - Constant [ integer VALIDITY_UNKNOWN ] { 0 } - Constant [ integer VALIDITY_UNDEFINED ] { 1 } - Constant [ integer VALIDITY_NEVER ] { 2 } - Constant [ integer VALIDITY_MARGINAL ] { 3 } - Constant [ integer VALIDITY_FULL ] { 4 } - Constant [ integer VALIDITY_ULTIMATE ] { 5 } - Constant [ integer PROTOCOL_OpenPGP ] { 0 } - Constant [ integer PROTOCOL_CMS ] { 1 } - Constant [ integer SIGSUM_VALID ] { 1 } - Constant [ integer SIGSUM_GREEN ] { 2 } - Constant [ integer SIGSUM_RED ] { 4 } - Constant [ integer SIGSUM_KEY_REVOKED ] { 16 } - Constant [ integer SIGSUM_KEY_EXPIRED ] { 32 } - Constant [ integer SIGSUM_SIG_EXPIRED ] { 64 } - Constant [ integer SIGSUM_KEY_MISSING ] { 128 } - Constant [ integer SIGSUM_CRL_MISSING ] { 256 } - Constant [ integer SIGSUM_CRL_TOO_OLD ] { 512 } - Constant [ integer SIGSUM_BAD_POLICY ] { 1024 } - Constant [ integer SIGSUM_SYS_ERROR ] { 2048 } - Constant [ integer ERROR_WARNING ] { 1 } - Constant [ integer ERROR_EXCEPTION ] { 2 } - Constant [ integer ERROR_SILENT ] { 3 } + - Constants [35] { + Constant [ public int SIG_MODE_NORMAL ] { 0 } + Constant [ public int SIG_MODE_DETACH ] { 1 } + Constant [ public int SIG_MODE_CLEAR ] { 2 } + Constant [ public int VALIDITY_UNKNOWN ] { 0 } + Constant [ public int VALIDITY_UNDEFINED ] { 1 } + Constant [ public int VALIDITY_NEVER ] { 2 } + Constant [ public int VALIDITY_MARGINAL ] { 3 } + Constant [ public int VALIDITY_FULL ] { 4 } + Constant [ public int VALIDITY_ULTIMATE ] { 5 } + Constant [ public int PROTOCOL_OpenPGP ] { 0 } + Constant [ public int PROTOCOL_CMS ] { 1 } + Constant [ public int SIGSUM_VALID ] { 1 } + Constant [ public int SIGSUM_GREEN ] { 2 } + Constant [ public int SIGSUM_RED ] { 4 } + Constant [ public int SIGSUM_KEY_REVOKED ] { 16 } + Constant [ public int SIGSUM_KEY_EXPIRED ] { 32 } + Constant [ public int SIGSUM_SIG_EXPIRED ] { 64 } + Constant [ public int SIGSUM_KEY_MISSING ] { 128 } + Constant [ public int SIGSUM_CRL_MISSING ] { 256 } + Constant [ public int SIGSUM_CRL_TOO_OLD ] { 512 } + Constant [ public int SIGSUM_BAD_POLICY ] { 1024 } + Constant [ public int SIGSUM_SYS_ERROR ] { 2048 } + Constant [ public int ERROR_WARNING ] { 1 } + Constant [ public int ERROR_EXCEPTION ] { 2 } + Constant [ public int ERROR_SILENT ] { 3 } + Constant [ public int PK_RSA ] { 1 } + Constant [ public int PK_RSA_E ] { 2 } + Constant [ public int PK_RSA_S ] { 3 } + Constant [ public int PK_DSA ] { 17 } + Constant [ public int PK_ELG ] { 20 } + Constant [ public int PK_ELG_E ] { 16 } + Constant [ public int PK_ECC ] { 18 } + Constant [ public int PK_ECDSA ] { 301 } + Constant [ public int PK_ECDH ] { 302 } + Constant [ public int PK_EDDSA ] { 303 } } - Static properties [0] { @@ -132,8 +273,20 @@ Extension [ extension #86 gnupg version 1.4.0 ] { - Properties [0] { } - - Methods [23] { + - Methods [26] { + Method [ public method __construct ] { + + - Parameters [1] { + Parameter #0 [ $options ] + } + } + Method [ public method keyinfo ] { + + - Parameters [2] { + Parameter #0 [ $pattern ] + Parameter #1 [ $secret_only ] + } } Method [ public method verify ] { @@ -145,43 +298,102 @@ Extension [ extension #86 gnupg version 1.4.0 ] { } } + Method [ public method getengineinfo ] { + + - Parameters [0] { + } + } + Method [ public method geterror ] { + + - Parameters [0] { + } + } + + Method [ public method geterrorinfo ] { + + - Parameters [0] { + } } Method [ public method clearsignkeys ] { + + - Parameters [0] { + } } Method [ public method clearencryptkeys ] { + + - Parameters [0] { + } } Method [ public method cleardecryptkeys ] { + + - Parameters [0] { + } } Method [ public method setarmor ] { + + - Parameters [1] { + Parameter #0 [ $armor ] + } } Method [ public method encrypt ] { + + - Parameters [1] { + Parameter #0 [ $text ] + } } Method [ public method decrypt ] { + + - Parameters [1] { + Parameter #0 [ $enctext ] + } } Method [ public method export ] { + + - Parameters [1] { + Parameter #0 [ $pattern ] + } } Method [ public method import ] { + + - Parameters [1] { + Parameter #0 [ $kye ] + } } Method [ public method getprotocol ] { + + - Parameters [0] { + } } Method [ public method setsignmode ] { + + - Parameters [1] { + Parameter #0 [ $signmode ] + } } Method [ public method sign ] { + + - Parameters [1] { + Parameter #0 [ $text ] + } } Method [ public method encryptsign ] { + + - Parameters [1] { + Parameter #0 [ $text ] + } } Method [ public method decryptverify ] { @@ -193,24 +405,55 @@ Extension [ extension #86 gnupg version 1.4.0 ] { } Method [ public method addsignkey ] { + + - Parameters [2] { + Parameter #0 [ $kye ] + Parameter #1 [ $passphrase ] + } } Method [ public method addencryptkey ] { + + - Parameters [1] { + Parameter #0 [ $kye ] + } } Method [ public method adddecryptkey ] { + + - Parameters [2] { + Parameter #0 [ $kye ] + Parameter #1 [ $passphrase ] + } } Method [ public method deletekey ] { + + - Parameters [2] { + Parameter #0 [ $kye ] + Parameter #1 [ $allow_secret ] + } } Method [ public method gettrustlist ] { + + - Parameters [1] { + Parameter #0 [ $pattern ] + } } Method [ public method listsignatures ] { + + - Parameters [1] { + Parameter #0 [ $kyeid ] + } } Method [ public method seterrormode ] { + + - Parameters [1] { + Parameter #0 [ $errnmode ] + } } } } @@ -231,21 +474,39 @@ Extension [ extension #86 gnupg version 1.4.0 ] { - Methods [6] { Method [ public method __construct ] { + + - Parameters [0] { + } } Method [ public method current ] { + + - Parameters [0] { + } } Method [ public method key ] { + + - Parameters [0] { + } } Method [ public method next ] { + + - Parameters [0] { + } } Method [ public method rewind ] { + + - Parameters [0] { + } } Method [ public method valid ] { + + - Parameters [0] { + } } } } diff --git a/gnupg-build.patch b/gnupg-build.patch new file mode 100644 index 0000000..cedea9f --- /dev/null +++ b/gnupg-build.patch @@ -0,0 +1,73 @@ +From 618e7ffc698f948dfe4feef38258e42a7c24130e Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Mon, 15 Feb 2021 08:04:31 +0100 +Subject: [PATCH] fix build with libgpgme 1.3 + +--- + gnupg.c | 12 ++++-------- + 1 file changed, 4 insertions(+), 8 deletions(-) + +diff --git a/gnupg.c b/gnupg.c +index 3ec2f07..67e8c7f 100644 +--- a/gnupg.c ++++ b/gnupg.c +@@ -170,7 +170,9 @@ static void php_gnupg_this_make(PHPC_THIS_DECLARE(gnupg), zval *options TSRMLS_D + ctx, GPGME_PROTOCOL_OpenPGP, file_name, home_dir); + } + gpgme_set_armor(ctx, 1); ++#if GPGME_VERSION_NUMBER >= 0x010400 /* GPGME >= 1.4.0 */ + gpgme_set_pinentry_mode(ctx, GPGME_PINENTRY_MODE_LOOPBACK); ++#endif + } + } + /* }}} */ +@@ -591,10 +593,8 @@ PHP_MINIT_FUNCTION(gnupg) + #if GPGME_VERSION_NUMBER >= 0x010500 /* GPGME >= 1.5.0 */ + PHP_GNUPG_SET_CLASS_CONST("PK_ECC", GPGME_PK_ECC); + #endif /* gpgme >= 1.5.0 */ +-#if GPGME_VERSION_NUMBER >= 0x010300 /* GPGME >= 1.3.0 */ + PHP_GNUPG_SET_CLASS_CONST("PK_ECDSA", GPGME_PK_ECDSA); + PHP_GNUPG_SET_CLASS_CONST("PK_ECDH", GPGME_PK_ECDH); +-#endif /* gpgme >= 1.3.0 */ + #if GPGME_VERSION_NUMBER >= 0x010700 /* GPGME >= 1.7.0 */ + PHP_GNUPG_SET_CLASS_CONST("PK_EDDSA", GPGME_PK_EDDSA); + #endif /* gpgme >= 1.7.0 */ +@@ -633,10 +633,8 @@ PHP_MINIT_FUNCTION(gnupg) + #if GPGME_VERSION_NUMBER >= 0x010500 /* GPGME >= 1.5.0 */ + PHP_GNUPG_REG_CONST("GNUPG_PK_ECC", GPGME_PK_ECC); + #endif /* gpgme >= 1.5.0 */ +-#if GPGME_VERSION_NUMBER >= 0x010300 /* GPGME >= 1.3.0 */ + PHP_GNUPG_REG_CONST("GNUPG_PK_ECDSA", GPGME_PK_ECDSA); + PHP_GNUPG_REG_CONST("GNUPG_PK_ECDH", GPGME_PK_ECDH); +-#endif /* gpgme >= 1.3.0 */ + #if GPGME_VERSION_NUMBER >= 0x010700 /* GPGME >= 1.7.0 */ + PHP_GNUPG_REG_CONST("GNUPG_PK_EDDSA", GPGME_PK_EDDSA); + #endif /* gpgme >= 1.7.0 */ +@@ -1099,9 +1097,7 @@ PHP_FUNCTION(gnupg_keyinfo) + PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, revoked, gpgme_subkey); + PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, can_certify, gpgme_subkey); + PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, can_authenticate, gpgme_subkey); +-#if GPGME_VERSION_NUMBER >= 0x010100 /* GPGME >= 1.1.0 */ + PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, is_qualified, gpgme_subkey); +-#endif /* gpgme >= 1.1.0 */ + #if GPGME_VERSION_NUMBER >= 0x010900 /* GPGME >= 1.9.0 */ + PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, is_de_vs, gpgme_subkey); + #endif /* gpgme >= 1.9.0 */ +@@ -1117,15 +1113,15 @@ PHP_FUNCTION(gnupg_keyinfo) + PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(subkey, keygrip, gpgme_subkey); + } + #endif /* gpgme >= 1.7.0 */ +-#if GPGME_VERSION_NUMBER >= 0x010200 /* GPGME >= 1.2.0 */ + PHP_GNUPG_ARRAY_ADD_ASSOC_BOOL(subkey, is_cardkey, gpgme_subkey); + if (gpgme_subkey->card_number) { + PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(subkey, card_number, gpgme_subkey); + } +-#endif /* gpgme >= 1.2.0 */ ++#if GPGME_VERSION_NUMBER >= 0x010403 /* GPGME >= 1.4.3 */ + if (gpgme_subkey->curve) { + PHP_GNUPG_ARRAY_ADD_ASSOC_CSTR(subkey, curve, gpgme_subkey); + } ++#endif + + PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL( + PHPC_VAL_CAST_TO_PZVAL(subkeys), diff --git a/gnupgt.inc b/gnupgt.inc new file mode 100644 index 0000000..c31415d --- /dev/null +++ b/gnupgt.inc @@ -0,0 +1,211 @@ +import($testkey); + } + + /** + * Delete all keys. + * @param null|string $homeDir + */ + static public function delete_key($homeDir = null) + { + if (is_null($homeDir)) { + $homeDir = self::get_home_dir(); + } + if (!is_dir($homeDir)) { + return; + } + foreach (glob($homeDir . '/*') as $filename) { + if (!is_dir($filename)) { + unlink($filename); + } + } + $privKeyDir = self::get_priv_key_dir($homeDir); + if (is_dir($privKeyDir)) { + foreach (glob($privKeyDir . '/*') as $key) { + unlink($key); + } + rmdir($privKeyDir); + } + rmdir($homeDir); + } + + /** + * Initialize key directory. + */ + static public function init_key_dir() + { + mkdir(self::get_home_dir()); + mkdir(self::get_priv_key_dir(), 0700); + } + + /** + * Reset all keys. + */ + static public function reset_key() + { + self::delete_key(); + self::init_key_dir(); + } + + /** + * Get home directory. + * + * @return string + */ + static private function get_home_dir() + { + return __DIR__ . '/home'; + } + + /** + * Get private key directory (for GPG2). + * @param null|string $homeDir + * @return string + */ + static private function get_priv_key_dir($homeDir = null) + { + if (is_null($homeDir)) { + $homeDir = self::get_home_dir(); + } + return $homeDir . '/private-keys-v1.d'; + } + + /** + * Print error message and return false. + * + * @param string $msg + * @return bool + */ + static private function error($msg) + { + echo "ERROR: " . $msg; + return false; + } + + /** + * Check single array value. + * + * @param mixed $expected + * @param array $a + * @param string $key1 + * @return bool + */ + static public function check_array($expected, $a, $key1) + { + $args = func_get_args(); + $keys = array_splice($args, 2); + $value = $a; + foreach ($keys as $key) { + if (!isset($value[$key])) { + return self::error("key $key not found in the array"); + } + $value = $value[$key]; + } + if ($value !== $expected) { + + return self::error( + sprintf( + "key %s value %s does not match expected %s\n", + $key, + var_export($value, true), + var_export($expected, true) + ) + ); + } + + return true; + } + + /** + * Check single array value but only for GpgME version higher than supplied. + * + * @param mixed $expected + * @param array $a + * @param string $key1 + * @return bool + */ + static public function check_array_from_version($version, $expected, $a, $key1) + { + if (version_compare(GNUPG_GPGME_VERSION, $version) < 0) { + return true; + } + + $args = func_get_args(); + return call_user_func_array('gnupgt::check_array', array_splice($args, 1)); + } + + /** + * Check keyinfo for var key + * + * @param $ret + * @param $secret_only + */ + static public function check_keyinfo($ret, $secret_only) { + self::check_array(false, $ret, 0, 'disabled'); + self::check_array(false, $ret, 0, 'expired'); + self::check_array(false, $ret, 0, 'revoked'); + self::check_array($secret_only, $ret, 0, 'is_secret'); + self::check_array(true, $ret, 0, 'can_sign'); + self::check_array(true, $ret, 0, 'can_encrypt'); + // uid + self::check_array('PHP GnuPG', $ret, 0, 'uids', 0, 'name'); + self::check_array('', $ret, 0, 'uids', 0, 'comment'); + self::check_array('gnupg@php.net', $ret, 0, 'uids', 0, 'email'); + self::check_array('PHP GnuPG ', $ret, 0, 'uids', 0, 'uid'); + self::check_array(false, $ret, 0, 'uids', 0, 'revoked'); + self::check_array(false, $ret, 0, 'uids', 0, 'invalid'); + self::check_array(false, $ret, 0, 'uids', 0, 'invalid'); + // subkey 1 + self::check_array("2DF0DD02DC9B70B7F64F572E669E775E0A6284B3", $ret, 0, 'subkeys', 0, 'fingerprint'); + self::check_array("669E775E0A6284B3", $ret, 0, 'subkeys', 0, 'keyid'); + self::check_array(1567958444, $ret, 0, 'subkeys', 0, 'timestamp'); + self::check_array(0, $ret, 0, 'subkeys', 0, 'expires'); + self::check_array($secret_only, $ret, 0, 'subkeys', 0, 'is_secret'); + self::check_array(false, $ret, 0, 'subkeys', 0, 'can_encrypt'); + self::check_array(true, $ret, 0, 'subkeys', 0, 'can_sign'); + self::check_array(false, $ret, 0, 'subkeys', 0, 'disabled'); + self::check_array(false, $ret, 0, 'subkeys', 0, 'expired'); + self::check_array(false, $ret, 0, 'subkeys', 0, 'revoked'); + self::check_array(true, $ret, 0, 'subkeys', 0, 'can_certify'); + self::check_array(false, $ret, 0, 'subkeys', 0, 'can_authenticate'); + self::check_array(false, $ret, 0, 'subkeys', 0, 'is_qualified'); + // TODO: The is_de_vs seems to differ between gpg2 (true) and gpg1 (false) - differenatiate the test + //self::check_array_from_version('1.9.0', true, $ret, 0, 'subkeys', 0, 'is_de_vs'); + self::check_array(GNUPG_PK_RSA, $ret, 0, 'subkeys', 0, 'pubkey_algo'); + self::check_array(2048, $ret, 0, 'subkeys', 0, 'length'); + self::check_array_from_version('1.7.0', false, $ret, 0, 'subkeys', 0, 'is_cardkey'); + // subkey 2 + self::check_array("9E84AE800874DFF647B6062B46DCA9B3662C7DFC", $ret, 0, 'subkeys', 1, 'fingerprint'); + self::check_array("46DCA9B3662C7DFC", $ret, 0, 'subkeys', 1, 'keyid'); + self::check_array(1567958444, $ret, 0, 'subkeys', 1, 'timestamp'); + self::check_array(0, $ret, 0, 'subkeys', 1, 'expires'); + self::check_array($secret_only, $ret, 0, 'subkeys', 1, 'is_secret'); + self::check_array(true, $ret, 0, 'subkeys', 1, 'can_encrypt'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'can_sign'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'disabled'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'expired'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'revoked'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'can_certify'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'can_authenticate'); + self::check_array(false, $ret, 0, 'subkeys', 1, 'is_qualified'); + // TODO: The is_de_vs seems to differ between gpg2 (true) and gpg1 (false) - differenatiate the test + // self::check_array_from_version('1.9.0', true, $ret, 0, 'subkeys', 1, 'is_de_vs'); + self::check_array(GNUPG_PK_RSA, $ret, 0, 'subkeys', 1, 'pubkey_algo'); + self::check_array(2048, $ret, 0, 'subkeys', 1, 'length'); + self::check_array_from_version('1.7.0', false, $ret, 0, 'subkeys', 1, 'is_cardkey'); + } +} diff --git a/php-pecl-gnupg.spec b/php-pecl-gnupg.spec index 7cec4c6..f3624ea 100644 --- a/php-pecl-gnupg.spec +++ b/php-pecl-gnupg.spec @@ -19,35 +19,40 @@ %else %global ini_name 40-%{pecl_name}.ini %endif -#global prever RC2 +%global upstream_version 1.5.0 +%global upstream_prever RC1 Summary: Wrapper around the gpgme library Name: %{?sub_prefix}php-pecl-gnupg -Version: 1.4.0 -Release: 10%{?dist}%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')} +Version: %{upstream_version}%{?upstream_prever:~%{upstream_prever}} +Release: 1%{?dist}%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')} License: BSD URL: https://pecl.php.net/package/gnupg -Source0: https://pecl.php.net/get/%{pecl_name}-%{version}%{?prever}.tgz +Source0: https://pecl.php.net/get/%{pecl_name}-%{upstream_version}%{?upstream_prever}.tgz + +Source1: https://raw.githubusercontent.com/php-gnupg/php-gnupg/master/tests/gnupgt.inc +Source2: https://raw.githubusercontent.com/php-gnupg/php-gnupg/master/tests/vars.inc +Patch0: gnupg-build.patch BuildRequires: make BuildRequires: %{?dtsprefix}gcc BuildRequires: %{?scl_prefix}php-devel BuildRequires: %{?scl_prefix}php-pear BuildRequires: gpgme-devel -%if 0%{?fedora} >= 30 || 0%{?rhel} >= 6 +%if 0%{?rhel} == 7 BuildRequires: gnupg1 %else -BuildRequires: gnupg < 2 +BuildRequires: gnupg %endif Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} Requires: %{?scl_prefix}php(api) = %{php_core_api} # We force use of /usr/bin/gpg as gpg2 is unusable in non-interactive mode -%if 0%{?fedora} >= 30 || 0%{?rhel} >= 6 +%if 0%{?rhel} == 7 Requires: gnupg1 %else -Requires: gnupg < 2 +Requires: gnupg %endif %{?_sclreq:Requires: %{?scl_prefix}runtime%{?_sclreq}%{?_isa}} @@ -62,37 +67,14 @@ Provides: %{?scl_prefix}php-pecl-%{pecl_name}%{?_isa} = %{version}-%{releas %if "%{?packager}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} # Other third party repo stuff -Obsoletes: php53-pecl-%{pecl_name} <= %{version} -Obsoletes: php53u-pecl-%{pecl_name} <= %{version} -Obsoletes: php54-pecl-%{pecl_name} <= %{version} -Obsoletes: php54w-pecl-%{pecl_name} <= %{version} -%if "%{php_version}" > "5.5" -Obsoletes: php55u-pecl-%{pecl_name} <= %{version} -Obsoletes: php55w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "5.6" -Obsoletes: php56u-pecl-%{pecl_name} <= %{version} -Obsoletes: php56w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.0" -Obsoletes: php70u-pecl-%{pecl_name} <= %{version} -Obsoletes: php70w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.1" -Obsoletes: php71u-pecl-%{pecl_name} <= %{version} -Obsoletes: php71w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.2" -Obsoletes: php72u-pecl-%{pecl_name} <= %{version} -Obsoletes: php72w-pecl-%{pecl_name} <= %{version} -%endif %if "%{php_version}" > "7.3" Obsoletes: php73-pecl-%{pecl_name} <= %{version} -Obsoletes: php73w-pecl-%{pecl_name} <= %{version} %endif %if "%{php_version}" > "7.4" Obsoletes: php74-pecl-%{pecl_name} <= %{version} -Obsoletes: php74w-pecl-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "8.0" +Obsoletes: php80-pecl-%{pecl_name} <= %{version} %endif %endif @@ -119,13 +101,15 @@ cat >%{ini_name} << 'EOF' extension=%{pecl_name}.so EOF -mv %{pecl_name}-%{version}%{?prever} NTS +mv %{pecl_name}-%{upstream_version}%{?upstream_prever} NTS cd NTS +cp %{SOURCE1} %{SOURCE2} tests/ +%patch0 -p1 # Check extension version extver=$(sed -n '/#define PHP_GNUPG_VERSION/{s/.* "//;s/".*$//;p}' php_gnupg.h) -if test "x${extver}" != "x%{version}%{?prever}"; then - : Error: Upstream extension version is ${extver}, expecting %{version}%{?prever}. +if test "x${extver}" != "x%{upstream_version}%{?upstream_prever}"; then + : Error: Upstream extension version is ${extver}, expecting %{upstream_version}%{?upstream_prever}. exit 1 fi cd .. @@ -141,13 +125,19 @@ cp -r NTS ZTS export PHP_RPATH=no export CFLAGS="$RPM_OPT_FLAGS -D_FILE_OFFSET_BITS=64" +%if 0%{?rhel} == 7 export GPG1=$(which gpg1 2>/dev/null || which gpg) $GPG1 --version +%else +gpg --version +%endif peclbuild() { %{_bindir}/${1}ize %configure \ +%if 0%{?rhel} == 7 --with-gpg=$GPG1 \ +%endif --with-libdir=%{_lib} \ --with-php-config=%{_bindir}/${1}-config @@ -252,6 +242,16 @@ cd ../ZTS %changelog +* Mon Feb 15 2021 Remi Collet - 1.5.0~RC1-1 +- Update to 1.5.0RC1 +- open https://github.com/php-gnupg/php-gnupg/pull/25 + missing files in pecl archive +- open https://github.com/php-gnupg/php-gnupg/pull/26 + also cleanup socket files +- open https://github.com/php-gnupg/php-gnupg/pull/27 + fix build with old libgpgme 1.3 +- use gnupg version 2 (Fedora and EL-8) + * Tue Feb 2 2021 Remi Collet - 1.4.0-10 - EL-7 rebuild diff --git a/vars.inc b/vars.inc new file mode 100644 index 0000000..02d2819 --- /dev/null +++ b/vars.inc @@ -0,0 +1,69 @@ + -- cgit