Skip to content

Commit

Permalink
Add support for group selection when creating a passkey
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Sep 14, 2024
1 parent c1a66a8 commit ee75920
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,9 @@ QJsonObject BrowserAction::handlePasskeysRegister(const QJsonObject& json, const
return getErrorReply(action, ERROR_PASSKEYS_INVALID_URL_PROVIDED);
}

const auto groupName = browserRequest.getString("groupName");
const auto keyList = getConnectionKeys(browserRequest);
const auto response = browserService()->showPasskeysRegisterPrompt(publicKey, origin, keyList);
const auto response = browserService()->showPasskeysRegisterPrompt(publicKey, origin, groupName, keyList);

const Parameters params{{"response", response}};
return buildResponse(action, browserRequest.incrementedNonce, params);
Expand Down
22 changes: 19 additions & 3 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static const QString KEEPASSXCBROWSER_GROUP_NAME = QStringLiteral("KeePassXC-Bro
static int KEEPASSXCBROWSER_DEFAULT_ICON = 1;
#ifdef WITH_XC_BROWSER_PASSKEYS
static int KEEPASSXCBROWSER_PASSKEY_ICON = 13;
static const QString PASSKEYS_DEFAULT_GROUP_NAME = QStringLiteral("KeePassXC-Browser Passkeys");
#endif
// These are for the settings and password conversion
static const QString KEEPASSHTTP_NAME = QStringLiteral("KeePassHttp Settings");
Expand Down Expand Up @@ -258,8 +259,12 @@ QJsonArray BrowserService::getDatabaseEntries()
return entries;
}

QJsonObject BrowserService::createNewGroup(const QString& groupName)
QJsonObject BrowserService::createNewGroup(const QString& groupName, bool isPasskeysGroup)
{
if (groupName.isEmpty()) {
return {};
}

auto db = getDatabase();
if (!db) {
return {};
Expand Down Expand Up @@ -309,10 +314,15 @@ QJsonObject BrowserService::createNewGroup(const QString& groupName)
QString gName = getGroupName(i);
auto tempGroup = rootGroup->findGroupByPath(gName);
if (!tempGroup) {
Group* newGroup = new Group();
auto newGroup = new Group();
newGroup->setName(groups[i]);
newGroup->setUuid(QUuid::createUuid());
newGroup->setParent(previousGroup);
#ifdef WITH_XC_BROWSER_PASSKEYS
if (isPasskeysGroup && i == groups.length() - 1) {
newGroup->setIcon(KEEPASSXCBROWSER_PASSKEY_ICON);
}
#endif
name = newGroup->name();
uuid = Tools::uuidToHex(newGroup->uuid());
previousGroup = newGroup;
Expand Down Expand Up @@ -620,6 +630,7 @@ QString BrowserService::getKey(const QString& id)
// Passkey registration
QJsonObject BrowserService::showPasskeysRegisterPrompt(const QJsonObject& publicKeyOptions,
const QString& origin,
const QString& groupName,
const StringPairList& keyList)
{
auto db = selectedDatabase();
Expand Down Expand Up @@ -691,8 +702,13 @@ QJsonObject BrowserService::showPasskeysRegisterPrompt(const QJsonObject& public
publicKeyCredentials.key);
}
} else {
// Handle new/existing group
const auto createResponse =
createNewGroup(groupName.isEmpty() ? PASSKEYS_DEFAULT_GROUP_NAME : groupName, true);
const auto group = db->rootGroup()->findGroupByUuid(Tools::hexToUuid(createResponse["uuid"].toString()));

addPasskeyToGroup(db,
nullptr,
group,
origin,
rpId,
rpName,
Expand Down
3 changes: 2 additions & 1 deletion src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BrowserService : public QObject

QJsonObject getDatabaseGroups();
QJsonArray getDatabaseEntries();
QJsonObject createNewGroup(const QString& groupName);
QJsonObject createNewGroup(const QString& groupName, bool isPasskeysGroup = false);
QString getCurrentTotp(const QString& uuid);
void showPasswordGenerator(const KeyPairMessage& keyPairMessage);
bool isPasswordGeneratorRequested() const;
Expand All @@ -90,6 +90,7 @@ class BrowserService : public QObject
#ifdef WITH_XC_BROWSER_PASSKEYS
QJsonObject showPasskeysRegisterPrompt(const QJsonObject& publicKeyOptions,
const QString& origin,
const QString& groupName,
const StringPairList& keyList);
QJsonObject showPasskeysAuthenticationPrompt(const QJsonObject& publicKeyOptions,
const QString& origin,
Expand Down

0 comments on commit ee75920

Please sign in to comment.