Subject: | Can't load encrypted private keys |
I'd like to be able to load encrypted private keys using this module.
I've implmented at least one way to do this, and the patch is attached.
Is it possible for this to get into the released module?
Thanks
--hachi
Subject: | Crypt-OpenSSL-RSA-0.25-encrypted-private-keys.diff |
diff --exclude=.git -u Crypt-OpenSSL-RSA-0.25/RSA.xs Crypt-OpenSSL-RSA-0.25-hachi/RSA.xs
--- Crypt-OpenSSL-RSA-0.25/RSA.xs 2006-11-13 04:24:28.000000000 -0800
+++ Crypt-OpenSSL-RSA-0.25-hachi/RSA.xs 2009-06-29 15:29:11.000000000 -0700
@@ -157,20 +157,30 @@
return sv;
}
-RSA* _load_rsa_key(SV* p_keyStringSv,
+RSA* _load_rsa_key(SV* p_keyStringSv, SV* p_passwordStringSv,
RSA*(*p_loader)(BIO*, RSA**, pem_password_cb*, void*))
{
STRLEN keyStringLength;
char* keyString;
+ char* passwordString;
RSA* rsa;
BIO* stringBIO;
keyString = SvPV(p_keyStringSv, keyStringLength);
+ if (p_passwordStringSv == &PL_sv_undef)
+ passwordString = NULL;
+ else {
+ OpenSSL_add_all_algorithms();
+ PKCS5_PBE_add();
+
+ passwordString = SvPV_nolen(p_passwordStringSv);
+ }
+
CHECK_OPEN_SSL(stringBIO = BIO_new_mem_buf(keyString, keyStringLength));
- rsa = p_loader(stringBIO, NULL, NULL, NULL);
+ rsa = p_loader(stringBIO, NULL, NULL, passwordString);
CHECK_OPEN_SSL(BIO_set_close(stringBIO, BIO_CLOSE) == 1);
BIO_free(stringBIO);
@@ -219,7 +229,18 @@
SV* key_string_SV;
CODE:
RETVAL = make_rsa_obj(
- proto, _load_rsa_key(key_string_SV, PEM_read_bio_RSAPrivateKey));
+ proto, _load_rsa_key(key_string_SV, &PL_sv_undef, PEM_read_bio_RSAPrivateKey));
+ OUTPUT:
+ RETVAL
+
+SV*
+new_private_key_with_password(proto, key_string_SV, password_string_SV)
+ SV* proto;
+ SV* key_string_SV;
+ SV* password_string_SV;
+ CODE:
+ RETVAL = make_rsa_obj(
+ proto, _load_rsa_key(key_string_SV, password_string_SV, PEM_read_bio_RSAPrivateKey));
OUTPUT:
RETVAL
@@ -229,7 +250,7 @@
SV* key_string_SV;
CODE:
RETVAL = make_rsa_obj(
- proto, _load_rsa_key(key_string_SV, PEM_read_bio_RSAPublicKey));
+ proto, _load_rsa_key(key_string_SV, &PL_sv_undef, PEM_read_bio_RSAPublicKey));
OUTPUT:
RETVAL
@@ -239,7 +260,7 @@
SV* key_string_SV;
CODE:
RETVAL = make_rsa_obj(
- proto, _load_rsa_key(key_string_SV, PEM_read_bio_RSA_PUBKEY));
+ proto, _load_rsa_key(key_string_SV, &PL_sv_undef, PEM_read_bio_RSA_PUBKEY));
OUTPUT:
RETVAL