Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created November 16, 2011 21:16
Show Gist options
  • Select an option

  • Save bnoordhuis/1371434 to your computer and use it in GitHub Desktop.

Select an option

Save bnoordhuis/1371434 to your computer and use it in GitHub Desktop.
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index c1e197b..cdc39de 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -54,8 +54,11 @@
return ThrowException(Exception::TypeError(String::New("Not a string or buffer"))); \
}
-static const char *PUBLIC_KEY_PFX = "-----BEGIN PUBLIC KEY-----";
-static const int PUBLIC_KEY_PFX_LEN = strlen(PUBLIC_KEY_PFX);
+static const char PUBLIC_KEY_PFX[] = "-----BEGIN PUBLIC KEY-----";
+static const int PUBLIC_KEY_PFX_LEN = sizeof(PUBLIC_KEY_PFX) - 1;
+
+static const char PUBRSA_KEY_PFX[] = "-----BEGIN RSA PUBLIC KEY-----";
+static const int PUBRSA_KEY_PFX_LEN = sizeof(PUBRSA_KEY_PFX) - 1;
static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
| ASN1_STRFLGS_ESC_MSB
@@ -3320,6 +3323,18 @@ class Verify : public ObjectWrap {
ERR_print_errors_fp(stderr);
return 0;
}
+ } else if (strncmp(key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0) {
+ RSA* rsa = PEM_read_bio_RSAPublicKey(bp, NULL, NULL, NULL);
+ if (rsa) {
+ pkey = EVP_PKEY_new();
+ if (pkey)
+ EVP_PKEY_set1_RSA(pkey, rsa);
+ RSA_free(rsa);
+ }
+ if (pkey == NULL) {
+ ERR_print_errors_fp(stderr);
+ return 0;
+ }
} else {
// X.509 fallback
x509 = PEM_read_bio_X509(bp, NULL, NULL, NULL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment