mirror of
https://github.com/rspamd/rspamd.git
synced 2024-09-13 23:56:50 +02:00
[Project] Move keypair function to Lua
This commit is contained in:
parent
32270a9bd1
commit
3636465690
89
lualib/rspamadm/keypair.lua
Normal file
89
lualib/rspamadm/keypair.lua
Normal file
@ -0,0 +1,89 @@
|
||||
--[[
|
||||
Copyright (c) 2018, Vsevolod Stakhov <vsevolod@highsecure.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
]]--
|
||||
|
||||
local argparse = require "argparse"
|
||||
local rspamd_keypair = require "rspamd_cryptobox_keypair"
|
||||
local ucl = require "ucl"
|
||||
|
||||
-- Define command line options
|
||||
local parser = argparse()
|
||||
:name "rspamadm keypair"
|
||||
:description "Manages keypairs for Rspamd"
|
||||
:help_description_margin(30)
|
||||
:command_target("command")
|
||||
:require_command(false)
|
||||
|
||||
local generate = parser:command "generate gen g"
|
||||
:description "Creates a new keypair"
|
||||
generate:flag "-s --sign"
|
||||
:description "Generates a sign keypair instead of the encryption one"
|
||||
generate:flag "-n --nist"
|
||||
:description "Uses nist encryption algorithm"
|
||||
generate:mutex(
|
||||
generate:flag "-j --json"
|
||||
:description "Output JSON instead of UCL",
|
||||
generate:flag "-u --ucl"
|
||||
:description "Output UCL"
|
||||
:default(true)
|
||||
)
|
||||
|
||||
-- Default command is generate, so duplicate options
|
||||
parser:flag "-s --sign"
|
||||
:description "Generates a sign keypair instead of the encryption one"
|
||||
parser:flag "-n --nist"
|
||||
:description "Uses nist encryption algorithm"
|
||||
parser:mutex(
|
||||
parser:flag "-j --json"
|
||||
:description "Output JSON instead of UCL",
|
||||
parser:flag "-u --ucl"
|
||||
:description "Output UCL"
|
||||
:default(true)
|
||||
)
|
||||
|
||||
local function handler(args)
|
||||
local opts = parser:parse(args)
|
||||
|
||||
local command = opts.command or "generate"
|
||||
|
||||
if command == 'generate' then
|
||||
local mode = 'encryption'
|
||||
if opts.sign then
|
||||
mode = 'sign'
|
||||
end
|
||||
local alg = 'curve25519'
|
||||
if opts.nist then
|
||||
alg = 'nist'
|
||||
end
|
||||
-- TODO: probably, do it in a more safe way
|
||||
local kp = rspamd_keypair.create(mode, alg):totable()
|
||||
|
||||
local format = 'ucl'
|
||||
|
||||
if opts.json then
|
||||
format = 'json'
|
||||
end
|
||||
io.write(ucl.to_format(kp, format))
|
||||
else
|
||||
parser:error('command %s is not yet implemented', command)
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
name = 'keypair',
|
||||
aliases = {'kp', 'key'},
|
||||
handler = handler,
|
||||
description = parser._description
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
SET(RSPAMADMSRC rspamadm.c
|
||||
commands.c
|
||||
pw.c
|
||||
keypair.c
|
||||
configtest.c
|
||||
fuzzy_convert.c
|
||||
fuzzy_merge.c
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "lua/lua_common.h"
|
||||
|
||||
extern struct rspamadm_command pw_command;
|
||||
extern struct rspamadm_command keypair_command;
|
||||
extern struct rspamadm_command configtest_command;
|
||||
extern struct rspamadm_command fuzzy_merge_command;
|
||||
extern struct rspamadm_command configdump_command;
|
||||
@ -34,7 +33,6 @@ extern struct rspamadm_command dkim_keygen_command;
|
||||
const struct rspamadm_command *commands[] = {
|
||||
&help_command,
|
||||
&pw_command,
|
||||
&keypair_command,
|
||||
&configtest_command,
|
||||
&fuzzy_merge_command,
|
||||
&configdump_command,
|
||||
|
Loading…
Reference in New Issue
Block a user