Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7611,6 +7611,18 @@ Do you want to overwrite it?</source>
<source>No valid UUID provided</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>evalByCredential is not supported at registration</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>evalByCredential is not empty, but allowedCredentials is</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Credential ID provided in evalByCredential not found</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown error</source>
<translation type="unfinished"></translation>
Expand Down
23 changes: 22 additions & 1 deletion src/browser/BrowserCbor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -171,6 +171,27 @@ QByteArray BrowserCbor::cborEncodeExtensionData(const QJsonObject& extensions) c
writer.endArray();
}

if (extensions.contains("prf")) {
const auto prfObject = extensions["prf"].toObject();
const auto salt = prfObject["eval"]["first"].toString();

if (salt.isEmpty()) {
writer.append("prf");
writer.startMap(1);
writer.append("enabled");
writer.append(true);
writer.endMap();
} else {
writer.append("prf");
writer.startMap(1);
writer.append("results");
writer.startMap(1);
writer.append("first");
writer.append(browserMessageBuilder()->getArrayFromBase64(salt));
writer.endMap();
}
}

writer.endMap();

return result;
Expand Down
8 changes: 7 additions & 1 deletion src/browser/BrowserMessageBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -156,6 +156,12 @@ QString BrowserMessageBuilder::getErrorMessage(const int errorCode) const
return QObject::tr("Challenge is shorter than required minimum length");
case ERROR_PASSKEYS_INVALID_USER_ID:
return QObject::tr("user.id does not match the required length");
case ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_SUPPORTED:
return QObject::tr("evalByCredential is not supported at registration");
case ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_EMPTY:
return QObject::tr("evalByCredential is not empty, but allowedCredentials is");
case ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_FOUND:
return QObject::tr("Credential ID provided in evalByCredential not found");
default:
return QObject::tr("Unknown error");
}
Expand Down
5 changes: 4 additions & 1 deletion src/browser/BrowserMessageBuilder.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -63,6 +63,9 @@ namespace
ERROR_PASSKEYS_UNKNOWN_ERROR = 31,
ERROR_PASSKEYS_INVALID_CHALLENGE = 32,
ERROR_PASSKEYS_INVALID_USER_ID = 33,
ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_SUPPORTED = 34,
ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_EMPTY = 35,
ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_FOUND = 36
};
}

Expand Down
18 changes: 15 additions & 3 deletions src/browser/BrowserPasskeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,22 @@ QJsonObject BrowserPasskeys::buildGetPublicKeyCredential(const QJsonObject& asse
const QString& credentialId,
const QString& userHandle,
const QString& privateKeyPem,
const QString& prfSecret,
QString* newPrfSecret,
const bool beFlag,
const bool bsFlag)
{
if (!passkeyUtils()->checkCredentialAssertionOptions(assertionOptions)) {
return {};
}

const auto authenticatorData = buildAuthenticatorData(
assertionOptions["rpId"].toString(), assertionOptions["extensions"].toString(), beFlag, bsFlag);
auto extensionObject = assertionOptions["extensionsObject"].toObject();
const auto allowCredentials = passkeyUtils()->getAllowedCredentialsFromAssertionOptions(assertionOptions);
const auto extensionData = passkeyUtils()->buildExtensionData(extensionObject, prfSecret, allowCredentials);
const auto extensions = browserMessageBuilder()->getBase64FromArray(extensionData.extensionData);

const auto authenticatorData =
buildAuthenticatorData(assertionOptions["rpId"].toString(), extensions, beFlag, bsFlag);
const auto clientDataJson = assertionOptions["clientDataJson"].toString();
const auto clientDataArray = clientDataJson.toUtf8();

Expand All @@ -143,10 +150,15 @@ QJsonObject BrowserPasskeys::buildGetPublicKeyCredential(const QJsonObject& asse
return {};
}

// New secret is generated
if (prfSecret.isEmpty() && !extensionData.prfSecret.isEmpty() && newPrfSecret) {
*newPrfSecret = extensionData.prfSecret;
}

QJsonObject responseObject;
responseObject["authenticatorData"] = browserMessageBuilder()->getBase64FromArray(authenticatorData);
responseObject["clientDataJSON"] = browserMessageBuilder()->getBase64FromArray(clientDataArray);
responseObject["clientExtensionResults"] = assertionOptions["clientExtensionResults"];
responseObject["clientExtensionResults"] = extensionData.extensionObject;
responseObject["signature"] = browserMessageBuilder()->getBase64FromArray(signature);
responseObject["userHandle"] = userHandle;

Expand Down
2 changes: 2 additions & 0 deletions src/browser/BrowserPasskeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class BrowserPasskeys : public QObject
const QString& credentialId,
const QString& userHandle,
const QString& privateKeyPem,
const QString& prfSecret,
QString* newPrfSecret,
const bool beFlag = DEFAULT_BE_FLAG,
const bool bsFlag = DEFAULT_BE_FLAG);

