}
/* No extra args. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (oidfile != NULL) {
/* Optional arg is cipher name. */
argv = opt_rest();
- argc = opt_num_rest();
- if (argc == 1)
+ if (opt_num_rest() == 1)
ciphers = argv[0];
- else if (argc != 0)
+ else if (!opt_check_rest_arg(NULL))
goto opthelp;
if (convert != NULL) {
}
/* No extra args. */
- argc = opt_num_rest();
- argv = opt_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
return 1;
}
if (!opt_md(digestname, &sign_md))
goto end;
}
- if (ciphername != NULL) {
- if (!opt_cipher_any(ciphername, &cipher))
- goto end;
- }
+ if (!opt_cipher_any(ciphername, &cipher))
+ goto end;
if (wrapname != NULL) {
if (!opt_cipher_any(wrapname, &wrap_cipher))
goto end;
}
/* No remaining args. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
- if (digestname != NULL) {
- if (!opt_md(digestname, &digest))
- goto opthelp;
- }
+ if (!opt_md(digestname, &digest))
+ goto opthelp;
x = load_crl(infile, informat, 1, "CRL");
if (x == NULL)
goto end;
}
/* No remaining args. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!nocrl) {
if (argc == 1) {
if (!opt_int(argv[0], &num) || num <= 0)
goto opthelp;
- } else if (argc != 0) {
+ } else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
}
if (!app_RAND_load())
}
/* No extra args. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &enc))
- goto end;
- }
+ if (!opt_cipher(ciphername, &enc))
+ goto end;
private = pubin || pubout ? 0 : 1;
if (text && !pubin)
private = 1;
if (argc == 1) {
if (!opt_int(argv[0], &num) || num < 0)
goto opthelp;
- } else if (argc != 0) {
+ } else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
}
if (!app_RAND_load())
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &enc))
- goto opthelp;
- }
+ if (!opt_cipher(ciphername, &enc))
+ goto opthelp;
private = param_out || pubin || pubout ? 0 : 1;
if (text && !pubin)
private = 1;
}
/* No extra args. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
goto end;
/* Get the cipher name, either from progname (if set) or flag. */
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &cipher))
- goto opthelp;
- }
+ if (!opt_cipher(ciphername, &cipher))
+ goto opthelp;
if (digestname != NULL) {
if (!opt_md(digestname, &dgst))
goto opthelp;
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0 || (verify && in_fname == NULL))
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
+ if (verify && in_fname == NULL) {
+ BIO_printf(bio_err, "Missing -in option for -verify\n");
+ goto opthelp;
+ }
if (parent_config != NULL) {
/* Test that a parent config can load the module */
}
/* One argument, the params file. */
- argc = opt_num_rest();
- argv = opt_rest();
- if (argc != 1)
+ if (!opt_check_rest_arg("params file"))
goto opthelp;
+ argv = opt_rest();
dsaparams = argv[0];
if (!app_RAND_load())
goto end;
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &enc))
- goto end;
- }
+ if (!opt_cipher(ciphername, &enc))
+ goto end;
private = 1;
if (!app_passwd(NULL, passoutarg, NULL, &passout)) {
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
/* Fetch cipher, etc. */
goto end;
}
}
- if (ciphername != NULL)
- if (!opt_cipher(ciphername, &cipher) || do_param == 1)
- goto opthelp;
+ if (!opt_cipher(ciphername, &cipher))
+ goto opthelp;
+ if (ciphername != NULL && do_param == 1) {
+ BIO_printf(bio_err, "Cannot use cipher with -genparam option\n");
+ goto opthelp;
+ }
private = do_param ? 0 : 1;
"Warning: It is not recommended to use more than %d bit for RSA keys.\n"
" Your key size is %d! Larger key size may behave not as expected.\n",
OPENSSL_RSA_MAX_MODULUS_BITS, num);
- } else if (argc > 0) {
- BIO_printf(bio_err, "Extra arguments given.\n");
+ } else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
}
goto end;
private = 1;
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &enc))
- goto end;
- }
+ if (!opt_cipher(ciphername, &enc))
+ goto end;
if (!app_passwd(NULL, passoutarg, NULL, &passout)) {
BIO_printf(bio_err, "Error getting password\n");
goto end;
int opt_cipher(const char *name, EVP_CIPHER **cipherp);
int opt_cipher_any(const char *name, EVP_CIPHER **cipherp);
int opt_cipher_silent(const char *name, EVP_CIPHER **cipherp);
+int opt_check_md(const char *name);
int opt_md(const char *name, EVP_MD **mdp);
int opt_md_silent(const char *name, EVP_MD **mdp);
char **opt_rest(void);
int opt_num_rest(void);
+int opt_check_rest_arg(const char *expected);
/* Returns non-zero if legacy paths are still available */
int opt_legacy_okay(void);
break;
}
}
- if (opt_num_rest() != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (dirty > 1) {
BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
{
int ret;
+ if (name == NULL)
+ return 1;
if ((ret = opt_cipher_silent(name, cipherp)) == 0)
- opt_printf_stderr("%s: Unknown cipher: %s\n", prog, name);
+ opt_printf_stderr("%s: Unknown option or cipher: %s\n", prog, name);
return ret;
}
unsigned long int flags;
EVP_CIPHER *c = NULL;
+ if (name == NULL)
+ return 1;
if (opt_cipher_any(name, &c)) {
mode = EVP_CIPHER_get_mode(c);
flags = EVP_CIPHER_get_flags(c);
{
int ret;
+ if (name == NULL)
+ return 1;
if ((ret = opt_md_silent(name, mdp)) == 0)
- opt_printf_stderr("%s: Unknown option or message digest: %s\n", prog,
- name != NULL ? name : "\"\"");
+ opt_printf_stderr("%s: Unknown option or message digest: %s\n",
+ prog, name);
return ret;
}
+int opt_check_md(const char *name)
+{
+ if (opt_md(name, NULL))
+ return 1;
+ ERR_clear_error();
+ return 0;
+}
+
/* Look through a list of name/value pairs. */
int opt_pair(const char *name, const OPT_PAIR* pairs, int *result)
{
return i;
}
+int opt_check_rest_arg(const char *expected)
+{
+ char *opt = *opt_rest();
+
+ if (opt == NULL || *opt == '\0') {
+ if (expected == NULL)
+ return 1;
+ opt_printf_stderr("%s: Missing argument: %s\n", prog, expected);
+ return 0;
+ } else if (expected != NULL) {
+ return 1;
+ }
+ if (opt_unknown() == NULL)
+ opt_printf_stderr("%s: Extra option: \"%s\"\n", prog, opt);
+ else
+ opt_printf_stderr("%s: Extra (unknown) options: \"%s\" \"%s\"\n",
+ prog, opt_unknown(), opt != NULL ? opt : "");
+ return 0;
+}
+
/* Return a string describing the parameter type. */
static const char *valtype2param(const OPTIONS *o)
{
}
/* No extra arguments. */
- if (opt_num_rest() != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (todo.commands)
}
/* One argument, the MAC name. */
- argc = opt_num_rest();
- argv = opt_rest();
- if (argc != 1)
+ if (!opt_check_rest_arg("MAC name"))
goto opthelp;
+ argv = opt_rest();
mac = EVP_MAC_fetch(app_get0_libctx(), argv[0], app_get0_propq());
if (mac == NULL) {
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
in = bio_open_default(infile, 'r', FORMAT_PEM);
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (trailing_md) {
new_argv[2] = NULL;
return do_cmd(prog_init(), 2, new_argv);
}
- if (opt_num_rest() != 0) {
+ if (!opt_check_rest_arg(NULL)) {
BIO_printf(bio_err, "Usage: %s\n", prog);
return 1;
}
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
goto end;
- if (ciphername != NULL) {
- if (!opt_cipher_any(ciphername, &enc))
- goto opthelp;
- }
+ if (!opt_cipher_any(ciphername, &enc))
+ goto opthelp;
if (export_pkcs12) {
if ((options & INFO) != 0)
WARN_EXPORT("info");
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
in = bio_open_default(infile, 'r', informat);
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
private = 1;
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (text && text_pub)
private = (!noout && !pubout) || (text && !text_pub);
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &cipher))
- goto opthelp;
- }
+ if (!opt_cipher(ciphername, &cipher))
+ goto opthelp;
if (cipher == NULL) {
if (passoutarg != NULL)
BIO_printf(bio_err,
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
in = bio_open_default(infile, 'r', FORMAT_PEM);
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
}
/* Optional arguments are numbers to check. */
+ if (generate && !opt_check_rest_arg(NULL))
+ goto opthelp;
argc = opt_num_rest();
argv = opt_rest();
- if (generate) {
- if (argc != 0)
- goto opthelp;
- } else if (argc == 0) {
+ if (!generate && argc == 0) {
+ BIO_printf(bio_err, "Missing number (s) to check\n");
goto opthelp;
}
if (argc == 1) {
if (!opt_int(argv[0], &num) || num <= 0)
goto opthelp;
- } else if (argc != 0) {
+ } else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
}
X509 *new_x509 = NULL, *CAcert = NULL;
X509_REQ *req = NULL;
EVP_CIPHER *cipher = NULL;
- EVP_MD *md = NULL;
int ext_copy = EXT_COPY_UNSET;
BIO *addext_bio = NULL;
char *extsect = NULL;
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
/* Check that any specified digest is fetchable */
if (digest != NULL) {
- if (!opt_md(digest, &md)) {
- ERR_clear_error();
+ if (!opt_check_md(digest))
goto opthelp;
- }
- EVP_MD_free(md);
} else {
/* No digest specified, default to configuration */
p = NCONF_get_string(req_conf, section, "default_md");
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
- if (ciphername != NULL) {
- if (!opt_cipher(ciphername, &enc))
- goto opthelp;
- }
+ if (!opt_cipher(ciphername, &enc))
+ goto opthelp;
private = (text && !pubin) || (!pubout && !noout) ? 1 : 0;
if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
}
/* Optional argument is connect string if -connect not used. */
- argc = opt_num_rest();
- if (argc == 1) {
+ if (opt_num_rest() == 1) {
/* Don't allow -connect and a separate argument. */
if (connectstr != NULL) {
BIO_printf(bio_err,
}
connect_type = use_inet;
freeandcopy(&connectstr, *opt_rest());
- } else if (argc != 0) {
+ } else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
}
if (!app_RAND_load())
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (cipher == NULL)
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
x = load_sess_id(infile, informat);
if (!opt_md(digestname, &sign_md))
goto opthelp;
}
- if (ciphername != NULL) {
- if (!opt_cipher_any(ciphername, &cipher))
+ if (!opt_cipher_any(ciphername, &cipher))
goto opthelp;
- }
if (!(operation & SMIME_SIGNERS) && (skkeys != NULL || sksigners != NULL)) {
BIO_puts(bio_err, "Multiple signers or keys not allowed\n");
goto opthelp;
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_passwd(passinarg, NULL, &passin, NULL)) {
}
/* One argument, the URI */
- argc = opt_num_rest();
- argv = opt_rest();
- if (argc != 1)
+ if (!opt_check_rest_arg("URI"))
goto opthelp;
+ argv = opt_rest();
- if (digestname != NULL) {
- if (!opt_md(digestname, &digest))
- goto opthelp;
- }
+ if (!opt_md(digestname, &digest))
+ goto opthelp;
if (criterion != 0) {
switch (criterion) {
case OPT_QUERY:
case OPT_REPLY:
case OPT_VERIFY:
- if (mode != OPT_ERR)
+ if (mode != OPT_ERR) {
+ BIO_printf(bio_err, "%s: Must give only one of -query, -reply, or -verify\n", prog);
goto opthelp;
+ }
mode = o;
break;
case OPT_DATA:
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0 || mode == OPT_ERR)
+ if (!opt_check_rest_arg(NULL))
+ goto opthelp;
+ if (mode == OPT_ERR) {
+ BIO_printf(bio_err, "%s: Must give one of -query, -reply, or -verify\n", prog);
goto opthelp;
+ }
if (!app_RAND_load())
goto end;
- if (digestname != NULL) {
- if (!opt_md(digestname, &md))
- goto opthelp;
- }
+ if (!opt_md(digestname, &md))
+ goto opthelp;
if (mode == OPT_REPLY && passin &&
!app_passwd(passin, NULL, &password, NULL)) {
BIO_printf(bio_err, "Error getting password.\n");
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!dirty)
}
/* No extra arguments. */
- argc = opt_num_rest();
- if (argc != 0)
+ if (!opt_check_rest_arg(NULL))
goto opthelp;
if (!app_RAND_load())
goto end;
+ if (!opt_check_md(digest))
+ goto opthelp;
+
if (preserve_dates && days != UNSET_DAYS) {
BIO_printf(bio_err, "Cannot use -preserve_dates with -days option\n");
goto err;