mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
crypto: reject Ed25519/Ed448 in Sign/Verify prototypes
fixes: #52097 PR-URL: https://github.com/nodejs/node/pull/52340 Fixes: https://github.com/nodejs/node/issues/52097 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
128c60d906
commit
9f939f5af7
2 files changed
+30
No files matched your search
@@ -423,6 +423,11 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
if (IsOneShot(key)) {
|
||||
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env);
|
||||
return;
|
||||
}
|
||||
|
||||
int padding = GetDefaultSignPadding(key);
|
||||
if (!args[offset]->IsUndefined()) {
|
||||
CHECK(args[offset]->IsInt32());
|
||||
@@ -548,6 +553,11 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
|
||||
if (!pkey)
|
||||
return;
|
||||
|
||||
if (IsOneShot(pkey)) {
|
||||
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env);
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayBufferOrViewContents<char> hbuf(args[offset]);
|
||||
if (UNLIKELY(!hbuf.CheckSizeInt32()))
|
||||
return THROW_ERR_OUT_OF_RANGE(env, "buffer is too big");
|
||||
|
||||
@@ -773,3 +773,23 @@ assert.throws(
|
||||
}, { code: 'ERR_INVALID_ARG_TYPE', message: /The "key\.key" property must be of type object/ });
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Ed25519 and Ed448 must use the one-shot methods
|
||||
const keys = [{ privateKey: fixtures.readKey('ed25519_private.pem', 'ascii'),
|
||||
publicKey: fixtures.readKey('ed25519_public.pem', 'ascii') },
|
||||
{ privateKey: fixtures.readKey('ed448_private.pem', 'ascii'),
|
||||
publicKey: fixtures.readKey('ed448_public.pem', 'ascii') }];
|
||||
|
||||
for (const { publicKey, privateKey } of keys) {
|
||||
assert.throws(() => {
|
||||
crypto.createSign('SHA256').update('Test123').sign(privateKey);
|
||||
}, { code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION', message: 'Unsupported crypto operation' });
|
||||
assert.throws(() => {
|
||||
crypto.createVerify('SHA256').update('Test123').verify(privateKey, 'sig');
|
||||
}, { code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION', message: 'Unsupported crypto operation' });
|
||||
assert.throws(() => {
|
||||
crypto.createVerify('SHA256').update('Test123').verify(publicKey, 'sig');
|
||||
}, { code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION', message: 'Unsupported crypto operation' });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user