Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
crypto: don't ignore DH init errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Dec 16, 2011
1 parent ee73132 commit cc2861e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/node_crypto.cc
Expand Up @@ -3504,8 +3504,7 @@ class DiffieHellman : public ObjectWrap {

if (args.Length() > 0) {
if (args[0]->IsInt32()) {
diffieHellman->Init(args[0]->Int32Value());
initialized = true;
initialized = diffieHellman->Init(args[0]->Int32Value());
} else {
if (args[0]->IsString()) {
char* buf;
Expand All @@ -3521,16 +3520,15 @@ class DiffieHellman : public ObjectWrap {
return ThrowException(Exception::Error(
String::New("Invalid argument")));
} else {
diffieHellman->Init(reinterpret_cast<unsigned char*>(buf), len);
initialized = diffieHellman->Init(
reinterpret_cast<unsigned char*>(buf), len);
delete[] buf;
initialized = true;
}
} else if (Buffer::HasInstance(args[0])) {
Local<Object> buffer = args[0]->ToObject();
diffieHellman->Init(
initialized = diffieHellman->Init(
reinterpret_cast<unsigned char*>(Buffer::Data(buffer)),
Buffer::Length(buffer));
initialized = true;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-crypto.js
Expand Up @@ -380,6 +380,14 @@ var secret3 = dh3.computeSecret(key2, 'hex', 'base64');

assert.equal(secret1, secret3);

// https://github.com/joyent/node/issues/2338
assert.throws(function() {
var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' +
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' +
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
crypto.createDiffieHellman(p, 'hex');
});

// Test RSA key signing/verification
var rsaSign = crypto.createSign('RSA-SHA1');
Expand Down

0 comments on commit cc2861e

Please sign in to comment.