Skip to content

Commit

Permalink
Bug 1862132 - Part 3. Modifify GeckoBundle structure to fit with Cred…
Browse files Browse the repository at this point in the history
…ential Manager API. r=jschanck,geckoview-reviewers,owlish

Credential Manager API requires that request parameter is JSON. So I
would like to modify GeckoBundle structure for upcoming new API
support.

Differential Revision: https://phabricator.services.mozilla.com/D207502
  • Loading branch information
makotokato committed May 16, 2024
1 parent 13dbc20 commit 665bcee
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
62 changes: 37 additions & 25 deletions dom/webauthn/AndroidWebAuthnService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,50 @@ AndroidWebAuthnService::MakeCredential(uint64_t aTransactionId,
GECKOBUNDLE_PUT(credentialBundle, "isWebAuthn",
java::sdk::Integer::ValueOf(1));

nsString rpId;
Unused << aArgs->GetRpId(rpId);
GECKOBUNDLE_PUT(credentialBundle, "rpId", jni::StringParam(rpId));
{
GECKOBUNDLE_START(rpBundle);

nsString rpId;
Unused << aArgs->GetRpId(rpId);
GECKOBUNDLE_PUT(rpBundle, "id", jni::StringParam(rpId));

nsString rpName;
Unused << aArgs->GetRpName(rpName);
GECKOBUNDLE_PUT(rpBundle, "name", jni::StringParam(rpName));

GECKOBUNDLE_FINISH(rpBundle);
GECKOBUNDLE_PUT(credentialBundle, "rp", rpBundle);
}

{
GECKOBUNDLE_START(userBundle);

nsString rpName;
Unused << aArgs->GetRpName(rpName);
GECKOBUNDLE_PUT(credentialBundle, "rpName", jni::StringParam(rpName));
nsString userName;
Unused << aArgs->GetUserName(userName);
GECKOBUNDLE_PUT(userBundle, "name", jni::StringParam(userName));

nsString userName;
Unused << aArgs->GetUserName(userName);
GECKOBUNDLE_PUT(credentialBundle, "userName",
jni::StringParam(userName));
nsString userDisplayName;
Unused << aArgs->GetUserDisplayName(userDisplayName);
GECKOBUNDLE_PUT(userBundle, "displayName",
jni::StringParam(userDisplayName));

nsString userDisplayName;
Unused << aArgs->GetUserDisplayName(userDisplayName);
GECKOBUNDLE_PUT(credentialBundle, "userDisplayName",
jni::StringParam(userDisplayName));
GECKOBUNDLE_FINISH(userBundle);
GECKOBUNDLE_PUT(credentialBundle, "user", userBundle);
}

nsString origin;
Unused << aArgs->GetOrigin(origin);
GECKOBUNDLE_PUT(credentialBundle, "origin", jni::StringParam(origin));

uint32_t timeout;
Unused << aArgs->GetTimeoutMS(&timeout);
GECKOBUNDLE_PUT(credentialBundle, "timeoutMS",
GECKOBUNDLE_PUT(credentialBundle, "timeout",
java::sdk::Double::New(timeout));

// Add UI support to consent to attestation, bug 1550164
GECKOBUNDLE_PUT(credentialBundle, "attestation",
jni::StringParam(u"none"_ns));

GECKOBUNDLE_FINISH(credentialBundle);

nsTArray<uint8_t> userId;
Expand Down Expand Up @@ -117,9 +135,6 @@ AndroidWebAuthnService::MakeCredential(uint64_t aTransactionId,
transportBuf.Length());

GECKOBUNDLE_START(authSelBundle);
// Add UI support to consent to attestation, bug 1550164
GECKOBUNDLE_PUT(authSelBundle, "attestationPreference",
jni::StringParam(u"none"_ns));

nsString residentKey;
Unused << aArgs->GetResidentKey(residentKey);
Expand Down Expand Up @@ -159,14 +174,11 @@ AndroidWebAuthnService::MakeCredential(uint64_t aTransactionId,
return;
}
if (authenticatorAttachment.EqualsLiteral(
MOZ_WEBAUTHN_AUTHENTICATOR_ATTACHMENT_PLATFORM)) {
GECKOBUNDLE_PUT(authSelBundle, "requirePlatformAttachment",
java::sdk::Integer::ValueOf(1));
} else if (
MOZ_WEBAUTHN_AUTHENTICATOR_ATTACHMENT_PLATFORM) ||
authenticatorAttachment.EqualsLiteral(
MOZ_WEBAUTHN_AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM)) {
GECKOBUNDLE_PUT(authSelBundle, "requireCrossPlatformAttachment",
java::sdk::Integer::ValueOf(1));
GECKOBUNDLE_PUT(authSelBundle, "authenticatorAttachment",
jni::StringParam(authenticatorAttachment));
}
}
GECKOBUNDLE_FINISH(authSelBundle);
Expand Down Expand Up @@ -262,7 +274,7 @@ AndroidWebAuthnService::GetAssertion(uint64_t aTransactionId,

uint32_t timeout;
Unused << aArgs->GetTimeoutMS(&timeout);
GECKOBUNDLE_PUT(assertionBundle, "timeoutMS",
GECKOBUNDLE_PUT(assertionBundle, "timeout",
java::sdk::Double::New(timeout));

// User Verification Requirement is not currently used in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ private static PublicKeyCredentialCreationOptions getRequestOptionsForMakeCreden
PublicKeyCredentialType.PUBLIC_KEY.toString(), algo.getAlgoValue()));
}

