From b5f9ed75b6a04c7a33fce2d2c753f659ec993e9b Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Fri, 24 Apr 2015 16:07:56 +0200 Subject: [PATCH] Bug 1106087 - Add test to ensure we can export newly generated ECDH private keys r=rbarnes --- dom/crypto/test/test_WebCrypto_ECDH.html | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dom/crypto/test/test_WebCrypto_ECDH.html b/dom/crypto/test/test_WebCrypto_ECDH.html index 04dc0c00e1d..4aa2a00e957 100644 --- a/dom/crypto/test/test_WebCrypto_ECDH.html +++ b/dom/crypto/test/test_WebCrypto_ECDH.html @@ -298,6 +298,37 @@ TestArray.addTest( } ); +// ----------------------------------------------------------------------------- +TestArray.addTest( + "JWK export of a newly generated ECDH private key", + function () { + var that = this; + var alg = { name: "ECDH", namedCurve: "P-256" }; + var reBase64URL = /^[a-zA-Z0-9_-]+$/; + + function doExportToJWK(x) { + return crypto.subtle.exportKey("jwk", x.privateKey) + } + + crypto.subtle.generateKey(alg, true, ["deriveKey", "deriveBits"]) + .then(doExportToJWK) + .then( + complete(that, function(x) { + return x.ext && + x.kty == 'EC' && + x.crv == 'P-256' && + reBase64URL.test(x.x) && + reBase64URL.test(x.y) && + reBase64URL.test(x.d) && + x.x.length == 43 && // 32 octets, base64-encoded + x.y.length == 43 && // 32 octets, base64-encoded + shallowArrayEquals(x.key_ops, ['deriveKey', 'deriveBits']); + }), + error(that) + ); + } +); + // ----------------------------------------------------------------------------- TestArray.addTest( "Derive an HMAC key from two ECDH keys and test sign/verify",