mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
crypto: fix auth tag length error when mode != GCM
PR-URL: https://github.com/nodejs/node/pull/42383 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
@@ -593,7 +593,8 @@ bool CipherBase::InitAuthenticated(
|
||||
// Tell OpenSSL about the desired length.
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
|
||||
nullptr)) {
|
||||
THROW_ERR_CRYPTO_INVALID_AUTH_TAG(env());
|
||||
THROW_ERR_CRYPTO_INVALID_AUTH_TAG(
|
||||
env(), "Invalid authentication tag length: %u", auth_tag_len);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ const errMessages = {
|
||||
state: / state/,
|
||||
FIPS: /not supported in FIPS mode/,
|
||||
length: /Invalid initialization vector/,
|
||||
authTagLength: /Invalid authentication tag/
|
||||
authTagLength: /Invalid authentication tag length/
|
||||
};
|
||||
|
||||
const ciphers = crypto.getCiphers();
|
||||
@@ -687,3 +687,17 @@ for (const test of TEST_CASES) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const key = Buffer.alloc(32);
|
||||
const iv = Buffer.alloc(12);
|
||||
|
||||
for (const authTagLength of [0, 17]) {
|
||||
assert.throws(() => {
|
||||
crypto.createCipheriv('chacha20-poly1305', key, iv, { authTagLength });
|
||||
}, {
|
||||
code: 'ERR_CRYPTO_INVALID_AUTH_TAG',
|
||||
message: errMessages.authTagLength
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user