Bug #17822 [Opn]: Missing keyId in KeyNotFoundException for decryption/verify process

From: Date: Thu, 26 Aug 2010 12:31:52 +0000
Subject: Bug #17822 [Opn]: Missing keyId in KeyNotFoundException for decryption/verify process
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-4687@lists.php.net to get a copy of this message
Edit report at http://pear.php.net/bugs/bug.php?id=17822&edit=1 ID: 17822 Updated by: alec@alec.pl Reported By: alec at alec dot pl Summary: Missing keyId in KeyNotFoundException for decryption/verify process Status: Open Type: Bug Package: Crypt_GPG Package Version: SVN PHP Version: Irrelevant Roadmap Versions: New Comment: --- GPG.old 2010-08-26 11:16:31.000000000 +0200 +++ GPG.php 2010-08-26 14:20:13.253145205 +0200 @@ -2394,7 +2394,7 @@ case Crypt_GPG::ERROR_KEY_NOT_FOUND: throw new Crypt_GPG_KeyNotFoundException( 'Public key required for data verification not in keyring.', - $code); + $code, $this->engine->getErrorKeyId()); default: throw new Crypt_GPG_Exception( 'Unknown error validating signature details. Please use the ' . --- Engine.old 2010-08-26 11:16:31.000000000 +0200 +++ Engine.php 2010-08-26 14:19:40.800391989 +0200 @@ -295,6 +295,14 @@ private $_errorFilename = ''; /** + * Key ID related to the error code of the current operation + * + * @var string + * @see Crypt_GPG_Engine::getErrorKeyId() + */ + private $_errorKeyId = ''; + + /** * The number of currently needed passphrases * * If this is not zero when the GPG command is completed, the error code is @@ -735,6 +743,24 @@ } // }}} + // {{{ getErrorKeyId() + + /** + * Gets the key ID related to the error code of the last executed operation + * + * This value is only meaningful after {@link Crypt_GPG_Engine::run()} has + * been executed. If there is no key ID related to the error, an empty string + * is returned. + * + * @return string the key ID related to the error code of the last executed + * operation. + */ + public function getErrorKeyId() + { + return $this->_errorKeyId; + } + + // }}} // {{{ setInput() /** @@ -936,6 +962,7 @@ case 'NO_PUBKEY': case 'NO_SECKEY': + $this->_errorKeyId = $tokens[1]; $this->_errorCode = Crypt_GPG::ERROR_KEY_NOT_FOUND; break; Previous Comments: ------------------------------------------------------------------------ [2010-08-26 11:06:05] alec -Summary: Missing keyId in KeyNotFoundException for decryption process +Summary: Missing keyId in KeyNotFoundException for decryption/verify process This patch is for decryption. I've found that key Id is also not set on verification. E.g. when there's no public key I got such responses: ERROR: gpg: Signature made Mon Aug 10 01:50:14 2009 CEST using DSA key ID B459AB58 ERROR: gpg: Can't check signature: No public key STATUS: ERRSIG 6BEFD4D6B459AB58 17 2 01 1249861814 9 STATUS: NO_PUBKEY 6BEFD4D6B459AB58 ------------------------------------------------------------------------ [2010-08-26 10:23:48] alec Description: ------------ When decryption fails because of lack of private key its ID is not set in exception object. Simple fix: --- DecryptStatusHandler.old 2010-08-26 11:16:31.000000000 +0200 +++ DecryptStatusHandler.php 2010-08-26 12:21:30.365249721 +0200 @@ -288,7 +288,7 @@ throw new Crypt_GPG_KeyNotFoundException( 'Cannot decrypt data. No suitable private key is in the ' . 'keyring. Import a suitable private key before trying to ' . - 'decrypt this data.', $code); + 'decrypt this data.', $code, $this->currentSubKeyId); case Crypt_GPG::ERROR_BAD_PASSPHRASE: $badPassphrases = array_diff_key( ------------------------------------------------------------------------ -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=17822&edit=1

« previous php.pear.bugs (#4687) next »