Skip to content

Commit 8dc50ed

Browse files
committed
Start implementing passkeys-register request
1 parent 7c271c9 commit 8dc50ed

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/main/java/org/keepassxc/Connection.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,28 @@ public JSONObject requestAutotype(String url) throws IOException, KeepassProxyAc
655655

656656
}
657657

658+
public JSONObject passkeysRegister(String publicKey, String origin, List<Map<String, String>> list) throws IOException, KeepassProxyAccessException {
659+
var array = new JSONArray();
660+
// Syntax check for list
661+
for (Map<String, String> m : list) {
662+
var o = new JSONObject(m);
663+
if (!(o.has("id") && o.has("key") && o.length() == 2)) {
664+
throw new KeepassProxyAccessException("JSON object key is malformed");
665+
}
666+
array.put(m);
667+
}
668+
669+
// Send passkeys-register request
670+
var nonce = sendEncryptedMessage(Map.of(
671+
"action", "passkeys-register",
672+
"publicKey", ensureNotNull(publicKey),
673+
"origin", ensureNotNull(origin),
674+
"keys", array
675+
));
676+
return getEncryptedResponseAndDecrypt("passkeys-register", nonce);
677+
678+
}
679+
658680
/**
659681
* Get a String representation of the JSON object.
660682
*

src/main/java/org/purejava/KeepassProxyAccess.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,26 @@ public boolean requestAutotype(String url) {
424424
}
425425
}
426426

427+
public String passkeysRegister(String publicKey, String origin, List<Map<String, String>> list) {
428+
try {
429+
var response = connection.passkeysRegister(publicKey, origin, list);
430+
if (response.has("response") && response.has("success") && response.getString("success").equals("true")) {
431+
try {
432+
var errorCode = response.getJSONObject("response").getString("errorCode");
433+
throw new KeepassProxyAccessException("ErrorCode: " + errorCode);
434+
435+
} catch (JSONException e) {
436+
return response.getString("response"); // PublicKeyCredential
437+
}
438+
} else {
439+
return "";
440+
}
441+
} catch (IOException | KeepassProxyAccessException e) {
442+
LOG.info(e.toString(), e.getCause());
443+
}
444+
return "";
445+
}
446+
427447
/**
428448
* Extract the groupUuid for the newly created group.
429449
* Note: in case a group with the following path was created: level1/level2, only level2 gets returned as name.

src/test/java/org/purejava/UnlockedDatabaseTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void shouldHaveNoErrors() throws InterruptedException {
5050
assertTrue(kpa.requestAutotype("https://github.com"));
5151
LOG.info("Please allow to delete entry");
5252
assertTrue(kpa.deleteEntry("2aafee1a89fd435c8bad7df12bbaaa3e"));
53+
LOG.info(kpa.passkeysRegister("publicKey", "https://www.passkeys.io", l));
5354
LOG.info("Please deny to save changes");
5455
assertTrue(kpa.lockDatabase());
5556
assertTrue(kpa.shutdown());

0 commit comments

Comments
 (0)