{"record":{"id":"c3017bcb8e6c58b2","repo":"passbolt/passbolt_api","slug":"the-key-0-was-not-found-in-the-keyring","errorCode":null,"errorMessage":"The key {0} was not found in the keyring","messagePattern":"The key (.+?) was not found in the keyring","errorType":"exception","errorClass":"Cake\\Core\\Exception\\CakeException","httpStatus":null,"severity":"error","filePath":"src/Utility/OpenPGP/Traits/OpenPGPCommonAssertsTrait.php","lineNumber":55,"sourceCode":"            throw new CakeException($msg);\n        }\n        if ($m !== $marker) {\n            throw new CakeException($msg);\n        }\n\n        return true;\n    }\n\n    /**\n     * Assert key is in the keyring\n     *\n     * @param string $fingerprint fingerprint\n     * @return void\n     */\n    public function assertKeyInKeyring(string $fingerprint): void\n    {\n        if (!$this->isKeyInKeyring($fingerprint)) {\n            throw new CakeException(__('The key {0} was not found in the keyring', $fingerprint));\n        }\n    }\n\n    /**\n     * Assert the signature key is set\n     *\n     * @throws \\Cake\\Core\\Exception\\CakeException if not signature key is set\n     * @return void\n     */\n    public function assertSignKey(): void\n    {\n        if (empty($this->_signKeyFingerprint)) {\n            throw new CakeException('Can not sign without a key. Set a sign key first.');\n        }\n    }\n\n    /**\n     * Assert the verification key is set","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Utility/OpenPGP/Traits/OpenPGPCommonAssertsTrait.php#L37-L73","documentation":"OpenPGPCommonAssertsTrait::assertKeyInKeyring() is a guard method that verifies a given fingerprint exists in the GnuPG keyring before performing key operations. It throws a CakeException when isKeyInKeyring() reports the fingerprint is absent, stopping operations that would otherwise fail later inside GnuPG with less clear errors.","triggerScenarios":"Calling assertKeyInKeyring($fingerprint) with a fingerprint that is not imported into the keyring of the configured GNUPGHOME — e.g. verifying or decrypting with a recipient/sender key that was never imported, or a fingerprint with wrong casing/spaces.","commonSituations":"Missing public key import during setup or deployment (fresh container with empty GNUPGHOME), server key rotation where the old key was deleted, typo in fingerprint config, tests running as a user without the keyring, or keyring path misconfiguration pointing at an empty directory.","solutions":["Import the missing key into the keyring (e.g. `gpg --home <GNUPGHOME> --import key.asc`) or re-run passbolt's key import command.","Verify the fingerprint string matches exactly (40 hex chars, no stray whitespace) what `gpg --fingerprint` shows.","Check the GNUPGHOME environment/config points to the keyring that actually contains the key and is readable by the PHP process user.","If the key was rotated, update the application configuration to reference the new fingerprint."],"exampleFix":"// before\n$gpg->assertKeyInKeyring($fingerprint); // throws if not imported\n// after\nif (!$gpg->isKeyInKeyring($fingerprint)) {\n    $gpg->importKeyIntoKeyring(file_get_contents($keyPath));\n}\n$gpg->assertKeyInKeyring($fingerprint);","handlingStrategy":"validation","validationCode":"if (!preg_match('/^[0-9A-F]{40}$/i', $fingerprint) || !$gpg->isKeyInKeyring($fingerprint)) {\n    $gpg->importKeyIntoKeyring($keyData); // or skip with a clear message\n}","typeGuard":"function keyExistsInKeyring($gpg, string $fingerprint): bool {\n    return is_string($fingerprint) && preg_match('/^[0-9A-F]{40}$/i', $fingerprint) === 1\n        && $gpg->isKeyInKeyring($fingerprint);\n}","tryCatchPattern":"try {\n    $gpg->assertKeyInKeyring($fingerprint);\n} catch (\\Cake\\Core\\Exception\\CakeException $e) {\n    // key missing: import it or report a 4xx-style configuration problem\n    $this->importMissingKey($fingerprint);\n}","preventionTips":["Import all required keys (server key, user keys) as part of deployment/setup scripts.","Normalize fingerprints (strip spaces, uppercase) before use.","Point GNUPGHOME consistently in config and make it readable by the PHP user.","Add a health check that verifies configured fingerprints exist in the keyring at startup."],"tags":["openpgp","gnupg","keyring","fingerprint"],"backgroundTag":"resource-not-found","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}