aboutsummaryrefslogtreecommitdiffstats
path: root/apps/req.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/req.c')
-rw-r--r--apps/req.c134
1 files changed, 73 insertions, 61 deletions
diff --git a/apps/req.c b/apps/req.c
index a47dfcffaf..34d906566c 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -371,21 +371,21 @@ int req_main(int argc, char **argv)
if (md_alg == NULL) {
p = NCONF_get_string(req_conf, SECTION, "default_md");
- if (p == NULL)
+ if (p == NULL) {
ERR_clear_error();
- else {
+ } else {
if (!opt_md(p, &md_alg))
goto opthelp;
digest = md_alg;
}
}
- if (!extensions) {
+ if (extensions == NULL) {
extensions = NCONF_get_string(req_conf, SECTION, V3_EXTENSIONS);
- if (!extensions)
+ if (extensions == NULL)
ERR_clear_error();
}
- if (extensions) {
+ if (extensions != NULL) {
/* Check syntax of file */
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
@@ -412,28 +412,28 @@ int req_main(int argc, char **argv)
}
p = NCONF_get_string(req_conf, SECTION, STRING_MASK);
- if (!p)
+ if (p == NULL)
ERR_clear_error();
- if (p && !ASN1_STRING_set_default_mask_asc(p)) {
+ if (p != NULL && !ASN1_STRING_set_default_mask_asc(p)) {
BIO_printf(bio_err, "Invalid global string mask setting %s\n", p);
goto end;
}
if (chtype != MBSTRING_UTF8) {
p = NCONF_get_string(req_conf, SECTION, UTF8_IN);
- if (!p)
+ if (p == NULL)
ERR_clear_error();
else if (strcmp(p, "yes") == 0)
chtype = MBSTRING_UTF8;
}
- if (!req_exts) {
+ if (req_exts == NULL) {
req_exts = NCONF_get_string(req_conf, SECTION, REQ_EXTENSIONS);
- if (!req_exts)
+ if (req_exts == NULL)
ERR_clear_error();
}
- if (req_exts) {
+ if (req_exts != NULL) {
/* Check syntax of file */
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
@@ -448,7 +448,7 @@ int req_main(int argc, char **argv)
if (keyfile != NULL) {
pkey = load_key(keyfile, keyform, 0, passin, e, "Private Key");
- if (!pkey) {
+ if (pkey == NULL) {
/* load_key() has already printed an appropriate message */
goto end;
} else {
@@ -464,17 +464,17 @@ int req_main(int argc, char **argv)
if (randfile == NULL)
ERR_clear_error();
app_RAND_load_file(randfile, 0);
- if (inrand)
+ if (inrand != NULL)
app_RAND_load_files(inrand);
if (!NCONF_get_number(req_conf, SECTION, BITS, &newkey)) {
newkey = DEFAULT_KEY_LENGTH;
}
- if (keyalg) {
+ if (keyalg != NULL) {
genctx = set_keygen_ctx(keyalg, &pkey_type, &newkey,
&keyalgstr, gen_eng);
- if (!genctx)
+ if (genctx == NULL)
goto end;
}
@@ -486,14 +486,14 @@ int req_main(int argc, char **argv)
goto end;
}
- if (!genctx) {
+ if (genctx == NULL) {
genctx = set_keygen_ctx(NULL, &pkey_type, &newkey,
&keyalgstr, gen_eng);
if (!genctx)
goto end;
}
- if (pkeyopts) {
+ if (pkeyopts != NULL) {
char *genopt;
for (i = 0; i < sk_OPENSSL_STRING_num(pkeyopts); i++) {
genopt = sk_OPENSSL_STRING_value(pkeyopts, i);
@@ -610,9 +610,9 @@ int req_main(int argc, char **argv)
goto end;
/* Set version to V3 */
- if (extensions && !X509_set_version(x509ss, 2))
+ if (extensions != NULL && !X509_set_version(x509ss, 2))
goto end;
- if (serial) {
+ if (serial != NULL) {
if (!X509_set_serialNumber(x509ss, serial))
goto end;
} else {
@@ -637,9 +637,9 @@ int req_main(int argc, char **argv)
X509V3_set_nconf(&ext_ctx, req_conf);
/* Add extensions */
- if (extensions && !X509V3_EXT_add_nconf(req_conf,
- &ext_ctx, extensions,
- x509ss)) {
+ if (extensions != NULL && !X509V3_EXT_add_nconf(req_conf,
+ &ext_ctx, extensions,
+ x509ss)) {
BIO_printf(bio_err, "Error Loading extension section %s\n",
extensions);
goto end;
@@ -668,9 +668,9 @@ int req_main(int argc, char **argv)
X509V3_set_nconf(&ext_ctx, req_conf);
/* Add extensions */
- if (req_exts && !X509V3_EXT_REQ_add_nconf(req_conf,
- &ext_ctx, req_exts,
- req)) {
+ if (req_exts != NULL
+ && !X509V3_EXT_REQ_add_nconf(req_conf, &ext_ctx,
+ req_exts, req)) {
BIO_printf(bio_err, "Error Loading extension section %s\n",
req_exts);
goto end;
@@ -723,8 +723,9 @@ int req_main(int argc, char **argv)
} else if (i == 0) {
BIO_printf(bio_err, "verify failure\n");
ERR_print_errors(bio_err);
- } else /* if (i > 0) */
+ } else { /* if (i > 0) */
BIO_printf(bio_err, "verify OK\n");
+ }
}
if (noout && !text && !modulus && !subject && !pubkey) {
@@ -951,7 +952,8 @@ static int prompt_info(X509_REQ *req,
if (sk_CONF_VALUE_num(dn_sk)) {
i = -1;
- start:for (;;) {
+ start:
+ for ( ; ; ) {
i++;
if (sk_CONF_VALUE_num(dn_sk) <= i)
break;
@@ -976,8 +978,9 @@ static int prompt_info(X509_REQ *req,
if (*type == '+') {
mval = -1;
type++;
- } else
+ } else {
mval = 0;
+ }
/* If OBJ not recognised ignore it */
if ((nid = OBJ_txt2nid(type)) == NID_undef)
goto start;
@@ -1030,7 +1033,8 @@ static int prompt_info(X509_REQ *req,
}
i = -1;
- start2: for (;;) {
+ start2:
+ for ( ; ; ) {
i++;
if ((attr_sk == NULL) || (sk_CONF_VALUE_num(attr_sk) <= i))
break;
@@ -1128,8 +1132,9 @@ static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *dn_sk,
if (plus_char) {
type++;
mval = -1;
- } else
+ } else {
mval = 0;
+ }
if (!X509_NAME_add_entry_by_txt(subj, type, chtype,
(unsigned char *)v->value, -1, -1,
mval))
@@ -1178,19 +1183,20 @@ static int add_DN_object(X509_NAME *n, char *text, const char *def,
}
if (buf[0] == '\0')
- return (0);
- else if (buf[0] == '\n') {
+ return 0;
+ if (buf[0] == '\n') {
if ((def == NULL) || (def[0] == '\0'))
- return (1);
+ return 1;
OPENSSL_strlcpy(buf, def, sizeof buf);
OPENSSL_strlcat(buf, "\n", sizeof buf);
- } else if ((buf[0] == '.') && (buf[1] == '\n'))
- return (1);
+ } else if ((buf[0] == '.') && (buf[1] == '\n')) {
+ return 1;
+ }
i = strlen(buf);
if (buf[i - 1] != '\n') {
BIO_printf(bio_err, "weird input :-(\n");
- return (0);
+ return 0;
}
buf[--i] = '\0';
#ifdef CHARSET_EBCDIC
@@ -1237,19 +1243,20 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def,
}
if (buf[0] == '\0')
- return (0);
- else if (buf[0] == '\n') {
+ return 0;
+ if (buf[0] == '\n') {
if ((def == NULL) || (def[0] == '\0'))
- return (1);
+ return 1;
OPENSSL_strlcpy(buf, def, sizeof buf);
OPENSSL_strlcat(buf, "\n", sizeof buf);
- } else if ((buf[0] == '.') && (buf[1] == '\n'))
- return (1);
+ } else if ((buf[0] == '.') && (buf[1] == '\n')) {
+ return 1;
+ }
i = strlen(buf);
if (buf[i - 1] != '\n') {
BIO_printf(bio_err, "weird input :-(\n");
- return (0);
+ return 0;
}
buf[--i] = '\0';
#ifdef CHARSET_EBCDIC
@@ -1320,15 +1327,15 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
*pkey_type = EVP_PKEY_RSA;
keylen = atol(gstr);
*pkeylen = keylen;
- } else if (strncmp(gstr, "param:", 6) == 0)
+ } else if (strncmp(gstr, "param:", 6) == 0) {
paramfile = gstr + 6;
- else {
+ } else {
const char *p = strchr(gstr, ':');
int len;
ENGINE *tmpeng;
const EVP_PKEY_ASN1_METHOD *ameth;
- if (p)
+ if (p != NULL)
len = p - gstr;
else
len = strlen(gstr);
@@ -1339,7 +1346,7 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
ameth = EVP_PKEY_asn1_find_str(&tmpeng, gstr, len);
- if (!ameth) {
+ if (ameth == NULL) {
BIO_printf(bio_err, "Unknown algorithm %.*s\n", len, gstr);
return NULL;
}
@@ -1349,28 +1356,31 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
ENGINE_finish(tmpeng);
#endif
if (*pkey_type == EVP_PKEY_RSA) {
- if (p) {
+ if (p != NULL) {
keylen = atol(p + 1);
*pkeylen = keylen;
- } else
+ } else {
keylen = *pkeylen;
- } else if (p)
+ }
+ } else if (p != NULL) {
paramfile = p + 1;
+ }
}
- if (paramfile) {
+ if (paramfile != NULL) {
pbio = BIO_new_file(paramfile, "r");
- if (!pbio) {
+ if (pbio == NULL) {
BIO_printf(bio_err, "Can't open parameter file %s\n", paramfile);
return NULL;
}
param = PEM_read_bio_Parameters(pbio, NULL);
- if (!param) {
+ if (param == NULL) {
X509 *x;
+
(void)BIO_reset(pbio);
x = PEM_read_bio_X509(pbio, NULL, NULL, NULL);
- if (x) {
+ if (x != NULL) {
param = X509_get_pubkey(x);
X509_free(x);
}
@@ -1378,25 +1388,26 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
BIO_free(pbio);
- if (!param) {
+ if (param == NULL) {
BIO_printf(bio_err, "Error reading parameter file %s\n", paramfile);
return NULL;
}
- if (*pkey_type == -1)
+ if (*pkey_type == -1) {
*pkey_type = EVP_PKEY_id(param);
- else if (*pkey_type != EVP_PKEY_base_id(param)) {
+ } else if (*pkey_type != EVP_PKEY_base_id(param)) {
BIO_printf(bio_err, "Key Type does not match parameters\n");
EVP_PKEY_free(param);
return NULL;
}
}
- if (palgnam) {
+ if (palgnam != NULL) {
const EVP_PKEY_ASN1_METHOD *ameth;
ENGINE *tmpeng;
const char *anam;
+
ameth = EVP_PKEY_asn1_find(&tmpeng, *pkey_type);
- if (!ameth) {
+ if (ameth == NULL) {
BIO_puts(bio_err, "Internal error: can't find key algorithm\n");
return NULL;
}
@@ -1407,12 +1418,13 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
#endif
}
- if (param) {
+ if (param != NULL) {
gctx = EVP_PKEY_CTX_new(param, keygen_engine);
*pkeylen = EVP_PKEY_bits(param);
EVP_PKEY_free(param);
- } else
+ } else {
gctx = EVP_PKEY_CTX_new_id(*pkey_type, keygen_engine);
+ }
if (gctx == NULL) {
BIO_puts(bio_err, "Error allocating keygen context\n");