-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support passkeys with Bitwarden import (#11401)
- Loading branch information
1 parent
95bae83
commit 6e0baf9
Showing
14 changed files
with
180 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2023 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2024 KeePassXC Team <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -81,6 +81,43 @@ namespace | |
entry->setTotp(Totp::parseSettings(totp)); | ||
} | ||
|
||
// Parse passkey | ||
if (loginMap.contains("fido2Credentials")) { | ||
const auto fido2CredentialsMap = loginMap.value("fido2Credentials").toList(); | ||
for (const auto& fido2Credentials : fido2CredentialsMap) { | ||
const auto passkey = fido2Credentials.toMap(); | ||
|
||
// Change from UUID to base64 byte array | ||
const auto credentialIdValue = passkey.value("credentialId").toString(); | ||
if (!credentialIdValue.isEmpty()) { | ||
const auto credentialUuid = Tools::uuidToHex(credentialIdValue); | ||
const auto credentialIdArray = QByteArray::fromHex(credentialUuid.toUtf8()); | ||
const auto credentialId = | ||
credentialIdArray.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); | ||
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_CREDENTIAL_ID, credentialId, true); | ||
} | ||
|
||
// Base64 needs to be changed from URL encoding back to normal, and the result as PEM string | ||
const auto keyValue = passkey.value("keyValue").toString(); | ||
if (!keyValue.isEmpty()) { | ||
const auto keyValueArray = | ||
QByteArray::fromBase64(keyValue.toUtf8(), QByteArray::Base64UrlEncoding); | ||
auto privateKey = keyValueArray.toBase64(QByteArray::Base64Encoding); | ||
privateKey.insert(0, EntryAttributes::KPEX_PASSKEY_PRIVATE_KEY_START.toUtf8()); | ||
privateKey.append(EntryAttributes::KPEX_PASSKEY_PRIVATE_KEY_END.toUtf8()); | ||
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_PRIVATE_KEY_PEM, privateKey, true); | ||
} | ||
|
||
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_USERNAME, | ||
passkey.value("userName").toString()); | ||
entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_RELYING_PARTY, | ||
passkey.value("rpId").toString()); | ||
entry->attributes()->set( | ||
EntryAttributes::KPEX_PASSKEY_USER_HANDLE, passkey.value("userHandle").toString(), true); | ||
entry->addTag(QObject::tr("Passkey")); | ||
} | ||
} | ||
|
||
// Set the entry url(s) | ||
int i = 1; | ||
for (const auto& urlObj : loginMap.value("uris").toList()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2022 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2024 KeePassXC Team <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -282,3 +282,36 @@ void TestImports::testBitwardenEncrypted() | |
} | ||
QVERIFY(db); | ||
} | ||
|
||
void TestImports::testBitwardenPasskey() | ||
{ | ||
auto bitwardenPath = | ||
QStringLiteral("%1/%2").arg(KEEPASSX_TEST_DATA_DIR, QStringLiteral("/bitwarden_passkey_export.json")); | ||
|
||
BitwardenReader reader; | ||
auto db = reader.convert(bitwardenPath); | ||
QVERIFY2(!reader.hasError(), qPrintable(reader.errorString())); | ||
QVERIFY(db); | ||
|
||
// Confirm Login fields | ||
auto entry = db->rootGroup()->findEntryByPath("/webauthn.io"); | ||
QVERIFY(entry); | ||
QCOMPARE(entry->title(), QStringLiteral("webauthn.io")); | ||
QCOMPARE(entry->username(), QStringLiteral("KPXC_BITWARDEN")); | ||
QCOMPARE(entry->url(), QStringLiteral("https://webauthn.io/")); | ||
|
||
// Confirm passkey attributes | ||
auto attr = entry->attributes(); | ||
QCOMPARE(attr->value(EntryAttributes::KPEX_PASSKEY_CREDENTIAL_ID), QStringLiteral("o-FfiyfBQq6Qz6YVrYeFTw")); | ||
QCOMPARE( | ||
attr->value(EntryAttributes::KPEX_PASSKEY_PRIVATE_KEY_PEM), | ||
QStringLiteral( | ||
"-----BEGIN PRIVATE " | ||
"KEY-----" | ||
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgmr4GQQjerojFuf0ZouOuUllMvAwxZSZAfB6gwDYcLiehRANCAAT0WR5zVS" | ||
"p6ieusvjkLkzaGc7fjGBmwpiuLPxR/d+ZjqMI9L2DKh+takp6wGt2x0n4jzr1KA352NZg0vjZX9CHh-----END PRIVATE KEY-----")); | ||
QCOMPARE(attr->value(EntryAttributes::KPEX_PASSKEY_USERNAME), QStringLiteral("KPXC_BITWARDEN")); | ||
QCOMPARE(attr->value(EntryAttributes::KPEX_PASSKEY_RELYING_PARTY), QStringLiteral("webauthn.io")); | ||
QCOMPARE(attr->value(EntryAttributes::KPEX_PASSKEY_USER_HANDLE), | ||
QStringLiteral("aTFtdmFnOHYtS2dxVEJ0by1rSFpLWGg0enlTVC1iUVJReDZ5czJXa3c2aw")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2022 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2024 KeePassXC Team <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -30,6 +30,7 @@ private slots: | |
void testOPVault(); | ||
void testBitwarden(); | ||
void testBitwardenEncrypted(); | ||
void testBitwardenPasskey(); | ||
}; | ||
|
||
#endif /* TEST_IMPORTS_H */ |
Oops, something went wrong.