Add support for group selection when creating a passkey

This commit is contained in:
Jonathan White 2024-10-07 17:45:34 -04:00
parent 518947e3aa
commit aeee40048c
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
3 changed files with 53 additions and 5 deletions

View File

@ -547,8 +547,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);

View File

@ -57,6 +57,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");
@ -227,7 +228,7 @@ QJsonObject BrowserService::getDatabaseGroups()
return result;
}
QJsonObject BrowserService::createNewGroup(const QString& groupName)
QJsonArray BrowserService::getDatabaseEntries()
{
auto db = getDatabase();
if (!db) {
@ -239,6 +240,39 @@ QJsonObject BrowserService::createNewGroup(const QString& groupName)
return {};
}
QJsonArray entries;
for (const auto& group : rootGroup->groupsRecursive(true)) {
if (group == db->metadata()->recycleBin()) {
continue;
}
for (const auto& entry : group->entries()) {
QJsonObject jentry;
jentry["title"] = entry->resolveMultiplePlaceholders(entry->title());
jentry["uuid"] = entry->resolveMultiplePlaceholders(entry->uuidToHex());
jentry["url"] = entry->resolveMultiplePlaceholders(entry->url());
entries.push_back(jentry);
}
}
return entries;
}
QJsonObject BrowserService::createNewGroup(const QString& groupName, bool isPasskeysGroup)
{
if (groupName.isEmpty()) {
return {};
}
auto db = getDatabase();
if (!db) {
return {};
}
Group* rootGroup = db->rootGroup();
if (!rootGroup) {
return {};
}
auto group = rootGroup->findGroupByPath(groupName);
// Group already exists
@ -278,10 +312,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;
@ -589,6 +628,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();
@ -660,8 +700,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,

View File

@ -79,7 +79,8 @@ public:
void lockDatabase();
QJsonObject getDatabaseGroups();
QJsonObject createNewGroup(const QString& groupName);
QJsonArray getDatabaseEntries();
QJsonObject createNewGroup(const QString& groupName, bool isPasskeysGroup = false);
QString getCurrentTotp(const QString& uuid);
void showPasswordGenerator(const KeyPairMessage& keyPairMessage);
bool isPasswordGeneratorRequested() const;
@ -89,6 +90,7 @@ public:
#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,