From 0c038ee69711a6d01fcc29bd2abbc24a962f12da Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 11 Aug 2023 14:33:33 +0100 Subject: [PATCH] [Fix] Fix output of non-RSA DKIM keys Issue: #4570 --- lualib/rspamadm/dkim_keygen.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lualib/rspamadm/dkim_keygen.lua b/lualib/rspamadm/dkim_keygen.lua index 3d51903dc..211094dfc 100644 --- a/lualib/rspamadm/dkim_keygen.lua +++ b/lualib/rspamadm/dkim_keygen.lua @@ -104,14 +104,14 @@ local function print_public_key_dns(opts, base64_pk) end -local function print_public_key(opts, pk) +local function print_public_key(opts, pk, need_base64) local key_type = opts.type == 'rsa' and 'rsa' or 'ed25519' - local base64_pk = tostring(rspamd_util.encode_base64(pk)) + local base64_pk = need_base64 and tostring(rspamd_util.encode_base64(pk)) or tostring(pk) if opts.output == 'plain' then io.write(base64_pk) io.write("\n") elseif opts.output == 'dns' then - print_public_key_dns(opts, base64_pk) + print_public_key_dns(opts, base64_pk, false) elseif opts.output == 'dnskey' then io.write(string.format('v=DKIM1; k=%s; p=%s\n', key_type, base64_pk)) end @@ -130,7 +130,8 @@ local function gen_rsa_key(opts) sk:save("-", opts.priv_output) end - print_public_key(opts, tostring(pk)) + -- We generate key directly via lua_rsa and it returns unencoded raw data + print_public_key(opts, tostring(pk), true) end local function gen_eddsa_key(opts) @@ -149,7 +150,8 @@ local function gen_eddsa_key(opts) io.flush() end - print_public_key(opts, tostring(pk)) + -- gen_dkim_keypair function returns everything encoded in base64, so no need to do anything + print_public_key(opts, tostring(pk), false) end local function handler(args) -- 2.39.5