Skip to content

Commit

Permalink
Make the -inform option to be respected if possible
Browse files Browse the repository at this point in the history
Add OSSL_STORE_PARAM_INPUT_TYPE and make it possible to be
set when OSSL_STORE_open_ex() or OSSL_STORE_attach() is called.

The input type format is enforced only in case the file
type file store is used.

By default we use FORMAT_UNDEF meaning the input type
is not enforced.

Fixes openssl#14569

Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#15100)
  • Loading branch information
t8m authored and mattcaswell committed May 6, 2021
1 parent b86fa8c commit d382e79
Show file tree
Hide file tree
Showing 38 changed files with 212 additions and 143 deletions.
10 changes: 5 additions & 5 deletions apps/ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int ca_main(int argc, char **argv)
char def_dgst[80] = "";
char *dgst = NULL, *policy = NULL, *keyfile = NULL;
char *certfile = NULL, *crl_ext = NULL, *crlnumberfile = NULL;
int certformat = FORMAT_PEM, informat = FORMAT_PEM;
int certformat = FORMAT_UNDEF, informat = FORMAT_UNDEF;
const char *infile = NULL, *spkac_file = NULL, *ss_cert_file = NULL;
const char *extensions = NULL, *extfile = NULL, *passinarg = NULL;
char *passin = NULL;
Expand All @@ -289,7 +289,7 @@ int ca_main(int argc, char **argv)
size_t outdirlen = 0;
int create_ser = 0, free_passin = 0, total = 0, total_done = 0;
int batch = 0, default_op = 1, doupdatedb = 0, ext_copy = EXT_COPY_NONE;
int keyformat = FORMAT_PEM, multirdn = 1, notext = 0, output_der = 0;
int keyformat = FORMAT_UNDEF, multirdn = 1, notext = 0, output_der = 0;
int ret = 1, email_dn = 1, req = 0, verbose = 0, gencrl = 0, dorevoke = 0;
int rand_ser = 0, i, j, selfsign = 0, def_ret;
char *crl_lastupdate = NULL, *crl_nextupdate = NULL;
Expand Down Expand Up @@ -594,7 +594,7 @@ int ca_main(int argc, char **argv)
&& (certfile = lookup_conf(conf, section, ENV_CERTIFICATE)) == NULL)
goto end;

x509 = load_cert_pass(certfile, 1, passin, "CA certificate");
x509 = load_cert_pass(certfile, certformat, 1, passin, "CA certificate");
if (x509 == NULL)
goto end;

