Skip to content

Commit 51aefb3

Browse files
committed
Bug 1573245 - Change AuthenticatorTransport to be string, not enum r=bzbarsky,keeler
Upstream: w3c/webauthn#1268 Differential Revision: https://phabricator.services.mozilla.com/D41620 --HG-- extra : moz-landing-system : lando
1 parent 94d12e1 commit 51aefb3

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

dom/webauthn/WebAuthnManager.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,19 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
532532
// Serialize transports.
533533
if (s.mTransports.WasPassed()) {
534534
uint8_t transports = 0;
535-
for (const auto& t : s.mTransports.Value()) {
535+
536+
// Transports is a string, but we match it to an enumeration so
537+
// that we have forward-compatibility, ignoring unknown transports.
538+
for (const nsAString& str : s.mTransports.Value()) {
539+
NS_ConvertUTF16toUTF8 cStr(str);
540+
int i = FindEnumStringIndexImpl(
541+
cStr.get(), cStr.Length(), AuthenticatorTransportValues::strings);
542+
if (i < 0 ||
543+
i >= static_cast<int>(AuthenticatorTransport::EndGuard_)) {
544+
continue; // Unknown enum
545+
}
546+
AuthenticatorTransport t = static_cast<AuthenticatorTransport>(i);
547+
536548
if (t == AuthenticatorTransport::Usb) {
537549
transports |= U2F_AUTHENTICATOR_TRANSPORT_USB;
538550
}

dom/webauthn/tests/test_webauthn_get_assertion.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ <h1>Tests for GetAssertion for W3C Web Authentication</h1>
132132
.catch(arrivingHereIsBad);
133133
});
134134

135+
// Test with an unexpected transport on a valid credential
136+
add_task(async () => {
137+
let cred = validCred;
138+
cred.transports = ["unknown", "usb"];
139+
140+
let publicKey = {
141+
challenge: gAssertionChallenge,
142+
unknownValue: "hi",
143+
allowCredentials: [cred]
144+
};
145+
146+
await requestGetAssertion({publicKey})
147+
.then(arrivingHereIsGood)
148+
.catch(arrivingHereIsBad);
149+
});
150+
135151
// Test with an invalid credential
136152
add_task(async () => {
137153
let publicKey = {

dom/webauthn/tests/test_webauthn_make_credential.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,26 @@ <h1>Test for MakeCredential for W3C Web Authentication</h1>
334334
return credm.create({publicKey: makeCredentialOptions})
335335
.then(arrivingHereIsBad)
336336
.catch(expectTypeError);
337+
},
338+
339+
// Test with excluding unknown transports
340+
function() {
341+
let completeRP = {id: document.domain, name: "Foxxy Name",
342+
icon: "https://example.com/fox.svg"};
343+
let completeUser = {id: string2buffer("foxes_are_the_best@example.com"),
344+
name: "Fox F. Foxington",
345+
icon: "https://example.com/fox.svg",
346+
displayName: "Foxxy V"};
347+
let excludedUnknownTransport = {type: "public-key",
348+
id: string2buffer("123"),
349+
transports: ["unknown", "usb"]};
350+
let makeCredentialOptions = {
351+
rp: completeRP, user: completeUser, challenge: gCredentialChallenge,
352+
pubKeyCredParams: [param], excludeCredentials: [excludedUnknownTransport]
353+
};
354+
return credm.create({publicKey: makeCredentialOptions})
355+
.then(arrivingHereIsGood)
356+
.catch(arrivingHereIsBad);
337357
}];
338358

339359
var i = 0;

dom/webidl/WebAuthentication.webidl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ enum PublicKeyCredentialType {
149149
dictionary PublicKeyCredentialDescriptor {
150150
required PublicKeyCredentialType type;
151151
required BufferSource id;
152-
sequence<AuthenticatorTransport> transports;
152+
// Transports is a string that is matched against the AuthenticatorTransport
153+
// enumeration so that we have forward-compatibility for new transports.
154+
sequence<DOMString> transports;
153155
};
154156

155157
enum AuthenticatorTransport {

0 commit comments

Comments
 (0)