[openssl] master update

dev at ddvo.net dev at ddvo.net
Fri Oct 22 05:29:52 UTC 2021


The branch master has been updated
       via  251e941283f554f0dc4b315e3a8fb82ef5b71982 (commit)
      from  d92c696d82b55552da62d6fb71942645315e307a (commit)


- Log -----------------------------------------------------------------
commit 251e941283f554f0dc4b315e3a8fb82ef5b71982
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Wed Oct 20 12:44:51 2021 +0200

    APPS/req.c: Make -reqexts option an alias of -extensions option
    
    This simplifies code, doc, and use.
    Fixes issue ignoring one or the other.
    
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/16865)

-----------------------------------------------------------------------

Summary of changes:
 apps/req.c                  | 83 ++++++++++++++++-----------------------------
 doc/man1/openssl-req.pod.in | 30 ++++++++--------
 2 files changed, 46 insertions(+), 67 deletions(-)

diff --git a/apps/req.c b/apps/req.c
index aac972e29b..84ea9baeff 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -89,8 +89,8 @@ typedef enum OPTION_choice {
     OPT_NAMEOPT, OPT_REQOPT, OPT_SUBJ, OPT_SUBJECT, OPT_TEXT, OPT_X509,
     OPT_CA, OPT_CAKEY,
     OPT_MULTIVALUE_RDN, OPT_DAYS, OPT_SET_SERIAL,
-    OPT_COPY_EXTENSIONS, OPT_ADDEXT, OPT_EXTENSIONS,
-    OPT_REQEXTS, OPT_PRECERT, OPT_MD,
+    OPT_COPY_EXTENSIONS, OPT_EXTENSIONS, OPT_REQEXTS, OPT_ADDEXT,
+    OPT_PRECERT, OPT_MD,
     OPT_SECTION,
     OPT_R_ENUM, OPT_PROV_ENUM
 } OPTION_CHOICE;
@@ -130,12 +130,11 @@ const OPTIONS req_options[] = {
     {"set_serial", OPT_SET_SERIAL, 's', "Serial number to use"},
     {"copy_extensions", OPT_COPY_EXTENSIONS, 's',
      "copy extensions from request when using -x509"},
+    {"extensions", OPT_EXTENSIONS, 's',
+     "Cert or request extension section (override value in config file)"},
+    {"reqexts", OPT_REQEXTS, 's', "An alias for -extensions"},
     {"addext", OPT_ADDEXT, 's',
      "Additional cert extension key=value pair (may be given more than once)"},
-    {"extensions", OPT_EXTENSIONS, 's',
-     "Cert extension section (override value in config file)"},
-    {"reqexts", OPT_REQEXTS, 's',
-     "Request extension section (override value in config file)"},
     {"precert", OPT_PRECERT, '-', "Add a poison extension to generated cert (implies -new)"},
 
     OPT_SECTION("Keys and Signing"),
@@ -245,13 +244,13 @@ int req_main(int argc, char **argv)
     EVP_MD *md = NULL;
     int ext_copy = EXT_COPY_UNSET;
     BIO *addext_bio = NULL;
-    char *extensions = NULL;
+    char *extsect = NULL;
     const char *infile = NULL, *CAfile = NULL, *CAkeyfile = NULL;
     char *outfile = NULL, *keyfile = NULL, *digest = NULL;
     char *keyalgstr = NULL, *p, *prog, *passargin = NULL, *passargout = NULL;
     char *passin = NULL, *passout = NULL;
     char *nofree_passin = NULL, *nofree_passout = NULL;
-    char *req_exts = NULL, *subj = NULL;
+    char *subj = NULL;
     X509_NAME *fsubj = NULL;
     char *template = default_config_file, *keyout = NULL;
     const char *keyalg = NULL;
@@ -444,6 +443,10 @@ int req_main(int argc, char **argv)
                 goto end;
             }
             break;
