diff --git a/src/crypto/crypto_sig.cc b/src/crypto/crypto_sig.cc index 64e788dcecaca1..a0ed640acaaa89 100644 --- a/src/crypto/crypto_sig.cc +++ b/src/crypto/crypto_sig.cc @@ -420,6 +420,11 @@ void Sign::SignFinal(const FunctionCallbackInfo& 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()); @@ -547,6 +552,11 @@ void Verify::VerifyFinal(const FunctionCallbackInfo& args) { if (!pkey) return; + if (IsOneShot(pkey)) { + THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env); + return; + } + ArrayBufferOrViewContents hbuf(args[offset]); if (UNLIKELY(!hbuf.CheckSizeInt32())) return THROW_ERR_OUT_OF_RANGE(env, "buffer is too big"); diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index 74c0ff53eb18b7..81adde1ba771c8 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -774,3 +774,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' }); + } +}