| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 478a719 commit 58d13b6
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2642,8 +2642,6 @@ DataPointer hkdf(const Digest& md, | |||
| 2642 | 2642 | const Buffer<const unsigned char>& info, | |
| 2643 | 2643 | const Buffer<const unsigned char>& salt, | |
| 2644 | 2644 | size_t length) { | |
| 2645 | - ClearErrorOnReturn clearErrorOnReturn; | ||
| 2646 | - | ||
| 2647 | 2645 | if (!checkHkdfLength(md, length) || info.len > INT_MAX || | |
| 2648 | 2646 | salt.len > INT_MAX) { | |
| 2649 | 2647 | return {}; | |
@@ -2714,8 +2712,6 @@ DataPointer scrypt(const Buffer<const char>& pass, | |||
| 2714 | 2712 | uint64_t p, | |
| 2715 | 2713 | uint64_t maxmem, | |
| 2716 | 2714 | size_t length) { | |
| 2717 | - ClearErrorOnReturn clearErrorOnReturn; | ||
| 2718 | - | ||
| 2719 | 2715 | if (pass.len > INT_MAX || salt.len > INT_MAX) { | |
| 2720 | 2716 | return {}; | |
| 2721 | 2717 | } | |
@@ -2742,8 +2738,6 @@ DataPointer pbkdf2(const Digest& md, | |||
| 2742 | 2738 | const Buffer<const unsigned char>& salt, | |
| 2743 | 2739 | uint32_t iterations, | |
| 2744 | 2740 | size_t length) { | |
| 2745 | - ClearErrorOnReturn clearErrorOnReturn; | ||
| 2746 | - | ||
| 2747 | 2741 | if (pass.len > INT_MAX || salt.len > INT_MAX || length > INT_MAX) { | |
| 2748 | 2742 | return {}; | |
| 2749 | 2743 | } | |
@@ -2775,8 +2769,6 @@ DataPointer argon2(const Buffer<const char>& pass, | |||
| 2775 | 2769 | const Buffer<const unsigned char>& secret, | |
| 2776 | 2770 | const Buffer<const unsigned char>& ad, | |
| 2777 | 2771 | Argon2Type type) { | |
| 2778 | - ClearErrorOnReturn clearErrorOnReturn; | ||
| 2779 | - | ||
| 2780 | 2772 | std::string_view algorithm; | |
| 2781 | 2773 | switch (type) { | |
| 2782 | 2774 | case Argon2Type::ARGON2I: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,6 +147,7 @@ bool Argon2Traits::DeriveBits(Environment* env, | |||
| 147 | 147 | config.type); | |
| 148 | 148 | ||
| 149 | 149 | if (!dp) { | |
| 150 | + errors->Capture(); | ||
| 150 | 151 | errors->Insert(NodeCryptoError::ARGON2_FAILED); | |
| 151 | 152 | return false; | |
| 152 | 153 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,6 +127,7 @@ bool HKDFTraits::DeriveBits(Environment* env, | |||
| 127 | 127 | }, | |
| 128 | 128 | params.length); | |
| 129 | 129 | if (!dp) { | |
| 130 | + errors->Capture(); | ||
| 130 | 131 | errors->Insert(NodeCryptoError::HKDF_FAILED); | |
| 131 | 132 | return false; | |
| 132 | 133 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -135,6 +135,7 @@ bool PBKDF2Traits::DeriveBits(Environment* env, | |||
| 135 | 135 | params.length); | |
| 136 | 136 | ||
| 137 | 137 | if (!dp) { | |
| 138 | + errors->Capture(); | ||
| 138 | 139 | errors->Insert(NodeCryptoError::PBKDF2_FAILED); | |
| 139 | 140 | return false; | |
| 140 | 141 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,6 +132,7 @@ bool ScryptTraits::DeriveBits(Environment* env, | |||
| 132 | 132 | params.length); | |
| 133 | 133 | ||
| 134 | 134 | if (!dp) { | |
| 135 | + errors->Capture(); | ||
| 135 | 136 | errors->Insert(NodeCryptoError::SCRYPT_FAILED); | |
| 136 | 137 | return false; | |
| 137 | 138 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,19 +29,31 @@ const empty = Buffer.alloc(0); | |||
| 29 | 29 | ||
| 30 | 30 | // Parameters that OpenSSL's Argon2 KDF rejects. | |
| 31 | 31 | const badParams = [ | |
| 32 | - { lanes: 0, keylen: 32, memcost: 16, iter: 1 }, // lanes < 1 | ||
| 33 | - { lanes: 1, keylen: 32, memcost: 0, iter: 1 }, // memcost == 0 | ||
| 34 | - { lanes: 1, keylen: 32, memcost: 16, iter: 0 }, // iter == 0 | ||
| 32 | + { lanes: 0, keylen: 32, memcost: 16, iter: 1, | ||
| 33 | + code: 'ERR_OSSL_INVALID_THREAD_POOL_SIZE', reason: /invalid thread pool size/ }, | ||
| 34 | + { lanes: 1, keylen: 32, memcost: 0, iter: 1, | ||
| 35 | + code: 'ERR_OSSL_INVALID_MEMORY_SIZE', reason: /invalid memory size/ }, | ||
| 36 | + { lanes: 1, keylen: 32, memcost: 16, iter: 0, | ||
| 37 | + code: 'ERR_OSSL_INVALID_ITERATION_COUNT', reason: /invalid iteration count/ }, | ||
| 35 | 38 | ]; | |
| 36 | 39 | ||
| 37 | - for (const { lanes, keylen, memcost, iter } of badParams) { | ||
| 40 | + function assertError(err, { code, reason }) { | ||
| 41 | + assert.ok(err); | ||
| 42 | + assert.match(err.message, /Argon2 derivation failed/); | ||
| 43 | + assert.strictEqual(err.code, code); | ||
| 44 | + assert.ok(err.opensslErrorStack.some((msg) => reason.test(msg)), | ||
| 45 | + `did not find ${reason} in ${err.opensslErrorStack}`); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + for (const params of badParams) { | ||
| 49 | + const { lanes, keylen, memcost, iter } = params; | ||
| 50 | + | ||
| 38 | 51 | { | |
| 39 | 52 | const job = new Argon2Job( | |
| 40 | 53 | kCryptoJobSync, pass, salt, lanes, keylen, memcost, iter, | |
| 41 | 54 | empty, empty, kTypeArgon2id); | |
| 42 | 55 | const { 0: err, 1: result } = job.run(); | |
| 43 | - assert.ok(err); | ||
| 44 | - assert.match(err.message, /Argon2 derivation failed/); | ||
| 56 | + assertError(err, params); | ||
| 45 | 57 | assert.strictEqual(result, undefined); | |
| 46 | 58 | } | |
| 47 | 59 | ||
@@ -50,8 +62,7 @@ for (const { lanes, keylen, memcost, iter } of badParams) { | |||
| 50 | 62 | kCryptoJobAsync, pass, salt, lanes, keylen, memcost, iter, | |
| 51 | 63 | empty, empty, kTypeArgon2id); | |
| 52 | 64 | job.ondone = common.mustCall((err, result) => { | |
| 53 | - assert.ok(err); | ||
| 54 | - assert.match(err.message, /Argon2 derivation failed/); | ||
| 65 | + assertError(err, params); | ||
| 55 | 66 | assert.strictEqual(result, undefined); | |
| 56 | 67 | }); | |
| 57 | 68 | job.run(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,24 @@ if (isMainThread) { | |||
| 26 | 26 | `did not find ${expected} in ${err.opensslErrorStack}`); | |
| 27 | 27 | } | |
| 28 | 28 | })); | |
| 29 | + | ||
| 30 | + const derivations = [ | ||
| 31 | + ['HKDF', () => crypto.hkdfSync('sha256', Buffer.alloc(32), Buffer.alloc(8), | ||
| 32 | + Buffer.alloc(0), 32)], | ||
| 33 | + ['PBKDF2', () => crypto.pbkdf2Sync('secret', Buffer.alloc(16), 1000, 32, | ||
| 34 | + 'sha256')], | ||
| 35 | + ]; | ||
| 36 | + for (const { 0: name, 1: derive } of derivations) { | ||
| 37 | + try { | ||
| 38 | + derive(); | ||
| 39 | + } catch (err) { | ||
| 40 | + assert.match(err.message, /derivation failed/); | ||
| 41 | + assert.strictEqual(err.code, 'ERR_OSSL_EVP_UNSUPPORTED', `${name}: ${err.code}`); | ||
| 42 | + const expected = /digital envelope routines::unsupported/; | ||
| 43 | + assert(err.opensslErrorStack.some((msg) => expected.test(msg)), | ||
| 44 | + `${name}: did not find ${expected} in ${err.opensslErrorStack}`); | ||
| 45 | + } | ||
| 46 | + } | ||
| 29 | 47 | } | |
| 30 | 48 | ||
| 31 | 49 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments