OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../fast/js/resources/js-test-pre.js"></script> | 4 <script src="../fast/js/resources/js-test-pre.js"></script> |
| 5 <script src="resources/common.js"></script> |
5 </head> | 6 </head> |
6 <body> | 7 <body> |
7 <p id="description"></p> | 8 <p id="description"></p> |
8 <div id="console"></div> | 9 <div id="console"></div> |
9 | 10 |
10 <script> | 11 <script> |
11 description("Tests cypto.subtle.generateKey."); | 12 description("Tests cypto.subtle.generateKey."); |
12 | 13 |
13 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
14 | 15 |
15 // Note that fractional numbers are truncated, so this length should be | |
16 // interpreted as 1024. | |
17 aesCbc = { name: 'aes-cbc', length: 1024.9 }; | |
18 extractable = true; | 16 extractable = true; |
19 keyUsages = ['encrypt', 'decrypt']; | 17 keyUsages = ['encrypt', 'decrypt']; |
20 | 18 |
21 // length property is missing. | 19 // Invalid keyUsages |
22 invalidAesKeyGen = { name: 'aes-cbc' }; | 20 aesCbc = { name: 'aes-cbc', length: 1024 }; |
23 shouldThrow("crypto.subtle.generateKey(invalidAesKeyGen, extractable, keyUsages)
"); | 21 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, -1)"); |
| 22 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, null)"); |
| 23 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, ['boo'])"); |
24 | 24 |
25 // length is invalid (outside of range of "unsigned short") | 25 // --------------------------------------------------- |
26 invalidAesKeyGen = { name: 'aes-cbc', length: 70000 }; | 26 // AES-CBC normalization failures (AesKeyGenParams) |
27 shouldThrow("crypto.subtle.generateKey(invalidAesKeyGen, extractable, keyUsages)
"); | 27 // --------------------------------------------------- |
28 | 28 |
29 // length is invalid (outside of range of "unsigned short") | 29 shouldThrow("crypto.subtle.generateKey({ name: 'aes-cbc' }, extractable, keyUsag
es)"); |
30 invalidAesKeyGen = { name: 'aes-cbc', length: -3 }; | 30 shouldThrow("crypto.subtle.generateKey({ name: 'aes-cbc', length: 70000 }, extra
ctable, keyUsages)"); |
31 shouldThrow("crypto.subtle.generateKey(invalidAesKeyGen, extractable, keyUsages)
"); | 31 shouldThrow("crypto.subtle.generateKey({ name: 'aes-cbc', length: -3 }, extracta
ble, keyUsages)"); |
| 32 shouldThrow("crypto.subtle.generateKey({ name: 'aes-cbc', length: -Infinity }, e
xtractable, keyUsages)"); |
32 | 33 |
33 // keyUsages is invalid. | 34 // --------------------------------------------------- |
34 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, -1)"); | 35 // HMAC normalization failures (HmacKeyParams) |
| 36 // --------------------------------------------------- |
35 | 37 |
36 // Invalid length | 38 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, l
ength: -3}, extractable , keyUsages)"); |
37 invalidHmac256 = { name: 'hmac', hash: {name: 'sha-256' }, length:-3 }; | 39 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: ''}, length:
48}, extractable , keyUsages)"); |
38 shouldThrow("crypto.subtle.generateKey(invalidHmac256, false, ['sign'])"); | 40 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, l
ength: 5000000000}, extractable , keyUsages)"); |
| 41 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, l
ength: NaN}, extractable , keyUsages)"); |
| 42 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, l
ength: -NaN}, extractable , keyUsages)"); |
| 43 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, l
ength: Infinity}, extractable , keyUsages)"); |
| 44 shouldThrow("crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, l
ength: -Infinity}, extractable , keyUsages)"); |
39 | 45 |
40 hmacSha256 = { name: 'hmac', hash: {name: 'sha-256' } }; | 46 // --------------------------------------------------- |
41 hmacSha256b = { name: 'hmac', hash: {name: 'sha-256' }, length:48 }; | 47 // RSASSA-PKCS1-v1_5 normalization failures (RsaKeyGenParams) |
| 48 // --------------------------------------------------- |
42 | 49 |
43 var promise0 = crypto.subtle.generateKey(aesCbc, extractable, keyUsages); | 50 shouldThrow("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength
: -30}, extractable , keyUsages)"); |
44 var promise1 = crypto.subtle.generateKey(hmacSha256, false, ['sign']); | 51 shouldThrow("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength
: NaN}, extractable , keyUsages)"); |
45 var promise2 = crypto.subtle.generateKey(hmacSha256b, false, ['sign']); | 52 shouldThrow("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5'}, extractable
, keyUsages)"); |
| 53 shouldThrow("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength
: 10}, extractable , keyUsages)"); |
| 54 shouldThrow("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength
: 10, publicExponent: 10}, extractable , keyUsages)"); |
| 55 shouldThrow("crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength
: 10, publicExponent: null}, extractable , keyUsages)"); |
46 | 56 |
47 Promise.every(promise0, promise1, promise2).then(function(results) | 57 // Note that fractional numbers are truncated, so this length should be |
48 { | 58 // interpreted as 1024. |
49 key = results[0]; | 59 crypto.subtle.generateKey({name: 'aes-cbc', length: 1024.9}, extractable, ['decr
ypt', 'encrypt']).then(function(result) { |
| 60 key = result; |
50 shouldBe("key.type", "'private'") | 61 shouldBe("key.type", "'private'") |
51 shouldBe("key.extractable", "true") | 62 shouldBe("key.extractable", "true") |
52 shouldBe("key.algorithm.name", "'AES-CBC'") | 63 shouldBe("key.algorithm.name", "'AES-CBC'") |
53 shouldBe("key.algorithm.length", "1024") | 64 shouldBe("key.algorithm.length", "1024") |
54 shouldBe("key.usages.join(',')", "'encrypt,decrypt'") | 65 shouldBe("key.usages.join(',')", "'encrypt,decrypt'") |
55 | 66 |
56 key = results[1]; | 67 return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256' }}, f
alse, ['sign']); |
| 68 }).then(function(result) { |
| 69 key = result; |
57 shouldBe("key.type", "'private'") | 70 shouldBe("key.type", "'private'") |
58 shouldBe("key.extractable", "false") | 71 shouldBe("key.extractable", "false") |
59 shouldBe("key.algorithm.name", "'HMAC'") | 72 shouldBe("key.algorithm.name", "'HMAC'") |
60 shouldBe("key.algorithm.hash.name", "'SHA-256'") | 73 shouldBe("key.algorithm.hash.name", "'SHA-256'") |
61 shouldBe("key.algorithm.length", "null") | 74 shouldBe("key.algorithm.length", "null") |
62 shouldBe("key.usages.join(',')", "'sign'") | 75 shouldBe("key.usages.join(',')", "'sign'") |
63 | 76 |
64 key = results[2]; | 77 return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256' }, le
ngth:48 }, false, ['sign']); |
| 78 }).then(function(result) { |
| 79 key = result; |
65 shouldBe("key.type", "'private'") | 80 shouldBe("key.type", "'private'") |
66 shouldBe("key.extractable", "false") | 81 shouldBe("key.extractable", "false") |
67 shouldBe("key.algorithm.name", "'HMAC'") | 82 shouldBe("key.algorithm.name", "'HMAC'") |
68 shouldBe("key.algorithm.hash.name", "'SHA-256'") | 83 shouldBe("key.algorithm.hash.name", "'SHA-256'") |
69 shouldBe("key.algorithm.length", "48") | 84 shouldBe("key.algorithm.length", "48") |
70 shouldBe("key.usages.join(',')", "'sign'") | 85 shouldBe("key.usages.join(',')", "'sign'") |
71 | 86 }).then(finishJSTest, failAndFinishJSTest); |
72 finishJSTest(); | |
73 }); | |
74 | 87 |
75 </script> | 88 </script> |
76 | 89 |
77 <script src="../fast/js/resources/js-test-post.js"></script> | 90 <script src="../fast/js/resources/js-test-post.js"></script> |
78 </body> | 91 </body> |
79 </html> | 92 </html> |
OLD | NEW |