passbolt/passbolt_api · error · BadRequestException

The user identifier should be a valid UUID.

Error message

The user identifier should be a valid UUID.

What it means

Thrown by Gnupg::importKeyIntoKeyring when gnupg_import() raises an exception; the gnupg error text is appended. It means GnuPG could not accept the armored key material into its keyring at all (malformed key, keyring problem, or gnupg extension error).

Solutions

  1. Check the appended gnupg exception message for the specific gnupg error.
  2. Verify GNUPGHOME exists and is writable by the PHP user (pubring.gpg ownership).
  3. Validate the armored key with `gpg --show-keys` outside the app.
  4. Re-export the key in ASCII armor and retry.
  5. Test that the gnupg PHP extension works: `var_dump(gnupg_keylistiterator...)` or a minimal gnupg::import.

Example fix

// before
exec('gpg --import', $out); // manual shell import bypassing error handling
// after
$fingerprint = $gpg->importKeyIntoKeyring($armoredKey); // and check GNUPGHOME perms if it throws
Defensive patterns

Strategy: try-catch

Validate before calling

$gpg->getPublicKeyInfo($armoredKey); // throws early if the key is not parsable

Type guard

function isArmoredKey(string $s): bool {
    return is_string($s)
        && preg_match('/-----BEGIN PGP (PUBLIC|PRIVATE) KEY BLOCK-----/', $s) === 1;
}

Try / catch

try {
    $fp = $gpg->importKeyIntoKeyring($armoredKey);
} catch (\Cake\Core\Exception\Exception $e) {
    $this->log('gnupg import failed: ' . $e->getMessage());
    throw new KeyImportException(previous: $e);
}

Prevention

When it happens

Trigger: Calling importKeyIntoKeyring with corrupted/unparseable key data, or when the gnupg extension/keyring fails during import (e.g. GNUPGHOME not writable).

Common situations: GNUPGHOME directory not writable by the web server user; corrupted key from a bad copy/paste; gnupg module misconfiguration; keys larger than allowed limits.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at plugins/PassboltCe/AccountSettings/src/Model/Table/AccountSettingsTable.php:150

     */
    public function buildRules(RulesChecker $rules): RulesChecker
    {
        $rules->add($rules->existsIn(['user_id'], 'Users'));

        return $rules;
    }

    /**
     * Find all the settings for a given user
     *
     * @param string $userId uuid
     * @param array $whitelist example ['theme']
     * @return \Cake\ORM\Query\SelectQuery
     */
    public function findIndex(string $userId, array $whitelist): SelectQuery
    {
        if (!Validation::uuid($userId)) {
            throw new BadRequestException(__('The user identifier should be a valid UUID.'));
        }

        $props = [];
        foreach ($whitelist as $item) {
            $props[] = $this->propertyToPropertyId($item);
        }

        return $this->find()->where(['user_id' => $userId, 'property_id IN' => $props]);
    }

    /**
     * Find all the settings for a given user
     *
     * @param string $userId uuid
     * @param string $property The name of the property to get
     * @return \Passbolt\AccountSettings\Model\Entity\AccountSetting The first result from the ResultSet.
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When there is no first record.
     * @throws \Cake\Http\Exception\BadRequestException When the user ID is not valid.

View on GitHub (pinned to 31c1bbc10f)