OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 <script src="resources/common.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 <p id="description"></p> |
| 9 <div id="console"></div> |
| 10 |
| 11 <script> |
| 12 description("Tests bad inputs to ECDH's deriveBits()"); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 var keyPairs = { |
| 17 ecdh: {}, |
| 18 ecdsa: {} |
| 19 }; |
| 20 |
| 21 // Generate some EC keys for ECDSA and ECDH. |
| 22 function createTestKeys() { |
| 23 return crypto.subtle.generateKey({name: "ecdh", namedCurve: "P-256"}, true,
["deriveBits"]).then(function(result) { |
| 24 keyPairs.ecdh.p256_1 = result; |
| 25 |
| 26 return crypto.subtle.generateKey({name: "ecdh", namedCurve: "P-256"}, true
, ["deriveBits"]); |
| 27 }).then(function(result) { |
| 28 keyPairs.ecdh.p256_2 = result; |
| 29 |
| 30 return crypto.subtle.generateKey({name: "ecdh", namedCurve: "P-384"}, true
, ["deriveBits"]); |
| 31 }).then(function(result) { |
| 32 keyPairs.ecdh.p384_1 = result; |
| 33 |
| 34 return crypto.subtle.generateKey({name: "ecdsa", namedCurve: "P-256"}, tru
e, ["sign"]); |
| 35 }).then(function(result) { |
| 36 keyPairs.ecdsa.p256_1 = result; |
| 37 }); |
| 38 } |
| 39 |
| 40 createTestKeys().then(function(result) { |
| 41 // Bad algorithm parameter (no algorithm name or public key) |
| 42 return crypto.subtle.deriveBits({}, keyPairs.ecdh.p256_1.privateKey, 256); |
| 43 }).then(failAndFinishJSTest, function(result) { |
| 44 logError(result); |
| 45 |
| 46 // Bad algorithm parameter (no public key) |
| 47 return crypto.subtle.deriveBits({name: 'ecdh'}, keyPairs.ecdh.p256_1.privateKe
y, 256); |
| 48 }).then(failAndFinishJSTest, function(result) { |
| 49 logError(result); |
| 50 |
| 51 // Bad algorithm parameter (null) |
| 52 return crypto.subtle.deriveBits(null, keyPairs.ecdh.p256_1.privateKey, 256); |
| 53 }).then(failAndFinishJSTest, function(result) { |
| 54 logError(result); |
| 55 |
| 56 // Bad algorithm parameter (not an object) |
| 57 return crypto.subtle.deriveBits(-1, keyPairs.ecdh.p256_1.privateKey, 256); |
| 58 }).then(failAndFinishJSTest, function(result) { |
| 59 logError(result); |
| 60 |
| 61 // Bad algorithm parameter (public key is null) |
| 62 return crypto.subtle.deriveBits({name: 'ecdh', public: null}, keyPairs.ecdh.p2
56_1.privateKey, 256); |
| 63 }).then(failAndFinishJSTest, function(result) { |
| 64 logError(result); |
| 65 |
| 66 // Bad algorithm parameter (public key is wrong type) |
| 67 return crypto.subtle.deriveBits({name: 'ecdh', public: -1}, keyPairs.ecdh.p256
_1.privateKey, 256); |
| 68 }).then(failAndFinishJSTest, function(result) { |
| 69 logError(result); |
| 70 |
| 71 // Bad algorithm parameter (public key is wrong type) |
| 72 return crypto.subtle.deriveBits({name: 'ecdh', public: "foo"}, keyPairs.ecdh.p
256_1.privateKey, 256); |
| 73 }).then(failAndFinishJSTest, function(result) { |
| 74 logError(result); |
| 75 |
| 76 // Bad algorithm parameter (public key is for wrong curve) |
| 77 return crypto.subtle.deriveBits({name: 'ecdh', public: keyPairs.ecdh.p384_1.pu
blicKey}, keyPairs.ecdh.p256_1.privateKey, 256); |
| 78 }).then(failAndFinishJSTest, function(result) { |
| 79 logError(result); |
| 80 |
| 81 // Bad algorithm parameter (public key is not a public key) |
| 82 return crypto.subtle.deriveBits({name: 'ecdh', public: keyPairs.ecdh.p256_2.pr
ivateKey}, keyPairs.ecdh.p256_1.privateKey, 256); |
| 83 }).then(failAndFinishJSTest, function(result) { |
| 84 logError(result); |
| 85 |
| 86 // Bad algorithm parameter (public key is for ECDSA). |
| 87 return crypto.subtle.deriveBits({name: 'ecdh', public: keyPairs.ecdsa.p256_1.p
ublicKey}, keyPairs.ecdh.p256_1.privateKey, {test: 3}); |
| 88 }).then(failAndFinishJSTest, function(result) { |
| 89 logError(result); |
| 90 }).then(finishJSTest, failAndFinishJSTest); |
| 91 |
| 92 </script> |
| 93 |
| 94 </body> |
| 95 </html> |
OLD | NEW |