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
|
<!DOCTYPE html>
<meta charset=utf-8>
<head>
<script type="text/javascript" src="frame_utils.js"></script>
<script type="text/javascript" src="u2futil.js"></script>
</head>
<body>
<p>AppID / Facet checks</p>
<script class="testbody" type="text/javascript">
"use strict";
async function doTests() {
let version = "U2F_V2";
let challenge = new Uint8Array(16);
window.crypto.getRandomValues(challenge);
local_is(window.location.origin, "https://example.com", "Is loaded correctly");
// Ensure the SpecialPowers push worked properly
local_isnot(window.u2f, undefined, "U2F API endpoint must exist");
await promiseU2FRegister(null, [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 0, "Null AppID should work.");
});
await promiseU2FRegister("", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 0, "Empty AppID should work.");
});
// Test: Correct TLD, but incorrect scheme
await promiseU2FRegister("http://example.com/appId", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_isnot(res.errorCode, 0, "HTTP scheme is disallowed");
});
// Test: Correct TLD, and also HTTPS
await promiseU2FRegister("https://example.com/appId", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 0, "HTTPS origin for example.com should work");
});
// Test: Sub-domain
await promiseU2FRegister("https://test2.example.com/appId", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 0, "HTTPS origin for test2.example.com should work");
});
// Test: Sub-sub-domain
await promiseU2FRegister("https://sub.test2.example.com/appId", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 0, "HTTPS origin for sub.test2.example.com should work");
});
// Test: TLD
await promiseU2FRegister("https://com/weirdAppID", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 2, "HTTPS origin of the TLD should not work");
});
// Test: Dynamic origin
await promiseU2FRegister(window.location.origin + "/otherAppId", [{
version,
challenge: bytesToBase64UrlSafe(challenge),
}], [], function(res){
local_is(res.errorCode, 0, "Direct window origin should work");
});
local_finished();
};
doTests();
</script>
</body>
</html>
|