Skip to content

Commit

Permalink
Close #401: Write PEM data to a file especially for crlgen
Browse files Browse the repository at this point in the history
The new option --pem-file=<filename> behaves like --pem, just that it
writes the PEM data (and nothing else) to the given file name
  • Loading branch information
chris2511 committed Aug 30, 2024
1 parent e1fbba9 commit 6777f7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const QList<arg_option> arguments::opts = {
"Database password for unlocking the database. See below for password format options."),
arg_option("pem", NULL, no_argument, true, false,
"Print PEM representation of provided files. Prints only the public part of private keys."),
arg_option("pem-file", NULL, file_argument, true, false,
"Specify a file name for the PEM data. Implies '--pem'."),
arg_option("print", NULL, no_argument, true, false,
"Print a synopsis of provided files."),
arg_option("select", "id-list", required_argument, true, true,
Expand Down
18 changes: 16 additions & 2 deletions lib/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ int read_cmdline(int argc, char *argv[], bool console_only,
}
}

BioByteArray bba;
BioByteArray bba, bbafile;
foreach(pki_base *pki, cmdline_items->get()) {
QString filename = pki->getFilename();
if ((cmd_opts.has("text") || cmd_opts.has("print")) &&
Expand All @@ -255,11 +255,25 @@ int read_cmdline(int argc, char *argv[], bool console_only,
pki->print(bba, pki_base::print_coloured);
if (cmd_opts.has("text"))
pki->print(bba, pki_base::print_openssl_txt);
if (cmd_opts.has("pem"))
if (cmd_opts.has("pem-file"))
pki->print(bbafile, pki_base::print_pem);
else if (cmd_opts.has("pem"))
pki->print(bba, pki_base::print_pem);
}
if (bba.size() > 0)
console_write(stdout, bba);

if (bbafile.size() > 0)
{
QString filename = cmd_opts["pem-file"];
XFile f(filename);
if (f.open_write())
f.write(bbafile);
else
XCA_ERROR(QObject::tr("Failed to write PEM data to '%1'")
.arg(filename));
f.close();
}
if (cmd_opts.has("import")) {
Database.insert(cmdline_items);
*_cmdline_items = nullptr;
Expand Down

0 comments on commit 6777f7c

Please sign in to comment.