Skip to content

Commit 97b34ff

Browse files
p1gp1gmakotokato
authored andcommitted
Bug 1964526 - Fido2 Always try Credential Manager to create key, and fallback to GMS r=geckoview-reviewers,jschanck,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D247877
1 parent dcb46a3 commit 97b34ff

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

mobile/android/geckoview/src/main/java/org/mozilla/gecko/WebAuthnCredentialManager.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,11 @@ public static GeckoResult<WebAuthnUtils.MakeCredentialResponse> makeCredential(
136136
final WebAuthnUtils.WebAuthnPublicCredential[] excludeList,
137137
final GeckoBundle authenticatorSelection,
138138
final byte[] clientDataHash) {
139-
final Boolean requireResidentKey =
140-
authenticatorSelection.getBoolean("requireResidentKey", false);
141139

142-
final Boolean residentKeyDiscouraged =
143-
authenticatorSelection
144-
.getString("residentKey", requireResidentKey ? "required" : "discouraged")
145-
.equals("discouraged");
146-
147-
// We only use Credential Manager for Passkeys. If residentKey is discouraged, use GMS FIDO2.
148-
if (residentKeyDiscouraged) {
149-
return GeckoResult.fromException(new WebAuthnUtils.Exception("NOT_SUPPORTED_ERR"));
150-
}
140+
// We use Credential Manager first. If it doesn't work, we use GMS FIDO2.
141+
// Credential manager may support non-discoverable keys,
142+
// Else, following the specifications, `residentKey=discouraged` allows discoverable keys too
143+
// but prefer non-discoverable keys
151144
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
152145
return GeckoResult.fromException(new WebAuthnUtils.Exception("NOT_SUPPORTED_ERR"));
153146
}

mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/WebAuthnUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,17 @@ public static JSONObject getJSONObjectForMakeCredential(
362362
json.put("excludeCredentials", excludeCredentials);
363363

364364
final JSONObject authenticatorSelectionJSON = authenticatorSelection.toJSONObject();
365-
authenticatorSelectionJSON.put("requireResidentKey", true);
365+
/*
366+
dom/webauthn/WebAuthnHandler.cpp: WebAuthnHandler::MakeCredential set `residentKey`
367+
to "required" if there is no `residentKey` and `requireResidentKey` is true, and
368+
`requireResidentKey` should be true if `residentKey` is "required". So we can retrieve
369+
`requireResidentKey`'s value from `residentKey`.
370+
`requireResidentKey` is only used if `residentKey` isn't set, so it shouldn't be used by any
371+
authenticator that follows the specs.
372+
*/
373+
authenticatorSelectionJSON.put(
374+
"requireResidentKey",
375+
authenticatorSelection.getString("residentKey", "").equals("required"));
366376
json.put("authenticatorSelection", authenticatorSelectionJSON);
367377

368378
final JSONObject extensions = new JSONObject();

0 commit comments

Comments
 (0)