diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-24 13:37:52 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-24 13:38:10 +0100 |
commit | 41a84bc6248297a8a66f70a0991ba418b591fe07 (patch) | |
tree | efc4e544ce60fa91b0f2ee703d8dd05cd6f8686c /src/lua/lua_rsa.c | |
parent | 4a5ee1bfcd32ccf8fa22683c2e011c6b8429a6cd (diff) | |
download | rspamd-41a84bc6248297a8a66f70a0991ba418b591fe07.tar.gz rspamd-41a84bc6248297a8a66f70a0991ba418b591fe07.zip |
[Minor] Another try to load RSA key from base64
Diffstat (limited to 'src/lua/lua_rsa.c')
-rw-r--r-- | src/lua/lua_rsa.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c index 50702199b..17675e548 100644 --- a/src/lua/lua_rsa.c +++ b/src/lua/lua_rsa.c @@ -328,6 +328,7 @@ lua_rsa_privkey_load_base64 (lua_State *L) { RSA *rsa = NULL, **prsa; BIO *b; + EVP_PKEY *evp = NULL; struct rspamd_lua_text *t; const gchar *data; guchar *decoded; @@ -357,17 +358,27 @@ lua_rsa_privkey_load_base64 (lua_State *L) } b = BIO_new_mem_buf (decoded, dec_len); - rsa = d2i_RSAPrivateKey_bio (b, NULL); - if (rsa == NULL) { - msg_err ("cannot open private key from data, %s", - ERR_error_string (ERR_get_error (), NULL)); - lua_pushnil (L); + if (d2i_PrivateKey_bio (b, &evp) != NULL) { + rsa = EVP_PKEY_get1_RSA (evp); + + if (rsa == NULL) { + msg_err ("cannot open RSA private key from data, %s", + ERR_error_string (ERR_get_error (), NULL)); + lua_pushnil (L); + } + else { + prsa = lua_newuserdata (L, sizeof (RSA *)); + rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1); + *prsa = rsa; + } + + EVP_PKEY_free (evp); } else { - prsa = lua_newuserdata (L, sizeof (RSA *)); - rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1); - *prsa = rsa; + msg_err ("cannot open EVP private key from data, %s", + ERR_error_string (ERR_get_error (), NULL)); + lua_pushnil (L); } BIO_free (b); |