diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-04-07 16:38:50 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-04-07 16:39:22 +0100 |
commit | a070e5a10a3084bf75472177bedfacc612c25071 (patch) | |
tree | 347823c471e0fd3ae2c88c9d0b5ded83a3cd3212 /src/lua | |
parent | 58bd6be3f7f9302e51ae4031658311f9cc9842d8 (diff) | |
download | rspamd-a070e5a10a3084bf75472177bedfacc612c25071.tar.gz rspamd-a070e5a10a3084bf75472177bedfacc612c25071.zip |
[Feature] Finish all features of dkim_keygen in Lua
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_cryptobox.c | 33 | ||||
-rw-r--r-- | src/lua/lua_text.c | 4 |
2 files changed, 35 insertions, 2 deletions
diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index e342610ce..2a7b0c202 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -2700,6 +2700,39 @@ lua_cryptobox_gen_dkim_keypair (lua_State *L) rspamd_explicit_memzero (pk, sizeof (pk)); rspamd_explicit_memzero (sk, sizeof (sk)); } + else if (strcmp (alg_str, "ed25519-seed") == 0) { + rspamd_sig_pk_t pk; + rspamd_sig_sk_t sk; + gchar *b64_data; + gsize b64_len; + + rspamd_cryptobox_keypair_sig (pk, sk, RSPAMD_CRYPTOBOX_MODE_25519); + + /* Process private key */ + b64_data = rspamd_encode_base64 (sk, + 32, + -1, &b64_len); + + priv_out = lua_newuserdata (L, sizeof (*priv_out)); + rspamd_lua_setclass (L, "rspamd{text}", -1); + priv_out->start = b64_data; + priv_out->len = b64_len; + priv_out->flags = RSPAMD_TEXT_FLAG_OWN|RSPAMD_TEXT_FLAG_WIPE; + + /* Process public key */ + b64_data = rspamd_encode_base64 (pk, + rspamd_cryptobox_pk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519), + -1, &b64_len); + + pub_out = lua_newuserdata (L, sizeof (*pub_out)); + rspamd_lua_setclass (L, "rspamd{text}", -1); + pub_out->start = b64_data; + pub_out->len = b64_len; + pub_out->flags = RSPAMD_TEXT_FLAG_OWN; + + rspamd_explicit_memzero (pk, sizeof (pk)); + rspamd_explicit_memzero (sk, sizeof (sk)); + } else { return luaL_error (L, "invalid algorithm %s", alg_str); } diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c index b6f0948c3..bafab3c08 100644 --- a/src/lua/lua_text.c +++ b/src/lua/lua_text.c @@ -1118,12 +1118,12 @@ lua_text_save_in_file (lua_State *L) fname = luaL_checkstring (L, 2); if (lua_type (L, 3) == LUA_TNUMBER) { - mode = lua_tonumber (L, 3); + mode = lua_tointeger(L, 3); } } else if (lua_type (L, 2) == LUA_TNUMBER) { /* Created fd */ - fd = lua_tonumber (L, 2); + fd = lua_tointeger (L, 2); } if (fd == -1) { |