diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 94d0cf01d87083..cd16d09991969c 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -34,7 +34,7 @@ Last update: - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/288c467d35/wasm/jsapi - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi - web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks -- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/0c413fb56b/WebCryptoAPI +- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/03a1476844/WebCryptoAPI - webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions - webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel diff --git a/test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.js b/test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.js index 8633af5279caa1..795d90ffbff4fd 100644 --- a/test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.js +++ b/test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.js @@ -59,6 +59,20 @@ function runTests(algorithmName) { testFormat(format, algorithm, data, keyData.length * 8, usages, extractable); }); testEmptyUsages(format, algorithm, data, keyData.length * 8, extractable); + + // Verify the key data is copied only after the algorithm is + // normalized (per spec, "get a copy of the bytes held by the + // keyData parameter" follows "normalize an algorithm"). A + // getter on the algorithm name mutates the key data during + // normalization; the imported key must reflect the restored + // bytes. Checked for BufferSource formats (jwk key data is + // not a BufferSource) when the key is extractable, so the + // imported bytes can be read back and compared. + if (extractable && format !== "jwk") { + allValidUsages(vector.legalUsages).forEach(function(usages) { + testKeyDataAlteredDuringCall(format, algorithm, keyData, keyData.length * 8, usages); + }); + } }); }); @@ -111,6 +125,35 @@ function runTests(algorithmName) { }, "Empty Usages: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, extractable, usages)); } + // Test that importKey copies the key data only after the algorithm has been + // normalized. The spec normalizes the algorithm (which can run author + // getters on the algorithm dictionary) before getting a copy of the bytes + // held by the keyData parameter. Here a getter on the algorithm's name + // mutates the key data during normalization and then restores it, so a + // spec-compliant implementation imports the restored (original) bytes. + function testKeyDataAlteredDuringCall(format, algorithm, keyData, keySize, usages) { + promise_test(function(test) { + var alteredKeyData = copyBuffer(keyData); + alteredKeyData[0] = 255 - alteredKeyData[0]; + var algorithmWithGetter = { + ...algorithm, + get name() { + alteredKeyData[0] = keyData[0]; + return algorithm.name; + } + }; + return subtle.importKey(format, alteredKeyData, algorithmWithGetter, true, usages). + then(function(key) { + return subtle.exportKey(format, key); + }). + then(function(result) { + assert_true(equalBuffers(keyData, result), "Imported key reflects the key data as it was after normalization"); + }, function(err) { + assert_unreached("Threw an unexpected error: " + err.toString()); + }); + }, "Key data altered during call: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, true, usages)); + } + // Helper methods follow: diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 4921aa48d0fd82..d1929a839269e5 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -96,7 +96,7 @@ "path": "web-locks" }, "WebCryptoAPI": { - "commit": "0c413fb56b9da8bf27502c866a3d60f93981804d", + "commit": "03a14768441c1ce2a31678d0dc080e81dc449d0a", "path": "WebCryptoAPI" }, "webidl": {