summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2014-01-26 20:09:14 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2014-01-26 22:24:57 +0400
commitb4c4e0bbaa19616f41857e20c2dc2824c780baf4 (patch)
tree6b764ba2c94d8eeb303f87a8485d8ee043b5a62e
parent00efcb4cd7609dcefad8acba915d850480436457 (diff)
downloadnode-new-b4c4e0bbaa19616f41857e20c2dc2824c780baf4.tar.gz
crypto: throw on SignFinal failure
fix #6963
-rw-r--r--src/node_crypto.cc13
-rw-r--r--test/simple/test-crypto.js13
2 files changed, 24 insertions, 2 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 87025dd6b7..d9eda59b8d 100644
--- a/src/node_crypto.cc
+++ b/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;
diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js
index abb767f762..96a269f4d0 100644
--- a/test/simple/test-crypto.js
+++ b/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/);