From e39be9b4e9216b31a52be0b2757b465d6561c623 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Sat, 23 Sep 2023 21:06:31 +0200 Subject: [PATCH] Close #423: parameter --name is not respected when running with CLI Evaluate --name argument when generating the CRL. Add --import-names option. This allows to name the imported items individually, even if one PEM file contains multiple items. --- lib/arguments.cpp | 2 ++ lib/db_crl.cpp | 6 ++++-- lib/db_crl.h | 2 +- lib/main.cpp | 10 +++++++++- lib/pki_multi.cpp | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/arguments.cpp b/lib/arguments.cpp index 45bc0289..df28c89c 100644 --- a/lib/arguments.cpp +++ b/lib/arguments.cpp @@ -34,6 +34,8 @@ const QList arguments::opts = { "Save OpenSSL index in ."), arg_option("import", NULL, no_argument, false, true, "Import all provided items into the database."), + arg_option("import-names", NULL, required_argument, false, true, + "A semicolon separated list of names applied to the imported items in the order found in the PEM file and on the commandline."), arg_option("issuers", NULL, no_argument, true, true, "Print all known issuer certificates that have an associated private key and the CA basic constraints set to 'true'."), arg_option("keygen", "type", required_argument, true, true, diff --git a/lib/db_crl.cpp b/lib/db_crl.cpp index bbc5a1e8..6b34bf1a 100644 --- a/lib/db_crl.cpp +++ b/lib/db_crl.cpp @@ -125,7 +125,7 @@ void db_crl::exportItems(const QModelIndexList &indexes, writeVcalendar(file, vcal); } -pki_crl *db_crl::newCrl(const crljob &task) +pki_crl *db_crl::newCrl(const crljob &task, QString name) { pki_crl *crl = NULL; pki_x509 *cert = task.issuer; @@ -137,8 +137,10 @@ pki_crl *db_crl::newCrl(const crljob &task) X509V3_set_ctx_nodb(&ext_ctx); XSqlQuery q; + if (name.isEmpty()) + name = cert->getIntName(); crl = new pki_crl(); - crl->createCrl(cert->getIntName(), cert); + crl->createCrl(name, cert); crl->pkiSource = generated; foreach(x509rev rev, cert->getRevList()) diff --git a/lib/db_crl.h b/lib/db_crl.h index 6b74b98a..c47e77d4 100644 --- a/lib/db_crl.h +++ b/lib/db_crl.h @@ -24,7 +24,7 @@ class db_crl: public db_x509name pki_base *insert(pki_base *item); void removeSigner(pki_base *signer); void updateCertView(); - pki_crl *newCrl(const crljob &crljob); + pki_crl *newCrl(const crljob &crljob, QString name = QString()); void exportItems(const QModelIndexList &indexes, const pki_export *xport, XFile &file) const; }; diff --git a/lib/main.cpp b/lib/main.cpp index a504c57d..887478f1 100644 --- a/lib/main.cpp +++ b/lib/main.cpp @@ -307,6 +307,14 @@ static void read_cmdline(int argc, char *argv[], bool console_only) qDebug() << "Probe" << file; cmdline_items->probeAnything(file); } + QStringList names = cmd_opts["import-names"].split(";"); + foreach(pki_base *pki, cmdline_items->get()) { + if (names.isEmpty()) + break; + QString name = names.takeFirst(); + if (!name.isEmpty()) + pki->setIntName(name); + } if (cmdline_items->failed_files.size() > 0) { XCA_WARN(QString("Failed to import from '%1'") .arg(cmdline_items->failed_files.join("' '"))); @@ -419,7 +427,7 @@ static void read_cmdline(int argc, char *argv[], bool console_only) .arg(cmd_opts["crlgen"])); } else { crljob task(issuer); - pki_crl *crl = crls->newCrl(task); + pki_crl *crl = crls->newCrl(task, cmd_opts["name"]); if (crl) cmdline_items->append_item(crl); } diff --git a/lib/pki_multi.cpp b/lib/pki_multi.cpp index 5f6b23d6..6795351a 100644 --- a/lib/pki_multi.cpp +++ b/lib/pki_multi.cpp @@ -41,7 +41,7 @@ void pki_multi::append_item(pki_base *pki) { pki_multi *m = dynamic_cast(pki); if (m) - multi += m; + multi += m->multi; else multi << pki; }