node/test/parallel/test-crypto-webcrypto-aes-decrypt-tag-too-small.js
XadillaX 7a9635b094 crypto: fix aes crash when tag length too small
Fixes: https://github.com/nodejs/node/issues/38883

PR-URL: https://github.com/nodejs/node/pull/38914
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-06-15 14:21:28 +08:00

30 lines
583 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto').webcrypto;
crypto.subtle.importKey(
'raw',
new Uint8Array(32),
{
name: 'AES-GCM'
},
false,
[ 'encrypt', 'decrypt' ])
.then((k) => {
assert.rejects(() => {
return crypto.subtle.decrypt({
name: 'AES-GCM',
iv: new Uint8Array(12),
}, k, new Uint8Array(0));
}, {
name: 'OperationError',
message: /The provided data is too small/,
});
});