1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
<!DOCTYPE html>
<meta charset=utf-8>
<head>
<title>W3C Web Authentication - Authenticator Transports</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="u2futil.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<h1>W3C Web Authentication - Authenticator Transports</h1>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1406467">Mozilla Bug 1406467</a>
<script class="testbody" type="text/javascript">
"use strict";
add_task(async () => {
await addVirtualAuthenticator();
});
function arrivingHereIsGood(aResult) {
ok(true, "Good result! Received a: " + aResult);
}
function arrivingHereIsBad(aResult) {
ok(false, "Bad result! Received a: " + aResult);
}
function expectNotAllowedError(aResult) {
ok(aResult.toString().startsWith("NotAllowedError"), "Expecting a NotAllowedError, got " + aResult);
}
function expectInvalidStateError(aResult) {
ok(aResult.toString().startsWith("InvalidStateError"), "Expecting a InvalidStateError, got " + aResult);
}
// Store the credential and transports of the first successful make credential
// operation so we can use them to get assertions later.
let gCredential;
let gTransports;
// Start a new MakeCredential() request.
function requestMakeCredential(excludeCredentials) {
let publicKey = {
rp: {id: document.domain, name: "none"},
user: {id: new Uint8Array(), name: "none", displayName: "none"},
challenge: crypto.getRandomValues(new Uint8Array(16)),
timeout: 5000, // the minimum timeout is actually 15 seconds
pubKeyCredParams: [{type: "public-key", alg: cose_alg_ECDSA_w_SHA256}],
excludeCredentials
};
return navigator.credentials.create({publicKey});
}
// Start a new GetAssertion() request.
function requestGetAssertion(allowCredentials) {
let publicKey = {
challenge: crypto.getRandomValues(new Uint8Array(16)),
timeout: 5000, // the minimum timeout is actually 15 seconds
rpId: document.domain,
allowCredentials
};
return navigator.credentials.get({publicKey});
}
// Test make credential behavior.
add_task(async function test_make_credential() {
// Make a credential.
await requestMakeCredential([])
// Save the credential for later.
.then(res => {
gCredential = res.rawId;
gTransports = res.response.getTransports();
})
.then(arrivingHereIsGood)
.catch(arrivingHereIsBad);
// gTransports should be "a sequence of zero or more unique DOMStrings in lexicographical order."
for (let i = 0; i < gTransports.length - 1; i++) {
if (gTransports[i] >= gTransports[i+1]) {
ok(false, "getTransports() should return a sorted list");
}
}
// Pass a random credential to exclude.
await requestMakeCredential([{
type: "public-key",
id: crypto.getRandomValues(new Uint8Array(16)),
transports: gTransports,
}]).then(arrivingHereIsGood)
.catch(arrivingHereIsBad);
// Pass gCredential with transport=usb.
// The credential already exists, and the softoken consents to create,
// so the error is InvalidState and not NotAllowed.
await requestMakeCredential([{
type: "public-key",
id: gCredential,
transports: ["usb"],
}]).then(arrivingHereIsBad)
.catch(expectInvalidStateError);
// Pass gCredential with transport=nfc.
// The softoken pretends to support all transports.
// Also, as above, the credential exists and the token indicates consent.
await requestMakeCredential([{
type: "public-key",
id: gCredential,
transports: ["nfc"],
}]).then(arrivingHereIsBad)
.catch(expectInvalidStateError);
// Pass gCredential with an empty transports list.
// As above, the token indicates consent, so expect InvalidStateError.
await requestMakeCredential([{
type: "public-key",
id: gCredential,
transports: [],
}]).then(arrivingHereIsBad)
.catch(expectInvalidStateError);
});
// Test get assertion behavior.
add_task(async function test_get_assertion() {
// Request an assertion for gCredential.
await requestGetAssertion([{
type: "public-key",
id: gCredential,
transports: gTransports,
}]).then(arrivingHereIsGood)
.catch(arrivingHereIsBad);
// Request an assertion for a random credential. This should be
// indistinguishable from the user denying consent for a known
// credential, so expect a NotAllowedError.
await requestGetAssertion([{
type: "public-key",
id: crypto.getRandomValues(new Uint8Array(16)),
transports: ["usb"],
}]).then(arrivingHereIsBad)
.catch(expectNotAllowedError);
// Request an assertion for gCredential with transport=nfc.
// The softoken pretends to support all transports.
await requestGetAssertion([{
type: "public-key",
id: gCredential,
transports: ["nfc"],
}]).then(arrivingHereIsGood)
.catch(arrivingHereIsBad);
// Request an assertion for gCredential with an empty transports list.
await requestGetAssertion([{
type: "public-key",
id: gCredential,
transports: [],
}]).then(arrivingHereIsGood)
.catch(arrivingHereIsBad);
});
</script>
</body>
</html>
|