Browse Source

Cleanup crypto verify to not print unnecessary errors

v0.7.4-release
Mark Cavage 14 years ago
committed by Ryan Dahl
parent
commit
7c51275bce
  1. 14
      src/node_crypto.cc

14
src/node_crypto.cc

@ -42,10 +42,8 @@
return ThrowException(Exception::TypeError(String::New("Not a string or buffer"))); \ return ThrowException(Exception::TypeError(String::New("Not a string or buffer"))); \
} }
static const char *RSA_PUB_KEY_PFX = "-----BEGIN RSA PUBLIC KEY-----"; static const char *PUBLIC_KEY_PFX = "-----BEGIN PUBLIC KEY-----";
static const char *DSA_PUB_KEY_PFX = "-----BEGIN PUBLIC KEY-----"; static const int PUBLIC_KEY_PFX_LEN = strlen(PUBLIC_KEY_PFX);
static const int RSA_PUB_KEY_PFX_LEN = strlen(RSA_PUB_KEY_PFX);
static const int DSA_PUB_KEY_PFX_LEN = strlen(DSA_PUB_KEY_PFX);
namespace node { namespace node {
namespace crypto { namespace crypto {
@ -2776,10 +2774,8 @@ class Verify : public ObjectWrap {
return 0; return 0;
} }
// Check if this is an RSA or DSA "raw" public key before trying // Check if this is a PKCS#8 public key before trying as X.509
// X.509 if (strncmp(key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0) {
if (strncmp(key_pem, RSA_PUB_KEY_PFX, RSA_PUB_KEY_PFX_LEN) == 0 ||
strncmp(key_pem, DSA_PUB_KEY_PFX, DSA_PUB_KEY_PFX_LEN) == 0) {
pkey = PEM_read_bio_PUBKEY(bp, NULL, NULL, NULL); pkey = PEM_read_bio_PUBKEY(bp, NULL, NULL, NULL);
if (pkey == NULL) { if (pkey == NULL) {
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
@ -2801,8 +2797,6 @@ class Verify : public ObjectWrap {
} }
r = EVP_VerifyFinal(&mdctx, sig, siglen, pkey); r = EVP_VerifyFinal(&mdctx, sig, siglen, pkey);
if (r != 1)
ERR_print_errors_fp (stderr);
if(pkey != NULL) if(pkey != NULL)
EVP_PKEY_free (pkey); EVP_PKEY_free (pkey);

Loading…
Cancel
Save