Skip to content

Commit a55c15d

Browse files
committed
crypto: move DEP0182 to End-of-Life
This commit moves support for implicitly short GCM authentication tags to End-of-Life status, thus requiring applications to explicitly specify the `authTagLength` for authentication tags shorter than 128 bits. There is quite a bit of refactoring to be done in the C++ source code. This commit does not do that; instead, it implements a minimal change only in order to avoid excessive divergence across git branches due to this being a semver-major change. Fixes: #52327 Refs: #17523
1 parent 05f8772 commit a55c15d

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

doc/api/crypto.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ When passing a string as the `buffer`, please consider
925925
<!-- YAML
926926
added: v1.0.0
927927
changes:
928+
- version: REPLACEME
929+
pr-url: ???
930+
description: Using GCM tag lengths other than 128 bits without specifying
931+
the `authTagLength` option when creating `decipher` is not
932+
allowed anymore.
928933
- version:
929934
- v22.0.0
930935
- v20.13.0

doc/api/deprecations.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,6 +3992,9 @@ Please use the [`crypto.createHmac()`][] method to create Hmac instances.
39923992

39933993
<!-- YAML
39943994
changes:
3995+
- version: REPLACEME
3996+
pr-url: ???
3997+
description: End-of-Life.
39953998
- version: v23.0.0
39963999
pr-url: https://github.com/nodejs/node/pull/52552
39974000
description: Runtime deprecation.
@@ -4006,9 +4009,10 @@ Applications that intend to use authentication tags that are shorter than the
40064009
default authentication tag length must set the `authTagLength` option of the
40074010
[`crypto.createDecipheriv()`][] function to the appropriate length.
40084011

4009-
For ciphers in GCM mode, the [`decipher.setAuthTag()`][] function accepts
4010-
authentication tags of any valid length (see [DEP0090](#DEP0090)). This behavior
4011-
is deprecated to better align with recommendations per [NIST SP 800-38D][].
4012+
For ciphers in GCM mode, the [`decipher.setAuthTag()`][] function used to accept
4013+
authentication tags of any valid length (see also [DEP0090](#DEP0090)). This
4014+
permissive behavior has been removed to better align with recommendations per
4015+
[NIST SP 800-38D][].
40124016

40134017
### DEP0183: OpenSSL engine-based APIs
40144018

src/crypto/crypto_cipher.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -554,23 +554,14 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
554554
is_valid = cipher->auth_tag_len_ == tag_len;
555555
}
556556

557-
if (!is_valid) {
557+
// TODO(tniessen): refactor this check.
558+
if (!is_valid ||
559+
(cipher->ctx_.isGcmMode() && cipher->auth_tag_len_ == kNoAuthTagLength &&
560+
tag_len != EVP_GCM_TLS_TAG_LEN)) {
558561
return THROW_ERR_CRYPTO_INVALID_AUTH_TAG(
559562
env, "Invalid authentication tag length: %u", tag_len);
560563
}
561564

562-
if (cipher->ctx_.isGcmMode() && cipher->auth_tag_len_ == kNoAuthTagLength &&
563-
tag_len != EVP_GCM_TLS_TAG_LEN && env->EmitProcessEnvWarning()) {
564-
if (ProcessEmitDeprecationWarning(
565-
env,
566-
"Using AES-GCM authentication tags of less than 128 bits without "
567-
"specifying the authTagLength option when initializing decryption "
568-
"is deprecated.",
569-
"DEP0182")
570-
.IsNothing())
571-
return;
572-
}
573-
574565
cipher->auth_tag_len_ = tag_len;
575566
CHECK_LE(cipher->auth_tag_len_, ncrypto::Cipher::MAX_AUTH_TAG_LENGTH);
576567

test/parallel/test-crypto-gcm-implicit-short-tag.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ const common = require('../common');
33
if (!common.hasCrypto)
44
common.skip('missing crypto');
55

6+
const assert = require('assert');
67
const { createDecipheriv, randomBytes } = require('crypto');
78

8-
common.expectWarning({
9-
DeprecationWarning: [
10-
['Using AES-GCM authentication tags of less than 128 bits without ' +
11-
'specifying the authTagLength option when initializing decryption is ' +
12-
'deprecated.',
13-
'DEP0182'],
14-
]
15-
});
16-
179
const key = randomBytes(32);
1810
const iv = randomBytes(16);
19-
const tag = randomBytes(12);
20-
createDecipheriv('aes-256-gcm', key, iv).setAuthTag(tag);
11+
for (let tagLength = 0; tagLength < 16; tagLength++) {
12+
const tag = randomBytes(tagLength);
13+
assert.throws(() => {
14+
createDecipheriv('aes-256-gcm', key, iv).setAuthTag(tag);
15+
}, {
16+
message: `Invalid authentication tag length: ${tagLength}`,
17+
});
18+
}

0 commit comments

Comments
 (0)