aboutsummaryrefslogtreecommitdiffstats
path: root/apps/apps.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/apps.c')
-rw-r--r--apps/apps.c138
1 files changed, 72 insertions, 66 deletions
diff --git a/apps/apps.c b/apps/apps.c
index 15cf4a76f0..a89d4eb5e6 100644
--- a/apps/apps.c
+++ b/apps/apps.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
@@ -140,9 +140,8 @@ int ctx_set_verify_locations(SSL_CTX *ctx, const char *CAfile,
int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path)
{
- if (path == NULL) {
+ if (path == NULL)
return SSL_CTX_set_default_ctlog_list_file(ctx);
- }
return SSL_CTX_set_ctlog_list_file(ctx, path);
}
@@ -312,8 +311,7 @@ int password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_tmp)
if (ok >= 0)
do {
ok = UI_process(ui);
- }
- while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0));
+ } while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0));
OPENSSL_clear_free(buff, (unsigned int)bufsiz);
@@ -342,22 +340,24 @@ static char *app_get_pass(const char *arg, int keepbio);
int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2)
{
int same;
- if (!arg2 || !arg1 || strcmp(arg1, arg2))
+ if (arg2 == NULL || arg1 == NULL || strcmp(arg1, arg2))
same = 0;
else
same = 1;
- if (arg1) {
+ if (arg1 != NULL) {
*pass1 = app_get_pass(arg1, same);
- if (!*pass1)
+ if (*pass1 == NULL)
return 0;
- } else if (pass1)
+ } else if (pass1 != NULL) {
*pass1 = NULL;
- if (arg2) {
+ }
+ if (arg2 != NULL) {
*pass2 = app_get_pass(arg2, same ? 2 : 0);
- if (!*pass2)
+ if (*pass2 == NULL)
return 0;
- } else if (pass2)
+ } else if (pass2 != NULL) {
*pass2 = NULL;
+ }
return 1;
}
@@ -371,16 +371,16 @@ static char *app_get_pass(const char *arg, int keepbio)
return OPENSSL_strdup(arg + 5);
if (strncmp(arg, "env:", 4) == 0) {
tmp = getenv(arg + 4);
- if (!tmp) {
+ if (tmp == NULL) {
BIO_printf(bio_err, "Can't read environment variable %s\n", arg + 4);
return NULL;
}
return OPENSSL_strdup(tmp);
}
- if (!keepbio || !pwdbio) {
+ if (!keepbio || pwdbio == NULL) {
if (strncmp(arg, "file:", 5) == 0) {
pwdbio = BIO_new_file(arg + 5, "r");
- if (!pwdbio) {
+ if (pwdbio == NULL) {
BIO_printf(bio_err, "Can't open file %s\n", arg + 5);
return NULL;
}
@@ -429,7 +429,7 @@ static char *app_get_pass(const char *arg, int keepbio)
return NULL;
}
tmp = strchr(tpass, '\n');
- if (tmp)
+ if (tmp != NULL)
*tmp = 0;
return OPENSSL_strdup(tpass);
}
@@ -454,6 +454,7 @@ static CONF *app_load_config_(BIO *in, const char *filename)
NCONF_free(conf);
return NULL;
}
+
CONF *app_load_config(const char *filename)
{
BIO *in;
@@ -467,6 +468,7 @@ CONF *app_load_config(const char *filename)
BIO_free(in);
return conf;
}
+
CONF *app_load_config_quiet(const char *filename)
{
BIO *in;
@@ -540,9 +542,9 @@ static int load_pkcs12(BIO *in, const char *desc,
goto die;
}
/* See if an empty password will do */
- if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, NULL, 0))
+ if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, NULL, 0)) {
pass = "";
- else {
+ } else {
if (!pem_cb)
pem_cb = (pem_password_cb *)password_callback;
len = pem_cb(tpass, PEM_BUFSIZE, 0, cb_data);
@@ -603,8 +605,7 @@ static int load_cert_crl_http(const char *url, X509 **pcert, X509_CRL **pcrl)
OPENSSL_free(host);
OPENSSL_free(path);
OPENSSL_free(port);
- if (bio)
- BIO_free_all(bio);
+ BIO_free_all(bio);
OCSP_REQ_CTX_free(rctx);
if (rv != 1) {
BIO_printf(bio_err, "Error loading %s from %s\n",
@@ -630,17 +631,18 @@ X509 *load_cert(const char *file, int format, const char *cert_descrip)
if (file == NULL) {
unbuffer(stdin);
cert = dup_bio_in(format);
- } else
+ } else {
cert = bio_open_default(file, 'r', format);
+ }
if (cert == NULL)
goto end;
- if (format == FORMAT_ASN1)
+ if (format == FORMAT_ASN1) {
x = d2i_X509_bio(cert, NULL);
- else if (format == FORMAT_PEM)
+ } else if (format == FORMAT_PEM) {
x = PEM_read_bio_X509_AUX(cert, NULL,
(pem_password_cb *)password_callback, NULL);
- else if (format == FORMAT_PKCS12) {
+ } else if (format == FORMAT_PKCS12) {
if (!load_pkcs12(cert, cert_descrip, NULL, NULL, NULL, &x, NULL))
goto end;
} else {
@@ -671,11 +673,11 @@ X509_CRL *load_crl(const char *infile, int format)
in = bio_open_default(infile, 'r', format);
if (in == NULL)
goto end;
- if (format == FORMAT_ASN1)
+ if (format == FORMAT_ASN1) {
x = d2i_X509_CRL_bio(in, NULL);
- else if (format == FORMAT_PEM)
+ } else if (format == FORMAT_PEM) {
x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
- else {
+ } else {
BIO_printf(bio_err, "bad input format specified for input crl\n");
goto end;
}
@@ -705,9 +707,9 @@ EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
goto end;
}
if (format == FORMAT_ENGINE) {
- if (e == NULL)
+ if (e == NULL) {
BIO_printf(bio_err, "no engine specified\n");
- else {
+ } else {
#ifndef OPENSSL_NO_ENGINE
if (ENGINE_init(e)) {
pkey = ENGINE_load_private_key(e, file, ui_method, &cb_data);
@@ -726,8 +728,9 @@ EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
if (file == NULL && maybe_stdin) {
unbuffer(stdin);
key = dup_bio_in(format);
- } else
+ } else {
key = bio_open_default(file, 'r', format);
+ }
if (key == NULL)
goto end;
if (format == FORMAT_ASN1) {
@@ -736,21 +739,19 @@ EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
pkey = PEM_read_bio_PrivateKey(key, NULL,
(pem_password_cb *)password_callback,
&cb_data);
- }
- else if (format == FORMAT_PKCS12) {
+ } else if (format == FORMAT_PKCS12) {
if (!load_pkcs12(key, key_descrip,
(pem_password_cb *)password_callback, &cb_data,
&pkey, NULL, NULL))
goto end;
- }
#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
- else if (format == FORMAT_MSBLOB)
+ } else if (format == FORMAT_MSBLOB) {
pkey = b2i_PrivateKey_bio(key);
- else if (format == FORMAT_PVK)
+ } else if (format == FORMAT_PVK) {
pkey = b2i_PVK_bio(key, (pem_password_cb *)password_callback,
&cb_data);
#endif
- else {
+ } else {
BIO_printf(bio_err, "bad input format specified for key file\n");
goto end;
}
@@ -778,9 +779,9 @@ EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
goto end;
}
if (format == FORMAT_ENGINE) {
- if (e == NULL)
+ if (e == NULL) {
BIO_printf(bio_err, "no engine specified\n");
- else {
+ } else {
#ifndef OPENSSL_NO_ENGINE
pkey = ENGINE_load_public_key(e, file, ui_method, &cb_data);
if (pkey == NULL) {
@@ -796,14 +797,14 @@ EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
if (file == NULL && maybe_stdin) {
unbuffer(stdin);
key = dup_bio_in(format);
- } else
+ } else {
key = bio_open_default(file, 'r', format);
+ }
if (key == NULL)
goto end;
if (format == FORMAT_ASN1) {
pkey = d2i_PUBKEY_bio(key, NULL);
- }
- else if (format == FORMAT_ASN1RSA) {
+ } else if (format == FORMAT_ASN1RSA) {
#ifndef OPENSSL_NO_RSA
RSA *rsa;
rsa = d2i_RSAPublicKey_bio(key, NULL);
@@ -833,16 +834,15 @@ EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
BIO_printf(bio_err, "RSA keys not supported\n");
#endif
pkey = NULL;
- }
- else if (format == FORMAT_PEM) {
+ } else if (format == FORMAT_PEM) {
pkey = PEM_read_bio_PUBKEY(key, NULL,
(pem_password_cb *)password_callback,
&cb_data);
- }
#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
- else if (format == FORMAT_MSBLOB)
+ } else if (format == FORMAT_MSBLOB) {
pkey = b2i_PublicKey_bio(key);
#endif
+ }
end:
BIO_free(key);
if (pkey == NULL)
@@ -880,36 +880,36 @@ static int load_certs_crls(const char *file, int format,
BIO_free(bio);
- if (pcerts && *pcerts == NULL) {
+ if (pcerts != NULL && *pcerts == NULL) {
*pcerts = sk_X509_new_null();
- if (!*pcerts)
+ if (*pcerts == NULL)
goto end;
}
- if (pcrls && *pcrls == NULL) {
+ if (pcrls != NULL && *pcrls == NULL) {
*pcrls = sk_X509_CRL_new_null();
- if (!*pcrls)
+ if (*pcrls == NULL)
goto end;
}
for (i = 0; i < sk_X509_INFO_num(xis); i++) {
xi = sk_X509_INFO_value(xis, i);
- if (xi->x509 && pcerts) {
+ if (xi->x509 != NULL && pcerts != NULL) {
if (!sk_X509_push(*pcerts, xi->x509))
goto end;
xi->x509 = NULL;
}
- if (xi->crl && pcrls) {
+ if (xi->crl != NULL && pcrls != NULL) {
if (!sk_X509_CRL_push(*pcrls, xi->crl))
goto end;
xi->crl = NULL;
}
}
- if (pcerts && sk_X509_num(*pcerts) > 0)
+ if (pcerts != NULL && sk_X509_num(*pcerts) > 0)
rv = 1;
- if (pcrls && sk_X509_CRL_num(*pcrls) > 0)
+ if (pcrls != NULL && sk_X509_CRL_num(*pcrls) > 0)
rv = 1;
end:
@@ -917,11 +917,11 @@ static int load_certs_crls(const char *file, int format,
sk_X509_INFO_pop_free(xis, X509_INFO_free);
if (rv == 0) {
- if (pcerts) {
+ if (pcerts != NULL) {
sk_X509_pop_free(*pcerts, X509_free);
*pcerts = NULL;
}
- if (pcrls) {
+ if (pcrls != NULL) {
sk_X509_CRL_pop_free(*pcrls, X509_CRL_free);
*pcrls = NULL;
}
@@ -1126,8 +1126,9 @@ static int set_table_opts(unsigned long *flags, const char *arg,
} else if (c == '+') {
c = 1;
arg++;
- } else
+ } else {
c = 1;
+ }
for (ptbl = in_tbl; ptbl->name; ptbl++) {
if (strcasecmp(arg, ptbl->name) == 0) {
@@ -1172,9 +1173,9 @@ void print_bignum_var(BIO *out, const BIGNUM *in, const char *var,
int len, unsigned char *buffer)
{
BIO_printf(out, " static unsigned char %s_%d[] = {", var, len);
- if (BN_is_zero(in))
+ if (BN_is_zero(in)) {
BIO_printf(out, "\n\t0x00");
- else {
+ } else {
int i, l;
l = BN_bn2bin(in, buffer);
@@ -1189,6 +1190,7 @@ void print_bignum_var(BIO *out, const BIGNUM *in, const char *var,
}
BIO_printf(out, "\n };\n");
}
+
void print_array(BIO *out, const char* title, int len, const unsigned char* d)
{
int i;
@@ -1222,8 +1224,9 @@ X509_STORE *setup_verify(const char *CAfile, const char *CApath, int noCAfile, i
BIO_printf(bio_err, "Error loading file %s\n", CAfile);
goto end;
}
- } else
+ } else {
X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
+ }
}
if (CApath != NULL || !noCApath) {
@@ -1235,8 +1238,9 @@ X509_STORE *setup_verify(const char *CAfile, const char *CApath, int noCAfile, i
BIO_printf(bio_err, "Error loading directory %s\n", CApath);
goto end;
}
- } else
+ } else {
X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
+ }
}
ERR_clear_error();
@@ -1267,7 +1271,7 @@ ENGINE *setup_engine(const char *engine, int debug)
ENGINE *e = NULL;
#ifndef OPENSSL_NO_ENGINE
- if (engine) {
+ if (engine != NULL) {
if (strcmp(engine, "auto") == 0) {
BIO_printf(bio_err, "enabling auto ENGINE support\n");
ENGINE_register_all_complete();
@@ -1873,8 +1877,9 @@ static void nodes_print(const char *name, STACK_OF(X509_POLICY_NODE) *nodes)
node = sk_X509_POLICY_NODE_value(nodes, i);
X509_POLICY_NODE_print(bio_err, node, 2);
}
- } else
+ } else {
BIO_puts(bio_err, " <empty>\n");
+ }
}
void policies_print(X509_STORE_CTX *ctx)
@@ -1919,8 +1924,9 @@ unsigned char *next_protos_parse(size_t *outlen, const char *in)
}
out[start] = i - start;
start = i + 1;
- } else
+ } else {
out[i + 1] = in[i];
+ }
}
*outlen = len + 1;
@@ -2229,9 +2235,9 @@ double app_tminterval(int stop, int usertime)
if (usertime)
now = rus.tms_utime;
- if (stop == TM_START)
+ if (stop == TM_START) {
tmstart = now;
- else {
+ } else {
long int tck = sysconf(_SC_CLK_TCK);
ret = (now - tmstart) / (double)tck;
}
@@ -2368,7 +2374,7 @@ int raw_read_stdin(void *buf, int siz)
return (-1);
}
#elif defined(__VMS)
-#include <sys/socket.h>
+# include <sys/socket.h>
int raw_read_stdin(void *buf, int siz)
{