+        case OPT_EXTENSIONS:
+        case OPT_REQEXTS:
+            extsect = opt_arg();
+            break;
         case OPT_ADDEXT:
             p = opt_arg();
             if (addexts == NULL) {
@@ -454,18 +457,12 @@ int req_main(int argc, char **argv)
             }
             i = duplicated(addexts, p);
             if (i == 1) {
-                BIO_printf(bio_err, "Duplicate extension: %s\n", p);
+                BIO_printf(bio_err, "Duplicate extension name: %s\n", p);
                 goto opthelp;
             }
             if (i < 0 || BIO_printf(addext_bio, "%s\n", p) < 0)
                 goto end;
             break;
-        case OPT_EXTENSIONS:
-            extensions = opt_arg();
-            break;
-        case OPT_REQEXTS:
-            req_exts = opt_arg();
-            break;
         case OPT_PRECERT:
             newreq = precert = 1;
             break;
@@ -550,21 +547,22 @@ int req_main(int argc, char **argv)
             digest = p;
     }
 
-    if (extensions == NULL) {
-        extensions = NCONF_get_string(req_conf, section, V3_EXTENSIONS);
-        if (extensions == NULL)
+    if (extsect == NULL) {
+        extsect = NCONF_get_string(req_conf, section,
+                                   gen_x509 ? V3_EXTENSIONS : REQ_EXTENSIONS);
+        if (extsect == NULL)
             ERR_clear_error();
     }
-    if (extensions != NULL) {
-        /* Check syntax of file */
+    if (extsect != NULL) {
+        /* Check syntax of extension section in config file */
         X509V3_CTX ctx;
 
         X509V3_set_ctx_test(&ctx);
         X509V3_set_nconf(&ctx, req_conf);
-        if (!X509V3_EXT_add_nconf(req_conf, &ctx, extensions, NULL)) {
+        if (!X509V3_EXT_add_nconf(req_conf, &ctx, extsect, NULL)) {
             BIO_printf(bio_err,
-                       "Error checking x509 extension section %s\n",
-                       extensions);
+                       "Error checking %s extension section %s\n",
+                       gen_x509 ? "x509" : "request", extsect);
             goto end;
         }
     }
@@ -611,25 +609,6 @@ int req_main(int argc, char **argv)
             chtype = MBSTRING_UTF8;
     }
 
-    if (req_exts == NULL) {
-        req_exts = NCONF_get_string(req_conf, section, REQ_EXTENSIONS);
-        if (req_exts == NULL)
-            ERR_clear_error();
-    }
-    if (req_exts != NULL) {
-        /* Check syntax of file */
-        X509V3_CTX ctx;
-
-        X509V3_set_ctx_test(&ctx);
-        X509V3_set_nconf(&ctx, req_conf);
-        if (!X509V3_EXT_add_nconf(req_conf, &ctx, req_exts, NULL)) {
-            BIO_printf(bio_err,
-                       "Error checking request extension section %s\n",
-                       req_exts);
-            goto end;
-        }
-    }
-
     if (keyfile != NULL) {
         pkey = load_key(keyfile, keyform, 0, passin, e, "private key");
         if (pkey == NULL)
@@ -868,17 +847,16 @@ int req_main(int argc, char **argv)
             X509V3_set_nconf(&ext_ctx, req_conf);
 
             /* Add extensions */
-            if (extensions != NULL
-                    && !X509V3_EXT_add_nconf(req_conf, &ext_ctx, extensions,
-                                             new_x509)) {
+            if (extsect != NULL
+                && !X509V3_EXT_add_nconf(req_conf, &ext_ctx, extsect, new_x509)) {
                 BIO_printf(bio_err, "Error adding x509 extensions from section %s\n",
-                           extensions);
+                           extsect);
                 goto end;
             }
             if (addext_conf != NULL
                 && !X509V3_EXT_add_nconf(addext_conf, &ext_ctx, "default",
                                          new_x509)) {
-                BIO_printf(bio_err, "Error adding extensions defined via -addext\n");
+                BIO_printf(bio_err, "Error adding x509 extensions defined via -addext\n");
                 goto end;
             }
 
@@ -902,21 +880,20 @@ int req_main(int argc, char **argv)
                            "Warning: Ignoring -precert flag since no cert is produced\n");
             }
             /* Set up V3 context struct */
