Skip to content

Commit d81a7b4

Browse files
tniessenjasnell
authored andcommitted
crypto: throw on invalid authentication tag length
Refs: #17523 PR-URL: #17825 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2b0825e commit d81a7b4

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/node_crypto.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -2912,11 +2912,10 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
29122912
const int mode = EVP_CIPHER_CTX_mode(cipher->ctx_);
29132913
if (mode == EVP_CIPH_GCM_MODE) {
29142914
if (tag_len > 16 || (tag_len < 12 && tag_len != 8 && tag_len != 4)) {
2915-
char msg[125];
2915+
char msg[50];
29162916
snprintf(msg, sizeof(msg),
2917-
"Permitting authentication tag lengths of %u bytes is deprecated. "
2918-
"Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.", tag_len);
2919-
ProcessEmitDeprecationWarning(cipher->env(), msg, "DEP0090");
2917+
"Invalid GCM authentication tag length: %u", tag_len);
2918+
return cipher->env()->ThrowError(msg);
29202919
}
29212920
}
29222921

test/parallel/test-crypto-authenticated.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,8 @@ const expectedWarnings = common.hasFipsCrypto ?
534534
['Use Cipheriv for counter mode of aes-256-ccm', common.noWarnCode]
535535
];
536536

537-
const expectedDeprecationWarnings = [0, 1, 2, 6, 9, 10, 11, 17]
538-
.map((i) => [`Permitting authentication tag lengths of ${i} bytes is ` +
539-
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.',
540-
'DEP0090']);
541-
542-
expectedDeprecationWarnings.push(['crypto.DEFAULT_ENCODING is deprecated.',
543-
'DEP0091']);
537+
const expectedDeprecationWarnings = ['crypto.DEFAULT_ENCODING is deprecated.',
538+
'DEP0091'];
544539

545540
common.expectWarning({
546541
Warning: expectedWarnings,
@@ -719,13 +714,18 @@ for (const test of TEST_CASES) {
719714
}
720715

721716
// GCM only supports specific authentication tag lengths, invalid lengths should
722-
// produce warnings.
717+
// throw.
723718
{
724-
for (const length of [0, 1, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) {
725-
const decrypt = crypto.createDecipheriv('aes-256-gcm',
726-
'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
727-
'qkuZpJWCewa6Szih');
728-
decrypt.setAuthTag(Buffer.from('1'.repeat(length)));
719+
for (const length of [0, 1, 2, 6, 9, 10, 11, 17]) {
720+
common.expectsError(() => {
721+
const decrypt = crypto.createDecipheriv('aes-128-gcm',
722+
'FxLKsqdmv0E9xrQh',
723+
'qkuZpJWCewa6Szih');
724+
decrypt.setAuthTag(Buffer.from('1'.repeat(length)));
725+
}, {
726+
type: Error,
727+
message: `Invalid GCM authentication tag length: ${length}`
728+
});
729729
}
730730
}
731731

0 commit comments

Comments
 (0)