Expand Down Expand Up @@ -1287,7 +1287,7 @@ int ca_main(int argc, char **argv)
} else {
X509 *revcert;

revcert = load_cert_pass(infile, 1, passin,
revcert = load_cert_pass(infile, informat, 1, passin,
"certificate to be revoked");
if (revcert == NULL)
goto end;
Expand Down Expand Up @@ -1417,7 +1417,7 @@ static int certify_cert(X509 **xret, const char *infile, int certformat,
EVP_PKEY *pktmp = NULL;
int ok = -1, i;

if ((template_cert = load_cert_pass(infile, 1, passin,
if ((template_cert = load_cert_pass(infile, certformat, 1, passin,
"template certificate")) == NULL)
goto end;
if (verbose)
Expand Down
6 changes: 3 additions & 3 deletions apps/cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ static int opt_revreason = CRL_REASON_NONE;
/* credentials format */
static char *opt_certform_s = "PEM";
static int opt_certform = FORMAT_PEM;
static char *opt_keyform_s = "PEM";
static int opt_keyform = FORMAT_PEM;
static char *opt_keyform_s = NULL;
static int opt_keyform = FORMAT_UNDEF;
static char *opt_otherpass = NULL;
static char *opt_engine = NULL;

Expand Down Expand Up @@ -635,7 +635,7 @@ static X509 *load_cert_pwd(const char *uri, const char *pass, const char *desc)
X509 *cert;
char *pass_string = get_passwd(pass, desc);

cert = load_cert_pass(uri, 0, pass_string, desc);
cert = load_cert_pass(uri, FORMAT_UNDEF, 0, pass_string, desc);
clear_free(pass_string);
return cert;
}
Expand Down
16 changes: 9 additions & 7 deletions apps/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ int cms_main(int argc, char **argv)
int flags = CMS_DETACHED, noout = 0, print = 0, keyidx = -1, vpmtouched = 0;
int informat = FORMAT_SMIME, outformat = FORMAT_SMIME;
int operation = 0, ret = 1, rr_print = 0, rr_allorfirst = -1;
int verify_retcode = 0, rctformat = FORMAT_SMIME, keyform = FORMAT_PEM;
int verify_retcode = 0, rctformat = FORMAT_SMIME, keyform = FORMAT_UNDEF;
size_t secret_keylen = 0, secret_keyidlen = 0;
unsigned char *pwri_pass = NULL, *pwri_tmp = NULL;
unsigned char *secret_key = NULL, *secret_keyid = NULL;
Expand Down Expand Up @@ -611,7 +611,8 @@ int cms_main(int argc, char **argv)
if (operation == SMIME_ENCRYPT) {
if (encerts == NULL && (encerts = sk_X509_new_null()) == NULL)
goto end;
cert = load_cert(opt_arg(), "recipient certificate file");
cert = load_cert(opt_arg(), FORMAT_UNDEF,
"recipient certificate file");
if (cert == NULL)
goto end;
sk_X509_push(encerts, cert);
Expand Down Expand Up @@ -810,7 +811,8 @@ int cms_main(int argc, char **argv)
if ((encerts = sk_X509_new_null()) == NULL)
goto end;
while (*argv) {
if ((cert = load_cert(*argv, "recipient certificate file")) == NULL)
if ((cert = load_cert(*argv, FORMAT_UNDEF,
"recipient certificate file")) == NULL)
goto end;
sk_X509_push(encerts, cert);
cert = NULL;
Expand All @@ -826,23 +828,23 @@ int cms_main(int argc, char **argv)
}

if (recipfile != NULL && (operation == SMIME_DECRYPT)) {
if ((recip = load_cert(recipfile,
if ((recip = load_cert(recipfile, FORMAT_UNDEF,
"recipient certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
}

if (originatorfile != NULL) {
if ((originator = load_cert(originatorfile,
if ((originator = load_cert(originatorfile, FORMAT_UNDEF,
"originator certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
}

if (operation == SMIME_SIGN_RECEIPT) {
if ((signer = load_cert(signerfile,
if ((signer = load_cert(signerfile, FORMAT_UNDEF,
"receipt signer certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
Expand Down Expand Up @@ -1048,7 +1050,7 @@ int cms_main(int argc, char **argv)
signerfile = sk_OPENSSL_STRING_value(sksigners, i);
keyfile = sk_OPENSSL_STRING_value(skkeys, i);

signer = load_cert(signerfile, "signer certificate");
signer = load_cert(signerfile, FORMAT_UNDEF, "signer certificate");
if (signer == NULL) {
ret = 2;
goto end;
Expand Down
6 changes: 3 additions & 3 deletions apps/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int crl_main(int argc, char **argv)
const char *CAfile = NULL, *CApath = NULL, *CAstore = NULL, *prog;
OPTION_CHOICE o;
int hash = 0, issuer = 0, lastupdate = 0, nextupdate = 0, noout = 0;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, keyformat = FORMAT_PEM;
int informat = FORMAT_UNDEF, outformat = FORMAT_PEM, keyformat = FORMAT_UNDEF;
int ret = 1, num = 0, badsig = 0, fingerprint = 0, crlnumber = 0;
int text = 0, do_ver = 0, noCAfile = 0, noCApath = 0, noCAstore = 0;
int i;
Expand Down Expand Up @@ -211,7 +211,7 @@ int crl_main(int argc, char **argv)
if (!opt_md(digestname, &digest))
goto opthelp;
}
x = load_crl(infile, 1, "CRL");
x = load_crl(infile, informat, 1, "CRL");
if (x == NULL)
goto end;

Expand Down Expand Up @@ -256,7 +256,7 @@ int crl_main(int argc, char **argv)
BIO_puts(bio_err, "Missing CRL signing key\n");
goto end;
}
newcrl = load_crl(crldiff, 0, "other CRL");
newcrl = load_crl(crldiff, informat, 0, "other CRL");
if (!newcrl)
goto end;
pkey = load_key(keyfile, keyformat, 0, NULL, NULL, "CRL signing key");
Expand Down
2 changes: 1 addition & 1 deletion apps/dgst.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int dgst_main(int argc, char **argv)
const char *sigfile = NULL;
const char *md_name = NULL;
OPTION_CHOICE o;
int separator = 0, debug = 0, keyform = FORMAT_PEM, siglen = 0;
int separator = 0, debug = 0, keyform = FORMAT_UNDEF, siglen = 0;
int i, ret = 1, out_bin = -1, want_pub = 0, do_verify = 0;
int xoflen = 0;
unsigned char *buf = NULL, *sigbuf = NULL;
Expand Down
2 changes: 1 addition & 1 deletion apps/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int dsa_main(int argc, char **argv)
char *infile = NULL, *outfile = NULL, *prog;
char *passin = NULL, *passout = NULL, *passinarg = NULL, *passoutarg = NULL;
OPTION_CHOICE o;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, text = 0, noout = 0;
int informat = FORMAT_UNDEF, outformat = FORMAT_PEM, text = 0, noout = 0;
int modulus = 0, pubin = 0, pubout = 0, ret = 1;
int pvk_encr = DEFAULT_PVK_ENCR_STRENGTH;
int private = 0;
Expand Down
4 changes: 2 additions & 2 deletions apps/dsaparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int dsaparam_main(int argc, char **argv)
EVP_PKEY *params = NULL, *pkey = NULL;
EVP_PKEY_CTX *ctx = NULL;
int numbits = -1, num = 0, genkey = 0;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, noout = 0;
int informat = FORMAT_UNDEF, outformat = FORMAT_PEM, noout = 0;
int ret = 1, i, text = 0, private = 0;
char *infile = NULL, *outfile = NULL, *prog;
OPTION_CHOICE o;
Expand Down Expand Up @@ -181,7 +181,7 @@ int dsaparam_main(int argc, char **argv)
goto end;
}
} else {
params = load_keyparams(infile, 1, "DSA", "DSA parameters");
params = load_keyparams(infile, informat, 1, "DSA", "DSA parameters");
}
if (params == NULL) {
/* Error message should already have been displayed */
Expand Down
2 changes: 1 addition & 1 deletion apps/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int ec_main(int argc, char **argv)
char *infile = NULL, *outfile = NULL, *ciphername = NULL, *prog;
char *passin = NULL, *passout = NULL, *passinarg = NULL, *passoutarg = NULL;
OPTION_CHOICE o;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, text = 0, noout = 0;
int informat = FORMAT_UNDEF, outformat = FORMAT_PEM, text = 0, noout = 0;
int pubin = 0, pubout = 0, param_out = 0, ret = 1, private = 0;
int check = 0;
char *asn1_encoding = NULL;
Expand Down
2 changes: 1 addition & 1 deletion apps/ecparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ int ecparam_main(int argc, char **argv)
goto end;
}
} else {
params_key = load_keyparams(infile, 1, "EC", "EC parameters");
params_key = load_keyparams(infile, informat, 1, "EC", "EC parameters");
if (params_key == NULL || !EVP_PKEY_is_a(params_key, "EC"))
goto end;
if (point_format
Expand Down
2 changes: 1 addition & 1 deletion apps/gendsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int gendsa_main(int argc, char **argv)
goto end;
}

pkey = load_keyparams(dsaparams, 1, "DSA", "DSA parameters");
pkey = load_keyparams(dsaparams, FORMAT_UNDEF, 1, "DSA", "DSA parameters");

out = bio_open_owner(outfile, FORMAT_PEM, private);
if (out == NULL)
Expand Down
15 changes: 8 additions & 7 deletions apps/include/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@ char *get_passwd(const char *pass, const char *desc);
int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2);
int add_oid_section(CONF *conf);
X509_REQ *load_csr(const char *file, int format, const char *desc);
X509 *load_cert_pass(const char *uri, int maybe_stdin,
X509 *load_cert_pass(const char *uri, int format, int maybe_stdin,
const char *pass, const char *desc);
#define load_cert(uri, desc) load_cert_pass(uri, 1, NULL, desc)
X509_CRL *load_crl(const char *uri, int maybe_stdin, const char *desc);
#define load_cert(uri, format, desc) load_cert_pass(uri, format, 1, NULL, desc)
X509_CRL *load_crl(const char *uri, int format, int maybe_stdin,
const char *desc);
void cleanse(char *str);
void clear_free(char *str);
EVP_PKEY *load_key(const char *uri, int format, int maybe_stdin,
const char *pass, ENGINE *e, const char *desc);
EVP_PKEY *load_pubkey(const char *uri, int format, int maybe_stdin,
const char *pass, ENGINE *e, const char *desc);
EVP_PKEY *load_keyparams(const char *uri, int maybe_stdin, const char *keytype,
const char *desc);
EVP_PKEY *load_keyparams(const char *uri, int format, int maybe_stdin,
const char *keytype, const char *desc);
char *next_item(char *opt); /* in list separated by comma and/or space */
int load_cert_certs(const char *uri,
X509 **pcert, STACK_OF(X509) **pcerts,
Expand All @@ -133,13 +134,13 @@ int load_certs(const char *uri, int maybe_stdin, STACK_OF(X509) **certs,
const char *pass, const char *desc);
int load_crls(const char *uri, STACK_OF(X509_CRL) **crls,
const char *pass, const char *desc);
int load_key_certs_crls(const char *uri, int maybe_stdin,
int load_key_certs_crls(const char *uri, int format, int maybe_stdin,
const char *pass, const char *desc,
EVP_PKEY **ppkey, EVP_PKEY **ppubkey,
EVP_PKEY **pparams,
X509 **pcert, STACK_OF(X509) **pcerts,
X509_CRL **pcrl, STACK_OF(X509_CRL) **pcrls);
int load_key_cert_crl(const char *uri, int maybe_stdin,
int load_key_cert_crl(const char *uri, int format, int maybe_stdin,
const char *pass, const char *desc,
EVP_PKEY **ppkey, EVP_PKEY **ppubkey,
X509 **pcert, X509_CRL **pcrl);
Expand Down
Loading

0 comments on commit d382e79

Please sign in to comment.