From 6b38d7dc1bccc708279ca5091ebc28cd4bdf225d Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Mon, 2 Aug 2021 17:00:51 +0200 Subject: [PATCH] If we have passed the private key, don't copy it implicitly Fixes #16197 Reviewed-by: David von Oheimb Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/16199) --- apps/req.c | 2 +- doc/man1/openssl-req.pod.in | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/req.c b/apps/req.c index eb286f8a8e..5524092f2c 100644 --- a/apps/req.c +++ b/apps/req.c @@ -686,7 +686,7 @@ int req_main(int argc, char **argv) EVP_PKEY_CTX_free(genctx); genctx = NULL; } - if (keyout == NULL) { + if (keyout == NULL && keyfile == NULL) { keyout = NCONF_get_string(req_conf, section, KEYFILE); if (keyout == NULL) ERR_clear_error(); diff --git a/doc/man1/openssl-req.pod.in b/doc/man1/openssl-req.pod.in index 7897610818..75d0da1743 100644 --- a/doc/man1/openssl-req.pod.in +++ b/doc/man1/openssl-req.pod.in @@ -205,11 +205,12 @@ See L for details. =item B<-keyout> I This gives the filename to write any private key to that has been newly created -or read from B<-key>. -If the B<-keyout> option is not given the filename specified in the -configuration file with the B option is used, if present. -If a new key is generated and no filename is specified -the key is written to standard output. +or read from B<-key>. If neither the B<-keyout> option nor the B<-key> option +are given then the filename specified in the configuration file with the +B option is used, if present. Thus, if you want to write the +private key and the B<-key> option is provided, you should provide the +B<-keyout> option explicitly. If a new key is generated and no filename is +specified the key is written to standard output. =item B<-noenc>