Expand Down
37 changes: 25 additions & 12 deletions src/browser/BrowserPasskeysClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -41,22 +41,22 @@ int BrowserPasskeysClient::getCredentialCreationOptions(const QJsonObject& publi

// Check validity of some basic values
const auto checkResultError = passkeyUtils()->checkLimits(publicKeyOptions);
if (checkResultError > 0) {
if (checkResultError > PASSKEYS_SUCCESS) {
return checkResultError;
}

// Get effective domain
QString effectiveDomain;
const auto effectiveDomainResponse = passkeyUtils()->getEffectiveDomain(origin, &effectiveDomain);
if (effectiveDomainResponse > 0) {
if (effectiveDomainResponse > PASSKEYS_SUCCESS) {
return effectiveDomainResponse;
}

// Validate RP ID
QString rpId;
const auto rpName = publicKeyOptions["rp"]["name"].toString();
const auto rpIdResponse = passkeyUtils()->validateRpId(publicKeyOptions["rp"]["id"], effectiveDomain, &rpId);
if (rpIdResponse > 0) {
if (rpIdResponse > PASSKEYS_SUCCESS) {
return rpIdResponse;
}

Expand Down Expand Up @@ -100,6 +100,15 @@ int BrowserPasskeysClient::getCredentialCreationOptions(const QJsonObject& publi

// Extensions
auto extensionObject = publicKeyOptions["extensions"].toObject();
if (extensionObject.contains("prf")) {
const auto prfObject = extensionObject["prf"].toObject();
if (prfObject.contains("evalByCredential")) {
// This is not supported at registration
return ERROR_PASSKEYS_EVAL_BY_CREDENTIAL_NOT_SUPPORTED;
}
}

// Parse extension data
const auto extensionData = passkeyUtils()->buildExtensionData(extensionObject);
const auto extensions = browserMessageBuilder()->getBase64FromArray(extensionData.extensionData);

Expand All @@ -112,14 +121,15 @@ int BrowserPasskeysClient::getCredentialCreationOptions(const QJsonObject& publi
credentialCreationOptions["credTypesAndPubKeyAlgs"] = pubKeyCredParams;
credentialCreationOptions["excludeCredentials"] = publicKeyOptions["excludeCredentials"];
credentialCreationOptions["extensions"] = extensions;
credentialCreationOptions["prfSecret"] = extensionData.prfSecret;
credentialCreationOptions["residentKey"] = isResidentKeyRequired;
credentialCreationOptions["rp"] = QJsonObject({{"id", rpId}, {"name", rpName}});
credentialCreationOptions["user"] = publicKeyOptions["user"];
credentialCreationOptions["userPresence"] = !isUserVerificationRequired;
credentialCreationOptions["userVerification"] = isUserVerificationRequired;

*result = credentialCreationOptions;
return 0;
return PASSKEYS_SUCCESS;
}

// Use an existing credential
Expand All @@ -135,21 +145,19 @@ int BrowserPasskeysClient::getAssertionOptions(const QJsonObject& publicKeyOptio
// Get effective domain
QString effectiveDomain;
const auto effectiveDomainResponse = passkeyUtils()->getEffectiveDomain(origin, &effectiveDomain);
if (effectiveDomainResponse > 0) {
if (effectiveDomainResponse > PASSKEYS_SUCCESS) {
return effectiveDomainResponse;
}

// Validate RP ID
QString rpId;
const auto rpIdResponse = passkeyUtils()->validateRpId(publicKeyOptions["rpId"], effectiveDomain, &rpId);
if (rpIdResponse > 0) {
if (rpIdResponse > PASSKEYS_SUCCESS) {
return rpIdResponse;
}

// Extensions
auto extensionObject = publicKeyOptions["extensions"].toObject();
const auto extensionData = passkeyUtils()->buildExtensionData(extensionObject);
const auto extensions = browserMessageBuilder()->getBase64FromArray(extensionData.extensionData);

// clientDataJson
const auto clientDataJson = passkeyUtils()->buildClientDataJson(publicKeyOptions, origin, true);
Expand All @@ -161,15 +169,20 @@ int BrowserPasskeysClient::getAssertionOptions(const QJsonObject& publicKeyOptio
}
const auto isUserVerificationRequired = passkeyUtils()->isUserVerificationRequired(publicKeyOptions);

// Checks for evalByCredential in PRF extension object
const auto checkEvalByCredential = passkeyUtils()->checkPrfEvalByCredential(publicKeyOptions, extensionObject);
if (checkEvalByCredential > PASSKEYS_SUCCESS) {
return checkEvalByCredential;
}

QJsonObject assertionOptions;
assertionOptions["allowCredentials"] = publicKeyOptions["allowCredentials"];
assertionOptions["clientDataJson"] = clientDataJson;
assertionOptions["clientExtensionResults"] = extensionData.extensionObject;
assertionOptions["extensions"] = extensions;
assertionOptions["extensionsObject"] = extensionObject;
assertionOptions["rpId"] = rpId;
assertionOptions["userPresence"] = true;
assertionOptions["userVerification"] = isUserVerificationRequired;

*result = assertionOptions;
return 0;
return PASSKEYS_SUCCESS;
}
28 changes: 22 additions & 6 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ QJsonObject BrowserService::showPasskeysRegisterPrompt(const QJsonObject& public
const auto username = credentialCreationOptions["user"].toObject()["name"].toString();
const auto user = credentialCreationOptions["user"].toObject();
const auto userId = user["id"].toString();
const auto prfSecret = credentialCreationOptions["prfSecret"].toString();

// Parse excludeCredentialDescriptorList
if (!excludeCredentials.isEmpty() && isPasskeyCredentialExcluded(excludeCredentials, rpId, keyList)) {
Expand Down Expand Up @@ -702,7 +703,8 @@ QJsonObject BrowserService::showPasskeysRegisterPrompt(const QJsonObject& public
username,
publicKeyCredentials.credentialId,
userId,
publicKeyCredentials.key);
publicKeyCredentials.key,
prfSecret);
}
} else {
// Handle new/existing group
Expand All @@ -718,7 +720,8 @@ QJsonObject BrowserService::showPasskeysRegisterPrompt(const QJsonObject& public
username,
publicKeyCredentials.credentialId,
userId,
publicKeyCredentials.key);
publicKeyCredentials.key,
prfSecret);
}

hideWindow();
Expand Down Expand Up @@ -781,13 +784,21 @@ QJsonObject BrowserService::showPasskeysAuthenticationPrompt(const QJsonObject&
? selectedEntry->attributes()->value(EntryAttributes::KPEX_PASSKEY_FLAG_BS) == "1"
|| selectedEntry->attributes()->value(EntryAttributes::KPEX_PASSKEY_FLAG_BS) == TRUE_STR
: DEFAULT_BS_FLAG;
const auto prfSecret = selectedEntry->attributes()->value(EntryAttributes::KPEX_PASSKEY_PRF);

// Handle PRF extension
QString newPrfSecret;
auto publicKeyCredential = browserPasskeys()->buildGetPublicKeyCredential(
assertionOptions, credentialId, userHandle, privateKeyPem, beFlag, bsFlag);
assertionOptions, credentialId, userHandle, privateKeyPem, prfSecret, &newPrfSecret, beFlag, bsFlag);
if (publicKeyCredential.isEmpty()) {
return getPasskeyError(ERROR_PASSKEYS_UNKNOWN_ERROR);
}

// If a new secret was generated, store it to the entry
if (!newPrfSecret.isEmpty()) {
selectedEntry->attributes()->set(EntryAttributes::KPEX_PASSKEY_PRF, newPrfSecret, true);
}

return publicKeyCredential;
}

Expand All @@ -803,7 +814,8 @@ void BrowserService::addPasskeyToGroup(const QSharedPointer<Database>& db,
const QString& username,
const QString& credentialId,
const QString& userHandle,
const QString& privateKey)
const QString& privateKey,
const QString& prfSecret)
{
// If no group provided, use the default browser group of the selected database
if (!group) {
Expand All @@ -821,7 +833,7 @@ void BrowserService::addPasskeyToGroup(const QSharedPointer<Database>& db,
entry->setUrl(url);
entry->setIcon(KEEPASSXCBROWSER_PASSKEY_ICON);

addPasskeyToEntry(entry, rpId, rpName, username, credentialId, userHandle, privateKey);
addPasskeyToEntry(entry, rpId, rpName, username, credentialId, userHandle, privateKey, prfSecret);

// Remove blank entry history
entry->removeHistoryItems(entry->historyItems());
Expand All @@ -833,7 +845,8 @@ void BrowserService::addPasskeyToEntry(Entry* entry,
const QString& username,
const QString& credentialId,
const QString& userHandle,
const QString& privateKey)
const QString& privateKey,
const QString& prfSecret)
{
// Reserved for future use
Q_UNUSED(rpName)
Expand Down Expand Up @@ -865,6 +878,9 @@ void BrowserService::addPasskeyToEntry(Entry* entry,
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_USER_HANDLE, userHandle, true);
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_FLAG_BE, "1");
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_FLAG_BS, "1");
if (!prfSecret.isEmpty()) {
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_PRF, prfSecret, true);
}
entry->addTag(tr("Passkey"));

entry->endUpdate();
Expand Down
8 changes: 5 additions & 3 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2025 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2017 Sami Vänttinen <sami.vanttinen@protonmail.com>
* Copyright (C) 2013 Francois Ferrand
*
Expand Down Expand Up @@ -103,14 +103,16 @@ class BrowserService : public QObject
const QString& username,
const QString& credentialId,
const QString& userHandle,
const QString& privateKey);
const QString& privateKey,
const QString& prfSecret);
void addPasskeyToEntry(Entry* entry,
const QString& rpId,
const QString& rpName,
const QString& username,
const QString& credentialId,
const QString& userHandle,
const QString& privateKey);
const QString& privateKey,
const QString& prfSecret);

void addEntry(const EntryParameters& entryParameters,
const QString& group,
Expand Down
Loading
Loading