{"record":{"id":"7e1b2f2455fb31c6","repo":"passbolt/passbolt_api","slug":"the-openpgp-user-key-cannot-be-found-exception-message","errorCode":null,"errorMessage":"The OpenPGP user key cannot be found. {exception message}","messagePattern":"The OpenPGP user key cannot be found\\. (.+?)","errorType":"http","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataKeyShareDefaultService.php","lineNumber":217,"sourceCode":"    private function setKeyForVerify(OpenPGPBackend $gpg, ?string $createdBy = null): OpenPGPBackend\n    {\n        // Use server key if no user is defined in createdBy\n        if ($createdBy === null) {\n            return $this->setVerifyKeyWithServerKey($gpg);\n        }\n\n        // User key if createdBy is a user\n        try {\n            $usersTable = TableRegistry::getTableLocator()->get('Gpgkeys');\n            /** @var \\App\\Model\\Entity\\Gpgkey $userKey */\n            $userKey = $usersTable->find()\n                ->where(['user_id' => $createdBy])\n                ->orderBy(['created' => 'DESC'])\n                ->firstOrFail();\n        } catch (Exception $exception) {\n            $msg = __('The OpenPGP user key cannot be found.') . ' ';\n            $msg .= $exception->getMessage();\n            throw new InternalErrorException($msg, 500, $exception);\n        }\n\n        return $this->setVerifyKeyWithUserKey($gpg, $userKey);\n    }\n}\n","sourceCodeStart":199,"sourceCodeEnd":223,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataKeyShareDefaultService.php#L199-L223","documentation":"setKeyForVerify throws InternalErrorException when it cannot load the Gpgkey of the user identified by modified_by to configure the OpenPGP backend for signature verification. The lookup on the gpgkeys table with firstOrFail() found no record (or the query failed), so verification of the metadata private key signature cannot proceed.","triggerScenarios":"shareMetadataKeyWithUser passes serverMetadataPrivateKey->modified_by to setKeyForVerify; if that user id has no row in gpgkeys (user deleted, key never generated, orphaned modified_by referencing a removed user) or the query throws, this error fires with the underlying message appended.","commonSituations":"modified_by points to a user deleted via cascade or hard delete that left gpgkeys orphaned/missing; a metadata key created by a script/bypassing ORM so modified_by is invalid; user deleted but their metadata key edits remain.","solutions":["Find the user id in the error message and check whether the user and their gpgkeys row still exist","If the user was deleted, correct modified_by on the metadata_private_keys/metadata_keys row to an existing admin, or restore the user/key from backup","If the gpgkeys row is missing but the user exists, have the user complete setup or re-register their OpenPGP key","Null out/normalize modified_by data via a migration if it references historical deleted users"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"$user = $usersTable->find()->where(['id' => $modifiedBy])->first();\n$gpg = $user ? $gpgkeysTable->find()->where(['user_id' => $modifiedBy])->first() : null;\nif (!$user || !$gpg) {\n    throw new \\DomainException(\"modified_by {$modifiedBy} has no user/gpg key; fix data before sharing.\");\n}","typeGuard":"if (!is_string($modifiedBy) || !preg_match('/^[a-f0-9-]{36}$/i', $modifiedBy)) { return; }","tryCatchPattern":"try {\n    $service->shareMetadataKeysWithUser($uac, $userIds, $keyId);\n} catch (MetadataKeyShareException $e) {\n    if (str_contains($e->getMessage(), 'OpenPGP user key cannot be found')) {\n        // reassign modified_by or restore the deleted user/key before retrying\n    }\n}","preventionTips":["Prefer soft-deleting users so their gpgkeys rows remain for signature verification","Never null/void modified_by via raw SQL when editing metadata keys","After user deletion, audit metadata keys/rows referencing the deleted id","Back up gpgkeys before destructive user cleanup"],"tags":["openpgp","gpgkey","user-not-found","signature-verification"],"backgroundTag":"record-not-found","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}