Browse Source

crypto: throw on SignFinal failure

fix #6963
v0.10.26-release
Fedor Indutny 11 years ago
parent
commit
b4c4e0bbaa
  1. 13
      src/node_crypto.cc
  2. 13
      test/simple/test-crypto.js

13
src/node_crypto.cc

@ -3005,9 +3005,15 @@ class Sign : public ObjectWrap {
if(!BIO_write(bp, key_pem, key_pemLen)) return 0;
pkey = PEM_read_bio_PrivateKey( bp, NULL, NULL, NULL );
if (pkey == NULL) return 0;
if (pkey == NULL) {
ERR_print_errors_fp(stderr);
return 0;
}
EVP_SignFinal(&mdctx, *md_value, md_len, pkey);
if (!EVP_SignFinal(&mdctx, *md_value, md_len, pkey)) {
ERR_print_errors_fp(stderr);
return 0;
}
EVP_MD_CTX_cleanup(&mdctx);
initialised_ = false;
EVP_PKEY_free(pkey);
@ -3107,8 +3113,11 @@ class Sign : public ObjectWrap {
int r = sign->SignFinal(&md_value, &md_len, buf, len);
if (r == 0) {
delete [] buf;
delete [] md_value;
md_value = NULL;
md_len = r;
return ThrowException(Exception::Error(String::New("SignFinal error")));
}
delete [] buf;

13
test/simple/test-crypto.js

@ -937,3 +937,16 @@ assert.throws(function() {
assert.throws(function() {
crypto.createVerify('RSA-SHA1').update('0', 'hex');
}, /Bad input string/);
assert.throws(function() {
var private = [
'-----BEGIN RSA PRIVATE KEY-----',
'MIGrAgEAAiEA+3z+1QNF2/unumadiwEr+C5vfhezsb3hp4jAnCNRpPcCAwEAAQIgQNriSQK4',
'EFwczDhMZp2dvbcz7OUUyt36z3S4usFPHSECEQD/41K7SujrstBfoCPzwC1xAhEA+5kt4BJy',
'eKN7LggbF3Dk5wIQN6SL+fQ5H/+7NgARsVBp0QIRANxYRukavs4QvuyNhMx+vrkCEQCbf6j/',
'Ig6/HueCK/0Jkmp+',
'-----END RSA PRIVATE KEY-----',
''
].join('\n');
crypto.createSign('RSA-SHA256').update('test').sign(private);
}, /SignFinal/);

Loading…
Cancel
Save