From 387c238d734e085ce13b33b0ebdc0714c27cd7c0 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Fri, 29 Sep 2023 12:24:05 +0200 Subject: [PATCH] Close #459: pass private key password The password provided on the command line will be used as automatic input of the first password dialog. The database will be opened without requiring a password. This results in the following bevavior: - crl-gen works with: o database password o private password o PIN - keygen works with database password --- lib/PwDialogCore.cpp | 6 ++++++ lib/PwDialogCore.h | 1 + lib/main.cpp | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/PwDialogCore.cpp b/lib/PwDialogCore.cpp index e0722d68..8c96b984 100644 --- a/lib/PwDialogCore.cpp +++ b/lib/PwDialogCore.cpp @@ -15,10 +15,16 @@ #include PwDialogUI_i *PwDialogCore::pwdialog; +Passwd PwDialogCore::cmdline_passwd; enum open_result PwDialogCore::execute(pass_info *p, Passwd *passwd, bool write, bool abort) { + if (!cmdline_passwd.isEmpty()) { + *passwd = cmdline_passwd; + cmdline_passwd.cleanse(); + return pw_ok; + } if (pwdialog) return pwdialog->execute(p, passwd, write, abort); #if !defined(Q_OS_WIN32) diff --git a/lib/PwDialogCore.h b/lib/PwDialogCore.h index 875e1294..49fb2a06 100644 --- a/lib/PwDialogCore.h +++ b/lib/PwDialogCore.h @@ -26,6 +26,7 @@ class PwDialogCore static PwDialogUI_i *pwdialog; public: + static Passwd cmdline_passwd; static enum open_result execute(pass_info *p, Passwd *passwd, bool write = false, bool abort = false); static int pwCallback(char *buf, int size, int rwflag, void *userdata); diff --git a/lib/main.cpp b/lib/main.cpp index ed7e8569..4ec8a234 100644 --- a/lib/main.cpp +++ b/lib/main.cpp @@ -25,6 +25,7 @@ #include "pki_base.h" #include "arguments.h" #include "pki_export.h" +#include "PwDialogCore.h" #include "db_x509.h" #if defined(Q_OS_WIN32) //For the segfault handler @@ -292,14 +293,14 @@ static pki_multi *cmdline_items; static void read_cmdline(int argc, char *argv[], bool console_only) { arguments cmd_opts(argc, argv); - pki_evp::passwd = acquire_password(cmd_opts["password"]); + PwDialogCore::cmdline_passwd = acquire_password(cmd_opts["password"]); Passwd sqlpw = acquire_password(cmd_opts["sqlpass"]); if (cmd_opts.has("verbose")) { QString all = cmd_opts["verbose"]; debug_info::set_debug(all.isEmpty() ? QString("all") : all); } - if (!cmd_opts.has("password") && console_only) + if (console_only) database_model::open_without_password = true; if (cmd_opts.has("database"))