summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-10-20 12:44:51 +0200
committerDr. David von Oheimb <dev@ddvo.net>2021-10-22 07:29:07 +0200
commit251e941283f554f0dc4b315e3a8fb82ef5b71982 (patch)
treea9353ac0b4c4f7d40951613fdec76dc060614499 /apps
parentd92c696d82b55552da62d6fb71942645315e307a (diff)
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@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16865)
Diffstat (limited to 'apps')
-rw-r--r--apps/req.c83
1 files changed, 30 insertions, 53 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);