GeezerVison is showing github.com — crypto: clear err stack after ECDH::BufferToPoint · nodejs/node@3640ba4
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/node_crypto.cc +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4916,6 +4916,8 @@ void ECDH::ComputeSecret(const FunctionCallbackInfo<Value>& args) { |
4916 | 4916 | ECDH* ecdh; |
4917 | 4917 | ASSIGN_OR_RETURN_UNWRAP(&ecdh, args.Holder()); |
4918 | 4918 |
|
| 4919 | + MarkPopErrorOnReturn mark_pop_error_on_return; |
| 4920 | + |
4919 | 4921 | EC_POINT* pub = ecdh->BufferToPoint(Buffer::Data(args[0]), |
4920 | 4922 | Buffer::Length(args[0])); |
4921 | 4923 | if (pub == nullptr) |
@@ -5038,6 +5040,8 @@ void ECDH::SetPublicKey(const FunctionCallbackInfo<Value>& args) { |
5038 | 5040 |
|
5039 | 5041 | THROW_AND_RETURN_IF_NOT_BUFFER(args[0]); |
5040 | 5042 |
|
| 5043 | + MarkPopErrorOnReturn mark_pop_error_on_return; |
| 5044 | + |
5041 | 5045 | EC_POINT* pub = ecdh->BufferToPoint(Buffer::Data(args[0].As<Object>()), |
5042 | 5046 | Buffer::Length(args[0].As<Object>())); |
5043 | 5047 | if (pub == nullptr) |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-crypto-dh.js +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -188,3 +188,23 @@ ecdh4.setPublicKey(ecdh1.getPublicKey()); |
188 | 188 | assert.throws(function() { |
189 | 189 | ecdh4.setPublicKey(ecdh3.getPublicKey()); |
190 | 190 | }); |
| 191 | + |
| 192 | +// Use of invalid keys was not cleaning up ERR stack, and was causing |
| 193 | +// unexpected failure in subsequent signing operations. |
| 194 | +var ecdh5 = crypto.createECDH('prime256v1'); |
| 195 | +var invalidKey = Buffer.alloc(65); |
| 196 | +invalidKey.fill('\0'); |
| 197 | +ecdh5.generateKeys(); |
| 198 | +assert.throws(() => { |
| 199 | + ecdh5.computeSecret(invalidKey); |
| 200 | +}, /^Error: Failed to translate Buffer to a EC_POINT$/); |
| 201 | +// Check that signing operations are not impacted by the above error. |
| 202 | +const ecPrivateKey = |
| 203 | + '-----BEGIN EC PRIVATE KEY-----\n' + |
| 204 | + 'MHcCAQEEIF+jnWY1D5kbVYDNvxxo/Y+ku2uJPDwS0r/VuPZQrjjVoAoGCCqGSM49\n' + |
| 205 | + 'AwEHoUQDQgAEurOxfSxmqIRYzJVagdZfMMSjRNNhB8i3mXyIMq704m2m52FdfKZ2\n' + |
| 206 | + 'pQhByd5eyj3lgZ7m7jbchtdgyOF8Io/1ng==\n' + |
| 207 | + '-----END EC PRIVATE KEY-----'; |
| 208 | +assert.doesNotThrow(() => { |
| 209 | + crypto.createSign('SHA256').sign(ecPrivateKey); |
| 210 | +}); |