Skip to content

Commit ebd9add

Browse files
indutnyShigeki Ohtsu
authored and
Shigeki Ohtsu
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 <thechargingvolcano@gmail.com> Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
1 parent 310530b commit ebd9add

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/node_crypto.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,6 +4678,8 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
46784678
void ECDH::New(const FunctionCallbackInfo<Value>& args) {
46794679
Environment* env = Environment::GetCurrent(args);
46804680

4681+
MarkPopErrorOnReturn mark_pop_error_on_return;
4682+
46814683
// TODO(indutny): Support raw curves?
46824684
CHECK(args[0]->IsString());
46834685
node::Utf8Value curve(env->isolate(), args[0]);

test/parallel/test-crypto-dh.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ 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
let firstByte = ecdh1.getPublicKey('buffer', 'compressed')[0];

0 commit comments

Comments
 (0)