Skip to content

Commit 858b48b

Browse files
committed
crypto: assign deprecation code for setAuthTag/GCM
PR-URL: #18017 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent b12425d commit 858b48b

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

doc/api/deprecations.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,18 @@ Importing assert directly is not recommended as the exposed functions will use
807807
loose equality checks. Use `require('assert').strict` instead. The API is the
808808
same as the legacy assert but it will always use strict equality checks.
809809
810+
<a id="DEP0090"></a>
811+
### DEP0090: Invalid GCM authentication tag lengths
812+
813+
Type: Runtime
814+
815+
Node.js supports all GCM authentication tag lengths which are accepted by
816+
OpenSSL when calling [`decipher.setAuthTag()`][]. This behavior will change in
817+
a future version at which point only authentication tag lengths of 128, 120,
818+
112, 104, 96, 64, and 32 bits will be allowed. Authentication tags whose length
819+
is not included in this list will be considered invalid in compliance with
820+
[NIST SP 800-38D][].
821+
810822
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
811823
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
812824
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
@@ -821,6 +833,7 @@ same as the legacy assert but it will always use strict equality checks.
821833
[`console.log()`]: console.html#console_console_log_data_args
822834
[`crypto.createCredentials()`]: crypto.html#crypto_crypto_createcredentials_details
823835
[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
836+
[`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer
824837
[`domain`]: domain.html
825838
[`ecdh.setPublicKey()`]: crypto.html#crypto_ecdh_setpublickey_publickey_encoding
826839
[`emitter.listenerCount(eventName)`]: events.html#events_emitter_listenercount_eventname
@@ -871,4 +884,5 @@ same as the legacy assert but it will always use strict equality checks.
871884
[alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size
872885
[from_arraybuffer]: buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length
873886
[from_string_encoding]: buffer.html#buffer_class_method_buffer_from_string_encoding
887+
[NIST SP 800-38D]: http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
874888
[`REPLServer.clearBufferedCommand()`]: repl.html#repl_replserver_clearbufferedcommand

src/node_crypto.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,10 +3157,11 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
31573157
// Restrict GCM tag lengths according to NIST 800-38d, page 9.
31583158
unsigned int tag_len = Buffer::Length(args[0]);
31593159
if (tag_len > 16 || (tag_len < 12 && tag_len != 8 && tag_len != 4)) {
3160-
ProcessEmitWarning(cipher->env(),
3161-
"Permitting authentication tag lengths of %u bytes is deprecated. "
3162-
"Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.",
3163-
tag_len);
3160+
char msg[125];
3161+
snprintf(msg, sizeof(msg),
3162+
"Permitting authentication tag lengths of %u bytes is deprecated. "
3163+
"Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.", tag_len);
3164+
ProcessEmitDeprecationWarning(cipher->env(), msg, "DEP0090");
31643165
}
31653166

31663167
// Note: we don't use std::max() here to work around a header conflict.

test/parallel/test-crypto-authenticated.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,17 @@ const errMessages = {
335335

336336
const ciphers = crypto.getCiphers();
337337

338-
common.expectWarning('Warning', (common.hasFipsCrypto ? [] : [
339-
'Use Cipheriv for counter mode of aes-192-gcm'
340-
]).concat(
341-
[0, 1, 2, 6, 9, 10, 11, 17]
338+
const expectedWarnings = common.hasFipsCrypto ?
339+
[] : ['Use Cipheriv for counter mode of aes-192-gcm'];
340+
341+
const expectedDeprecationWarnings = [0, 1, 2, 6, 9, 10, 11, 17]
342342
.map((i) => `Permitting authentication tag lengths of ${i} bytes is ` +
343-
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.')
344-
));
343+
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.');
344+
345+
common.expectWarning({
346+
Warning: expectedWarnings,
347+
DeprecationWarning: expectedDeprecationWarnings
348+
});
345349

346350
for (const test of TEST_CASES) {
347351
if (!ciphers.includes(test.algo)) {

0 commit comments

Comments
 (0)