Skip to content

Commit 9d4a226

Browse files
indutnyMyles Borins
authored and
Myles Borins
committed
crypto: clear error stack in ECDH::Initialize
Clean up OpenSSL error stack in `ECDH::Initialize`, some curves have faulty implementations that are leaving dangling errors after initializing the curve. Fix: #4686 PR-URL: #4689 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent d615757 commit 9d4a226

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/node_crypto.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4533,6 +4533,8 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
45334533
void ECDH::New(const FunctionCallbackInfo<Value>& args) {
45344534
Environment* env = Environment::GetCurrent(args);
45354535

4536+
MarkPopErrorOnReturn mark_pop_error_on_return;
4537+
45364538
// TODO(indutny): Support raw curves?
45374539
CHECK(args[0]->IsString());
45384540
node::Utf8Value curve(env->isolate(), args[0]);

test/parallel/test-crypto-dh.js

+5
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ var secret2 = ecdh2.computeSecret(key1, 'binary', 'buffer');
159159

160160
assert.equal(secret1, secret2.toString('base64'));
161161

162+
// Oakley curves do not clean up ERR stack, it was causing unexpected failure
163+
// when accessing other OpenSSL APIs afterwards.
164+
crypto.createECDH('Oakley-EC2N-3');
165+
crypto.createHash('sha256');
166+
162167
// Point formats
163168
assert.equal(ecdh1.getPublicKey('buffer', 'uncompressed')[0], 4);
164169
var firstByte = ecdh1.getPublicKey('buffer', 'compressed')[0];

0 commit comments

Comments
 (0)