final GeckoBundle userBundle = credentialBundle.getBundle("user");
final PublicKeyCredentialUserEntity user =
new PublicKeyCredentialUserEntity(
userId,
credentialBundle.getString("userName", ""),
userBundle.getString("name", ""),
/* deprecated userIcon field */ "",
credentialBundle.getString("userDisplayName", ""));
userBundle.getString("displayName", ""));

AttestationConveyancePreference pref = AttestationConveyancePreference.NONE;
final String attestationPreference =
authenticatorSelection.getString("attestationPreference", "NONE");
final String attestationPreference = credentialBundle.getString("attestation", "NONE");
if (attestationPreference.equalsIgnoreCase(AttestationConveyancePreference.DIRECT.name())) {
pref = AttestationConveyancePreference.DIRECT;
} else if (attestationPreference.equalsIgnoreCase(
Expand All @@ -105,10 +105,11 @@ private static PublicKeyCredentialCreationOptions getRequestOptionsForMakeCreden

final AuthenticatorSelectionCriteria.Builder selBuild =
new AuthenticatorSelectionCriteria.Builder();
if (authenticatorSelection.getInt("requirePlatformAttachment", 0) == 1) {
final String authenticatorAttachment =
authenticatorSelection.getString("authenticatorAttachment", "");
if (authenticatorAttachment.equals("platform")) {
selBuild.setAttachment(Attachment.PLATFORM);
}
if (authenticatorSelection.getInt("requireCrossPlatformAttachment", 0) == 1) {
} else if (authenticatorAttachment.equals("cross-platform")) {
selBuild.setAttachment(Attachment.CROSS_PLATFORM);
}
final String residentKey = authenticatorSelection.getString("residentKey", "");
Expand Down Expand Up @@ -145,10 +146,11 @@ private static PublicKeyCredentialCreationOptions getRequestOptionsForMakeCreden
WebAuthnUtils.getTransportsForByte(cred.transports)));
}

final GeckoBundle rpBundle = credentialBundle.getBundle("rp");
final PublicKeyCredentialRpEntity rp =
new PublicKeyCredentialRpEntity(
credentialBundle.getString("rpId"),
credentialBundle.getString("rpName", ""),
rpBundle.getString("id"),
rpBundle.getString("name", ""),
/* deprecated rpIcon field */ "");

return requestBuilder
Expand All @@ -159,7 +161,7 @@ private static PublicKeyCredentialCreationOptions getRequestOptionsForMakeCreden
.setChallenge(challenge)
.setRp(rp)
.setParameters(params)
.setTimeoutSeconds(credentialBundle.getLong("timeoutMS") / 1000.0)
.setTimeoutSeconds(credentialBundle.getLong("timeout") / 1000.0)
.setExcludeList(excludedList)
.build();
}
Expand Down Expand Up @@ -354,7 +356,7 @@ private static PublicKeyCredentialRequestOptions getRequestOptionsForGetAssertio
return new PublicKeyCredentialRequestOptions.Builder()
.setChallenge(challenge)
.setAllowList(allowedList)
.setTimeoutSeconds(assertionBundle.getLong("timeoutMS") / 1000.0)
.setTimeoutSeconds(assertionBundle.getLong("timeout") / 1000.0)
.setRpId(assertionBundle.getString("rpId"))
.setAuthenticationExtensions(ext)
.build();
Expand Down

0 comments on commit 665bcee

Please sign in to comment.