commit 0c038ee: [Fix] Fix output of non-RSA DKIM keys

Vsevolod Stakhov vsevolod at rspamd.com
Fri Aug 11 13:35:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-08-11 14:33:33 +0100
URL: https://github.com/rspamd/rspamd/commit/0c038ee69711a6d01fcc29bd2abbc24a962f12da (HEAD -> master)

[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)


More information about the Commits mailing list