Browse Source

crypto: don't ignore DH init errors

v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
cc2861ee44
  1. 10
      src/node_crypto.cc
  2. 8
      test/simple/test-crypto.js

10
src/node_crypto.cc

@ -3504,8 +3504,7 @@ class DiffieHellman : public ObjectWrap {
if (args.Length() > 0) { if (args.Length() > 0) {
if (args[0]->IsInt32()) { if (args[0]->IsInt32()) {
diffieHellman->Init(args[0]->Int32Value()); initialized = diffieHellman->Init(args[0]->Int32Value());
initialized = true;
} else { } else {
if (args[0]->IsString()) { if (args[0]->IsString()) {
char* buf; char* buf;
@ -3521,16 +3520,15 @@ class DiffieHellman : public ObjectWrap {
return ThrowException(Exception::Error( return ThrowException(Exception::Error(
String::New("Invalid argument"))); String::New("Invalid argument")));
} else { } else {
diffieHellman->Init(reinterpret_cast<unsigned char*>(buf), len); initialized = diffieHellman->Init(
reinterpret_cast<unsigned char*>(buf), len);
delete[] buf; delete[] buf;
initialized = true;
} }
} else if (Buffer::HasInstance(args[0])) { } else if (Buffer::HasInstance(args[0])) {
Local<Object> buffer = args[0]->ToObject(); Local<Object> buffer = args[0]->ToObject();
diffieHellman->Init( initialized = diffieHellman->Init(
reinterpret_cast<unsigned char*>(Buffer::Data(buffer)), reinterpret_cast<unsigned char*>(Buffer::Data(buffer)),
Buffer::Length(buffer)); Buffer::Length(buffer));
initialized = true;
} }
} }
} }

8
test/simple/test-crypto.js

@ -380,6 +380,14 @@ var secret3 = dh3.computeSecret(key2, 'hex', 'base64');
assert.equal(secret1, secret3); 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 // Test RSA key signing/verification
var rsaSign = crypto.createSign('RSA-SHA1'); var rsaSign = crypto.createSign('RSA-SHA1');

Loading…
Cancel
Save