-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,crypto: fix 0-length output crash in webcrypto
Fixes: #38883
- Loading branch information
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const crypto = require('crypto').webcrypto; | ||
|
||
(async () => { | ||
const k = await crypto.subtle.importKey( | ||
'raw', | ||
new Uint8Array(32), | ||
{ name: 'AES-GCM' }, | ||
false, | ||
[ 'encrypt', 'decrypt' ]); | ||
assert(k instanceof crypto.CryptoKey); | ||
|
||
const e = await crypto.subtle.encrypt({ | ||
name: 'AES-GCM', | ||
iv: new Uint8Array(12), | ||
}, k, new Uint8Array(0)); | ||
assert(e instanceof ArrayBuffer); | ||
assert.deepStrictEqual( | ||
Buffer.from(e), | ||
Buffer.from([ | ||
0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9, | ||
0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b ])); | ||
|
||
const v = await crypto.subtle.decrypt({ | ||
name: 'AES-GCM', | ||
iv: new Uint8Array(12), | ||
}, k, e); | ||
assert(v instanceof ArrayBuffer); | ||
assert.strictEqual(v.byteLength, 0); | ||
})().then(common.mustCall()).catch((e) => { | ||
assert.ifError(e); | ||
}); |