{"record":{"id":"d4c8b7201c0d4902","repo":"passbolt/passbolt_api","slug":"the-user-armored-key-is-not-available-or-incomplete","errorCode":null,"errorMessage":"The user armored key is not available or incomplete.","messagePattern":"The user armored key is not available or incomplete\\.","errorType":"http","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"src/Service/OpenPGP/OpenPGPCommonUserOperationsTrait.php","lineNumber":121,"sourceCode":"     * @throws \\Cake\\Http\\Exception\\InternalErrorException if the user key cannot be loaded\n     */\n    private function assertUserKey(Gpgkey $userKey): void\n    {\n        if (!isset($userKey->armored_key) || !isset($userKey->fingerprint)) {\n            $msg = __('The user public key is not available or incomplete.');\n            throw new InternalErrorException($msg);\n        }\n\n        $fingerprint = $userKey->fingerprint;\n        if (!is_string($fingerprint) || !PublicKeyValidationService::isValidFingerprint($fingerprint)) {\n            $msg = __('The user public key fingerprint is not available or incomplete.');\n            throw new InternalErrorException($msg);\n        }\n\n        $armoredKey = $userKey->armored_key;\n        if (!is_string($armoredKey) || !PublicKeyValidationService::parseAndValidatePublicKey($armoredKey)) {\n            $msg = __('The user armored key is not available or incomplete.');\n            throw new InternalErrorException($msg);\n        }\n    }\n}\n","sourceCodeStart":103,"sourceCodeEnd":125,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/OpenPGP/OpenPGPCommonUserOperationsTrait.php#L103-L125","documentation":"InternalErrorException thrown by assertUserKey when the armored_key is not a string or fails PublicKeyValidationService::parseAndValidatePublicKey, meaning the stored armored key is unparseable or invalid OpenPGP. The trait refuses to load a key the GnuPG backend cannot use.","triggerScenarios":"setEncryptKeyWithUserKey or setVerifyKeyWithUserKey receives a Gpgkey whose armored_key is null, truncated, corrupt, or not a valid OpenPGP public key block (e.g. bad BEGIN/END headers, tampered content).","commonSituations":"Copy-paste truncation during key import; database charset/migration corruption; users submitting invalid key material that bypassed validation before storage.","solutions":["Re-import a valid armored public key for the user through the proper key setup flow.","Run the armored key through PublicKeyValidationService::parseAndValidatePublicKey before use to get a precise validation error.","Verify the gpgkeys.armored_key column content was not truncated (check length and headers).","Catch InternalErrorException and prompt the user to re-upload their key."],"exampleFix":"// before\n$gpg->setEncryptKeyWithUserKey($userKey);\n\n// after\ntry {\n    PublicKeyValidationService::parseAndValidatePublicKey($userKey->armored_key);\n} catch (CustomValidationException $e) {\n    throw new InternalErrorException(__('Stored key is invalid; re-import required.'), null, $e);\n}\n$gpg->setEncryptKeyWithUserKey($userKey);","handlingStrategy":"validation","validationCode":"// PHP\nif (!is_string($userKey->armored_key) || !PublicKeyValidationService::isParsableArmoredPublicKey($userKey->armored_key)) {\n    throw new BadRequestException(__('Stored armored key is invalid or corrupt.'));\n}","typeGuard":"function isUsableArmoredKey($armoredKey): bool {\n    return is_string($armoredKey)\n        && str_contains($armoredKey, '-----BEGIN PGP PUBLIC KEY BLOCK-----');\n}","tryCatchPattern":"try {\n    $gpg->setEncryptKeyWithUserKey($userKey);\n} catch (\\Cake\\Http\\Exception\\InternalErrorException $e) {\n    throw new BadRequestException(__('The user armored key is invalid; please re-upload your key.'));\n}","preventionTips":["Run PublicKeyValidationService::parseAndValidatePublicKey on every key before persisting it.","Check armored key headers and length after any DB migration or manual data import.","Never write user key material without going through the validated Gpgkeys save flow."],"tags":["openpgp","gpg","invalid-key","internal-error"],"backgroundTag":"invalid-argument-format","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"}