passbolt/passbolt_api · error · InternalErrorException

The user armored key is not available or incomplete.

Error message

The user armored key is not available or incomplete.

What it means

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.

Solutions

  1. Re-import a valid armored public key for the user through the proper key setup flow.
  2. Run the armored key through PublicKeyValidationService::parseAndValidatePublicKey before use to get a precise validation error.
  3. Verify the gpgkeys.armored_key column content was not truncated (check length and headers).
  4. Catch InternalErrorException and prompt the user to re-upload their key.

Example fix

// before
$gpg->setEncryptKeyWithUserKey($userKey);

// after
try {
    PublicKeyValidationService::parseAndValidatePublicKey($userKey->armored_key);
} catch (CustomValidationException $e) {
    throw new InternalErrorException(__('Stored key is invalid; re-import required.'), null, $e);
}
$gpg->setEncryptKeyWithUserKey($userKey);
Defensive patterns

Strategy: validation

Validate before calling

// PHP
if (!is_string($userKey->armored_key) || !PublicKeyValidationService::isParsableArmoredPublicKey($userKey->armored_key)) {
    throw new BadRequestException(__('Stored armored key is invalid or corrupt.'));
}

Type guard

function isUsableArmoredKey($armoredKey): bool {
    return is_string($armoredKey)
        && str_contains($armoredKey, '-----BEGIN PGP PUBLIC KEY BLOCK-----');
}

Try / catch

try {
    $gpg->setEncryptKeyWithUserKey($userKey);
} catch (\Cake\Http\Exception\InternalErrorException $e) {
    throw new BadRequestException(__('The user armored key is invalid; please re-upload your key.'));
}

Prevention

When it happens

Trigger: 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).

Common situations: Copy-paste truncation during key import; database charset/migration corruption; users submitting invalid key material that bypassed validation before storage.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/d4c8b7201c0d4902. Report an issue: GitHub.

Appendix: source

Thrown at src/Service/OpenPGP/OpenPGPCommonUserOperationsTrait.php:121

     * @throws \Cake\Http\Exception\InternalErrorException if the user key cannot be loaded
     */
    private function assertUserKey(Gpgkey $userKey): void
    {
        if (!isset($userKey->armored_key) || !isset($userKey->fingerprint)) {
            $msg = __('The user public key is not available or incomplete.');
            throw new InternalErrorException($msg);
        }

        $fingerprint = $userKey->fingerprint;
        if (!is_string($fingerprint) || !PublicKeyValidationService::isValidFingerprint($fingerprint)) {
            $msg = __('The user public key fingerprint is not available or incomplete.');
            throw new InternalErrorException($msg);
        }

        $armoredKey = $userKey->armored_key;
        if (!is_string($armoredKey) || !PublicKeyValidationService::parseAndValidatePublicKey($armoredKey)) {
            $msg = __('The user armored key is not available or incomplete.');
            throw new InternalErrorException($msg);
        }
    }
}

View on GitHub (pinned to 31c1bbc10f)