-            X509V3_set_ctx(&ext_ctx, NULL, NULL, req, NULL, 0);
+            X509V3_set_ctx(&ext_ctx, NULL, NULL, req, NULL, X509V3_CTX_REPLACE);
             X509V3_set_nconf(&ext_ctx, req_conf);
 
             /* Add extensions */
-            if (req_exts != NULL
-                && !X509V3_EXT_REQ_add_nconf(req_conf, &ext_ctx,
-                                             req_exts, req)) {
+            if (extsect != NULL
+                && !X509V3_EXT_REQ_add_nconf(req_conf, &ext_ctx, extsect, req)) {
                 BIO_printf(bio_err, "Error adding request extensions from section %s\n",
-                           req_exts);
+                           extsect);
                 goto end;
             }
             if (addext_conf != NULL
                 && !X509V3_EXT_REQ_add_nconf(addext_conf, &ext_ctx, "default",
                                              req)) {
-                BIO_printf(bio_err, "Error adding extensions defined via -addext\n");
+                BIO_printf(bio_err, "Error adding request extensions defined via -addext\n");
                 goto end;
             }
             i = do_X509_REQ_sign(req, pkey, digest, sigopts);
diff --git a/doc/man1/openssl-req.pod.in b/doc/man1/openssl-req.pod.in
index a21c30ba47..fcb533a29e 100644
--- a/doc/man1/openssl-req.pod.in
+++ b/doc/man1/openssl-req.pod.in
@@ -39,9 +39,9 @@ B<openssl> B<req>
 [B<-set_serial> I<n>]
 [B<-newhdr>]
 [B<-copy_extensions> I<arg>]
-[B<-addext> I<ext>]
 [B<-extensions> I<section>]
 [B<-reqexts> I<section>]
+[B<-addext> I<ext>]
 [B<-precert>]
 [B<-utf8>]
 [B<-reqopt>]
@@ -161,7 +161,7 @@ This option is used to generate a new private key unless B<-key> is given.
 It is subsequently used as if it was given using the B<-key> option.
 
 This option implies the B<-new> flag to create a new certificate request
-or a new certificate in case B<-x509> is given.
+or a new certificate in case B<-x509> is used.
 
 The argument takes one of several forms.
 
@@ -290,8 +290,9 @@ a large random number will be used for the serial number.
 Unless the B<-copy_extensions> option is used,
 X.509 extensions are not copied from any provided request input file.
 
-X.509 extensions to be added can be specified in the configuration file
-or using the B<-addext> option.
+X.509 extensions to be added can be specified in the configuration file,
+possibly using the B<-config> and B<-extensions> options,
+and/or using the B<-addext> option.
 
 =item B<-CA> I<filename>|I<uri>
 
@@ -330,6 +331,15 @@ all extensions in the request are copied to the certificate.
 The main use of this option is to allow a certificate request to supply
 values for certain extensions such as subjectAltName.
 
+=item B<-extensions> I<section>,
+B<-reqexts> I<section>
+
+Can be used to override the name of the configuration file section
+from which X.509 extensions are included
+in the certificate (when B<-x509> is in use) or certificate request.
+This allows several different sections to be used in the same configuration
+file to specify requests for a variety of purposes.
+
 =item B<-addext> I<ext>
 
 Add a specific extension to the certificate (if B<-x509> is in use)
@@ -338,16 +348,6 @@ a key=value pair as it would appear in a config file.
 
 This option can be given multiple times.
 
-=item B<-extensions> I<section>
-
-=item B<-reqexts> I<section>
-
-These options specify alternative sections to include certificate
-extensions (if B<-x509> is in use) or certificate request extensions.
-This allows several different sections to
-be used in the same configuration file to specify requests for
-a variety of purposes.
-
 =item B<-precert>
 
 A poison extension will be added to the certificate, making it a
@@ -763,6 +763,8 @@ has no effect.
 The B<-engine> option was deprecated in OpenSSL 3.0.
 The <-nodes> option was deprecated in OpenSSL 3.0, too; use B<-noenc> instead.
 
+The B<-reqexts> option has been made an alias of B<-extensions> in OpenSSL 3.1.
+
 =head1 COPYRIGHT
 
 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.


More information about the openssl-commits mailing list