Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Last update:
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/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/7cbe7e8ed9/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/42e47329fd/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
Expand Down
54 changes: 35 additions & 19 deletions test/fixtures/wpt/WebCryptoAPI/digest/cshake.tentative.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,42 @@ Object.keys(digestedData).forEach(function (alg) {
});
}, alg + ' with ' + length + ' bit output and ' + size + ' source data');

promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
return crypto.subtle
.digest({ name: alg, length: length }, buffer)
.then(function (result) {
// Alter the buffer after calling digest
if (buffer.length > 0) {
if (sourceData[size].length > 0) {
promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
// Alter the buffer before calling digest
buffer[0] = ~buffer[0];
return crypto.subtle
.digest({
get name() {
// Alter the buffer back while calling digest
buffer[0] = sourceData[size][0];
return alg;
},
length
}, buffer)
.then(function (result) {
assert_true(
equalBuffers(result, digestedData[alg][length][size]),
'digest matches expected'
);
});
}, alg + ' with ' + length + ' bit output and ' + size + ' source data and altered buffer during call');

promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
return crypto.subtle
.digest({ name: alg, length: length }, buffer)
.then(function (result) {
// Alter the buffer after calling digest
buffer[0] = ~buffer[0];
}
assert_true(
equalBuffers(result, digestedData[alg][length][size]),
'digest matches expected'
);
});
}, alg +
' with ' +
length +
' bit output and ' +
size +
' source data and altered buffer after call');
assert_true(
equalBuffers(result, digestedData[alg][length][size]),
'digest matches expected'
);
});
}, alg + ' with ' + length + ' bit output and ' + size + ' source data and altered buffer after call');
}
});
});
});
Expand Down
44 changes: 31 additions & 13 deletions test/fixtures/wpt/WebCryptoAPI/digest/digest.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,37 @@
return promise;
}, mixedCase + " with " + size + " source data");

promise_test(function(test) {
var copiedBuffer = copyBuffer(sourceData[size]);
var promise = subtle.digest({name: upCase}, copiedBuffer)
.then(function(result) {
assert_true(equalBuffers(result, digestedData[alg][size]), "digest() yielded expected result for " + alg + ":" + size);
}, function(err) {
assert_unreached("digest() threw an error for " + alg + ":" + size + " - " + err.message);
});

copiedBuffer[0] = 255 - copiedBuffer;
return promise;
}, upCase + " with " + size + " source data and altered buffer after call");

if (sourceData[size].length > 0) {
promise_test(function(test) {
var copiedBuffer = copyBuffer(sourceData[size]);
copiedBuffer[0] = 255 - copiedBuffer[0];
var promise = subtle.digest({
get name() {
copiedBuffer[0] = sourceData[size][0];
return upCase;
}
}, copiedBuffer)
.then(function(result) {
assert_true(equalBuffers(result, digestedData[alg][size]), "digest() yielded expected result for " + alg + ":" + size);
}, function(err) {
assert_unreached("digest() threw an error for " + alg + ":" + size + " - " + err.message);
});
return promise;
}, upCase + " with " + size + " source data and altered buffer during call");

promise_test(function(test) {
var copiedBuffer = copyBuffer(sourceData[size]);
var promise = subtle.digest({name: upCase}, copiedBuffer)
.then(function(result) {
assert_true(equalBuffers(result, digestedData[alg][size]), "digest() yielded expected result for " + alg + ":" + size);
}, function(err) {
assert_unreached("digest() threw an error for " + alg + ":" + size + " - " + err.message);
});

copiedBuffer[0] = 255 - copiedBuffer[0];
return promise;
}, upCase + " with " + size + " source data and altered buffer after call");
}
});
});

Expand Down
44 changes: 32 additions & 12 deletions test/fixtures/wpt/WebCryptoAPI/digest/sha3.tentative.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,39 @@ Object.keys(sourceData).forEach(function (size) {
});
}, alg + ' with ' + size + ' source data');

promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
return crypto.subtle.digest(alg, buffer).then(function (result) {
// Alter the buffer after calling digest
if (buffer.length > 0) {
if (sourceData[size].length > 0) {
promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
// Alter the buffer before calling digest
buffer[0] = ~buffer[0];
return crypto.subtle
.digest({
get name() {
// Alter the buffer back while calling digest
buffer[0] = sourceData[size][0];
return alg;
}
}, buffer)
.then(function (result) {
assert_true(
equalBuffers(result, digestedData[alg][size]),
'digest matches expected'
);
});
}, alg + ' with ' + size + ' source data and altered buffer during call');

promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
return crypto.subtle.digest(alg, buffer).then(function (result) {
// Alter the buffer after calling digest
buffer[0] = ~buffer[0];
}
assert_true(
equalBuffers(result, digestedData[alg][size]),
'digest matches expected'
);
});
}, alg + ' with ' + size + ' source data and altered buffer after call');
assert_true(
equalBuffers(result, digestedData[alg][size]),
'digest matches expected'
);
});
}, alg + ' with ' + size + ' source data and altered buffer after call');
}
});
});

Expand Down
74 changes: 69 additions & 5 deletions test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,38 @@ function run_test() {
all_promises.push(promise);
});

// Check for successful encryption even if the buffer is changed while calling encrypt.
passingVectors.forEach(function(vector) {
var plaintext = copyBuffer(vector.plaintext);
plaintext[0] = 255 - plaintext[0];
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
.then(function(vector) {
promise_test(function(test) {
var operation = subtle.encrypt({
...vector.algorithm,
get name() {
plaintext[0] = vector.plaintext[0];
return vector.algorithm.name;
}
}, vector.key, plaintext)
.then(function(result) {
assert_true(equalBuffers(result, vector.result), "Should return expected result");
}, function(err) {
assert_unreached("encrypt error for test " + vector.name + ": " + err.message);
});
return operation;
}, vector.name + " with altered plaintext during call");
}, function(err) {
// We need a failed test if the importVectorKey operation fails, so
// we know we never tested encryption
promise_test(function(test) {
assert_unreached("importKey failed for " + vector.name);
}, "importKey step: " + vector.name + " with altered plaintext during call");
});

all_promises.push(promise);
});

// Check for successful encryption even if the buffer is changed after calling encrypt.
passingVectors.forEach(function(vector) {
var plaintext = copyBuffer(vector.plaintext);
Expand All @@ -49,13 +81,13 @@ function run_test() {
});
plaintext[0] = 255 - plaintext[0];
return operation;
}, vector.name + " with altered plaintext");
}, vector.name + " with altered plaintext after call");
}, function(err) {
// We need a failed test if the importVectorKey operation fails, so
// we know we never tested encryption
promise_test(function(test) {
assert_unreached("importKey failed for " + vector.name);
}, "importKey step: " + vector.name + " with altered plaintext");
}, "importKey step: " + vector.name + " with altered plaintext after call");
});

all_promises.push(promise);
Expand Down Expand Up @@ -84,7 +116,39 @@ function run_test() {
all_promises.push(promise);
});

// Check for successful decryption even if ciphertext is altered.
// Check for successful decryption even if ciphertext is altered while calling encrypt.
passingVectors.forEach(function(vector) {
var ciphertext = copyBuffer(vector.result);
ciphertext[0] = 255 - ciphertext[0];
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
.then(function(vector) {
promise_test(function(test) {
var operation = subtle.decrypt({
...vector.algorithm,
get name() {
ciphertext[0] = vector.result[0];
return vector.algorithm.name;
}
}, vector.key, ciphertext)
.then(function(result) {
assert_true(equalBuffers(result, vector.plaintext), "Should return expected result");
}, function(err) {
assert_unreached("decrypt error for test " + vector.name + ": " + err.message);
});
return operation;
}, vector.name + " decryption with altered ciphertext during call");
}, function(err) {
// We need a failed test if the importVectorKey operation fails, so
// we know we never tested encryption
promise_test(function(test) {
assert_unreached("importKey failed for " + vector.name);
}, "importKey step for decryption: " + vector.name + " with altered ciphertext during call");
});

all_promises.push(promise);
});

// Check for successful decryption even if ciphertext is altered after calling encrypt.
passingVectors.forEach(function(vector) {
var ciphertext = copyBuffer(vector.result);
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
Expand All @@ -98,13 +162,13 @@ function run_test() {
});
ciphertext[0] = 255 - ciphertext[0];
return operation;
}, vector.name + " decryption with altered ciphertext");
}, vector.name + " decryption with altered ciphertext after call");
}, function(err) {
// We need a failed test if the importVectorKey operation fails, so
// we know we never tested encryption
promise_test(function(test) {
assert_unreached("importKey failed for " + vector.name);
}, "importKey step for decryption: " + vector.name + " with altered ciphertext");
}, "importKey step for decryption: " + vector.name + " with altered ciphertext after call");
});

all_promises.push(promise);
Expand Down
Loading
Loading