diff options
author | Fedor Indutny <fedor@indutny.com> | 2015-01-27 22:58:14 +0300 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2015-01-28 02:02:52 +0300 |
commit | 87e62bd4c87e8674e3d1c432506e9b4991784ee2 (patch) | |
tree | aa377dab8988789ac34dd4df50a1eba7ca8dcae4 /src/node_crypto.cc | |
parent | b50fea4d490278b291321e6b96c49cf20bee1552 (diff) | |
download | node-new-87e62bd4c87e8674e3d1c432506e9b4991784ee2.tar.gz |
crypto: implement privateEncrypt/publicDecrypt
PR-URL: https://github.com/iojs/io.js/pull/625
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fix iojs/io.js#477
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index b76a1a607e..3ad4af230c 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3561,12 +3561,12 @@ bool PublicKeyCipher::Cipher(const char* key_pem, // Check if this is a PKCS#8 or RSA public key before trying as X.509 and // private key. - if (operation == kEncrypt && + if (operation == kPublic && strncmp(key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0) { pkey = PEM_read_bio_PUBKEY(bp, nullptr, nullptr, nullptr); if (pkey == nullptr) goto exit; - } else if (operation == kEncrypt && + } else if (operation == kPublic && strncmp(key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0) { RSA* rsa = PEM_read_bio_RSAPublicKey(bp, nullptr, nullptr, nullptr); if (rsa) { @@ -3577,7 +3577,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem, } if (pkey == nullptr) goto exit; - } else if (operation == kEncrypt && + } else if (operation == kPublic && strncmp(key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0) { x509 = PEM_read_bio_X509(bp, nullptr, CryptoPemCallback, nullptr); if (x509 == nullptr) @@ -5038,13 +5038,21 @@ void InitCrypto(Handle<Object> target, env->SetMethod(target, "getCiphers", GetCiphers); env->SetMethod(target, "getHashes", GetHashes); env->SetMethod(target, "publicEncrypt", - PublicKeyCipher::Cipher<PublicKeyCipher::kEncrypt, + PublicKeyCipher::Cipher<PublicKeyCipher::kPublic, EVP_PKEY_encrypt_init, EVP_PKEY_encrypt>); env->SetMethod(target, "privateDecrypt", - PublicKeyCipher::Cipher<PublicKeyCipher::kDecrypt, + PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate, EVP_PKEY_decrypt_init, EVP_PKEY_decrypt>); + env->SetMethod(target, "privateEncrypt", + PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate, + EVP_PKEY_sign_init, + EVP_PKEY_sign>); + env->SetMethod(target, "publicDecrypt", + PublicKeyCipher::Cipher<PublicKeyCipher::kPublic, + EVP_PKEY_verify_recover_init, + EVP_PKEY_verify_recover>); } } // namespace crypto |