Skip to content

Commit d244204

Browse files
panvarichardlau
authored andcommitted
crypto: reject Ed25519/Ed448 in Sign/Verify prototypes
fixes: #52097 PR-URL: #52340 Fixes: #52097 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent b097d85 commit d244204

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/crypto/crypto_sig.cc

+10
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
420420
if (!key)
421421
return;
422422

423+
if (IsOneShot(key)) {
424+
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env);
425+
return;
426+
}
427+
423428
int padding = GetDefaultSignPadding(key);
424429
if (!args[offset]->IsUndefined()) {
425430
CHECK(args[offset]->IsInt32());
@@ -547,6 +552,11 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
547552
if (!pkey)
548553
return;
549554

555+
if (IsOneShot(pkey)) {
556+
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env);
557+
return;
558+
}
559+
550560
ArrayBufferOrViewContents<char> hbuf(args[offset]);
551561
if (UNLIKELY(!hbuf.CheckSizeInt32()))
552562
return THROW_ERR_OUT_OF_RANGE(env, "buffer is too big");

test/parallel/test-crypto-sign-verify.js

+20
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,23 @@ assert.throws(
774774
}, { code: 'ERR_INVALID_ARG_TYPE', message: /The "key\.key" property must be of type object/ });
775775
}
776776
}
777+
778+
{
779+
// Ed25519 and Ed448 must use the one-shot methods
780+
const keys = [{ privateKey: fixtures.readKey('ed25519_private.pem', 'ascii'),
781+
publicKey: fixtures.readKey('ed25519_public.pem', 'ascii') },
782+
{ privateKey: fixtures.readKey('ed448_private.pem', 'ascii'),
783+
publicKey: fixtures.readKey('ed448_public.pem', 'ascii') }];
784+
785+
for (const { publicKey, privateKey } of keys) {
786+
assert.throws(() => {
787+
crypto.createSign('SHA256').update('Test123').sign(privateKey);
788+
}, { code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION', message: 'Unsupported crypto operation' });
789+
assert.throws(() => {
790+
crypto.createVerify('SHA256').update('Test123').verify(privateKey, 'sig');
791+
}, { code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION', message: 'Unsupported crypto operation' });
792+
assert.throws(() => {
793+
crypto.createVerify('SHA256').update('Test123').verify(publicKey, 'sig');
794+
}, { code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION', message: 'Unsupported crypto operation' });
795+
}
796+
}

0 commit comments

Comments
 (0)