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
|
<!DOCTYPE html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests crypto.subtle.generateKey.");
jsTestIsAsync = true;
extractable = true;
keyUsages = ['encrypt', 'decrypt'];
// Invalid keyUsages
aesCbc = { name: 'aes-cbc', length: 1024 };
shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, -1)");
shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, null)");
shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, ['boo'])");
// ---------------------------------------------------
// AES-CBC normalization failures (AesKeyGenParams)
// ---------------------------------------------------
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-cbc' }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-cbc', length: 70000 }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-cbc', length: -3 }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-cbc', length: -Infinity }, extractable, keyUsages)");
// ---------------------------------------------------
// AES-CTR normalization failures (AesKeyGenParams)
// ---------------------------------------------------
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-ctr' }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-ctr', length: 70000 }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-ctr', length: -3 }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-ctr', length: -Infinity }, extractable, keyUsages)");
// ---------------------------------------------------
// AES-KW normalization failures (AesKeyGenParams)
// ---------------------------------------------------
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-kw' }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-kw', length: 70000 }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-kw', length: -3 }, extractable, keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({ name: 'aes-kw', length: -Infinity }, extractable, keyUsages)");
// ---------------------------------------------------
// HMAC normalization failures (HmacKeyParams)
// ---------------------------------------------------
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: -3}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: ''}, length: 48}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: 5000000000}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: NaN}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: Infinity}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: -Infinity}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: crypto}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: undefined}, extractable , keyUsages)");
// The length property doesn't strictly need to be a number according to WebIDL.
// It just has to be convertable with ToNumber().
shouldAcceptPromise("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: '48'}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: null}, extractable , keyUsages)");
shouldAcceptPromise("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, length: true}, extractable , keyUsages)");
// ---------------------------------------------------
// RSASSA-PKCS1-v1_5 normalization failures (RsaKeyGenParams)
// ---------------------------------------------------
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength: -30}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength: NaN}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5'}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength: 10}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength: 10, publicExponent: 10}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength: 10, publicExponent: null}, extractable , keyUsages)");
// ---------------------------------------------------
// RSAES-PKCS1-v1_5 normalization failures (RsaKeyGenParams)
// ---------------------------------------------------
// Note: these are the same tests as for RSASSA-PKCS1-v1_5 above.
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength: -30}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength: NaN}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5'}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength: 10}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength: 10, publicExponent: 10}, extractable , keyUsages)");
shouldRejectPromiseWithNull("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength: 10, publicExponent: null}, extractable , keyUsages)");
completeTestWhenAllTasksDone();
</script>
</body>
</html>
|