From: Fedor Indutny Date: Sun, 26 Jan 2014 16:09:14 +0000 (+0400) Subject: crypto: throw on SignFinal failure X-Git-Tag: v0.10.26~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4c4e0bbaa19616f41857e20c2dc2824c780baf4;p=platform%2Fupstream%2Fnodejs.git crypto: throw on SignFinal failure fix #6963 --- diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 87025dd..d9eda59 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 abb767f..96a269f 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/);