GeezerVison is showing github.com — crypto: reject Ed25519/Ed448 in Sign/Verify prototypes · nodejs/node@d244204
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_sig.cc +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -420,6 +420,11 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) { |
420 | 420 | if (!key) |
421 | 421 | return; |
422 | 422 |
|
| 423 | + if (IsOneShot(key)) { |
| 424 | + THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env); |
| 425 | + return; |
| 426 | + } |
| 427 | + |
423 | 428 | int padding = GetDefaultSignPadding(key); |
424 | 429 | if (!args[offset]->IsUndefined()) { |
425 | 430 | CHECK(args[offset]->IsInt32()); |
@@ -547,6 +552,11 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) { |
547 | 552 | if (!pkey) |
548 | 553 | return; |
549 | 554 |
|
| 555 | + if (IsOneShot(pkey)) { |
| 556 | + THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env); |
| 557 | + return; |
| 558 | + } |
| 559 | + |
550 | 560 | ArrayBufferOrViewContents<char> hbuf(args[offset]); |
551 | 561 | if (UNLIKELY(!hbuf.CheckSizeInt32())) |
552 | 562 | return THROW_ERR_OUT_OF_RANGE(env, "buffer is too big"); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-crypto-sign-verify.js +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -774,3 +774,23 @@ assert.throws( |
774 | 774 | }, { code: 'ERR_INVALID_ARG_TYPE', message: /The "key\.key" property must be of type object/ }); |
775 | 775 | } |
776 | 776 | } |
| 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 | +} |