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 /lualib/rspamadm/dkim_keygen.lua | |
parent | 58bd6be3f7f9302e51ae4031658311f9cc9842d8 (diff) | |
download | rspamd-a070e5a10a3084bf75472177bedfacc612c25071.tar.gz rspamd-a070e5a10a3084bf75472177bedfacc612c25071.zip |
[Feature] Finish all features of dkim_keygen in Lua
Diffstat (limited to 'lualib/rspamadm/dkim_keygen.lua')
-rw-r--r-- | lualib/rspamadm/dkim_keygen.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lualib/rspamadm/dkim_keygen.lua b/lualib/rspamadm/dkim_keygen.lua index a957d8fde..05be73436 100644 --- a/lualib/rspamadm/dkim_keygen.lua +++ b/lualib/rspamadm/dkim_keygen.lua @@ -16,6 +16,7 @@ limitations under the License. local argparse = require "argparse" local rspamd_util = require "rspamd_util" +local rspamd_cryptobox = require "rspamd_cryptobox" local parser = argparse() :name 'rspamadm dkim_keygen' @@ -64,6 +65,8 @@ parser:option '--priv-output' ['der'] = 'der', } :default 'pem' +parser:flag '-f --force' + :description 'Force overwrite of existing files' local function split_string(input, max_length) max_length = max_length or 253 @@ -114,6 +117,9 @@ local function gen_rsa_key(opts) local sk,pk = rsa.keypair(opts.bits or 1024) if opts.privkey then + if opts.force then + os.remove(opts.privkey) + end sk:save(opts.privkey, opts.priv_output) else sk:save("-", opts.priv_output) @@ -122,6 +128,25 @@ local function gen_rsa_key(opts) print_public_key(opts, tostring(pk)) end +local function gen_eddsa_key(opts) + local sk,pk = rspamd_cryptobox.gen_dkim_keypair(opts.type) + + if opts.privkey and opts.force then + os.remove(opts.privkey) + end + if not sk:save_in_file(opts.privkey, tonumber('0600', 8)) then + io.stderr:write('cannot save private key to ' .. (opts.privkey or 'stdout') .. '\n') + os.exit(1) + end + + if not opts.privkey then + io.write("\n") + io.flush() + end + + print_public_key(opts, tostring(pk)) +end + local function handler(args) local opts = parser:parse(args) |