diff options
author | Richard Levitte <levitte@openssl.org> | 2002-08-01 16:28:40 +0000 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2002-08-01 16:28:40 +0000 |
commit | da9b97246695c370702d15be2b3778427cf57082 (patch) | |
tree | 9ef594c01fa55c710cc254495f366e6763b368fc | |
parent | bd45950f4a85d04eb23a4d3846ed5a3c13bd19e0 (diff) |
Make it possible to load keys from stdin, and restore that
functionality in the programs that had that before.
Part fo PR 164
-rw-r--r-- | apps/apps.c | 38 | ||||
-rw-r--r-- | apps/apps.h | 4 | ||||
-rw-r--r-- | apps/ca.c | 2 | ||||
-rw-r--r-- | apps/dgst.c | 4 | ||||
-rw-r--r-- | apps/ocsp.c | 4 | ||||
-rw-r--r-- | apps/pkcs12.c | 2 | ||||
-rw-r--r-- | apps/pkcs8.c | 3 | ||||
-rw-r--r-- | apps/req.c | 2 | ||||
-rw-r--r-- | apps/rsa.c | 4 | ||||
-rw-r--r-- | apps/rsautl.c | 4 | ||||
-rw-r--r-- | apps/smime.c | 2 | ||||
-rw-r--r-- | apps/spkac.c | 2 | ||||
-rw-r--r-- | apps/x509.c | 13 |
13 files changed, 50 insertions, 34 deletions
diff --git a/apps/apps.c b/apps/apps.c index a302119d7f..6f64e6313f 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -798,7 +798,7 @@ end: return(x); } -EVP_PKEY *load_key(BIO *err, const char *file, int format, +EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *key_descrip) { BIO *key=NULL; @@ -808,7 +808,7 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format, cb_data.password = pass; cb_data.prompt_info = file; - if (file == NULL) + if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE)) { BIO_printf(err,"no keyfile specified\n"); goto end; @@ -828,12 +828,19 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format, ERR_print_errors(err); goto end; } - if (BIO_read_filename(key,file) <= 0) + if (file == NULL && maybe_stdin) { - BIO_printf(err, "Error opening %s %s\n", key_descrip, file); - ERR_print_errors(err); - goto end; + setvbuf(stdin, NULL, _IONBF, 0); + BIO_set_fp(key,stdin,BIO_NOCLOSE); } + else + if (BIO_read_filename(key,file) <= 0) + { + BIO_printf(err, "Error opening %s %s\n", + key_descrip, file); + ERR_print_errors(err); + goto end; + } if (format == FORMAT_ASN1) { pkey=d2i_PrivateKey_bio(key, NULL); @@ -867,7 +874,7 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format, return(pkey); } -EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, +EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *key_descrip) { BIO *key=NULL; @@ -877,7 +884,7 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, cb_data.password = pass; cb_data.prompt_info = file; - if (file == NULL) + if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE)) { BIO_printf(err,"no keyfile specified\n"); goto end; @@ -897,11 +904,18 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, ERR_print_errors(err); goto end; } - if (BIO_read_filename(key,file) <= 0) + if (file == NULL && maybe_stdin) { - BIO_printf(err, "Error opening %s %s\n", key_descrip, file); - ERR_print_errors(err); - goto end; + setvbuf(stdin, NULL, _IONBF, 0); + BIO_set_fp(key,stdin,BIO_NOCLOSE); + } + else + if (BIO_read_filename(key,file) <= 0) + { + BIO_printf(err, "Error opening %s %s\n", + key_descrip, file); + ERR_print_errors(err); + goto end; } if (format == FORMAT_ASN1) { diff --git a/apps/apps.h b/apps/apps.h index a88902ac13..32a79605ee 100644 --- a/apps/apps.h +++ b/apps/apps.h @@ -233,9 +233,9 @@ int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2); int add_oid_section(BIO *err, CONF *conf); X509 *load_cert(BIO *err, const char *file, int format, const char *pass, ENGINE *e, const char *cert_descrip); -EVP_PKEY *load_key(BIO *err, const char *file, int format, +EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *key_descrip); -EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, +EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *key_descrip); STACK_OF(X509) *load_certs(BIO *err, const char *file, int format, const char *pass, ENGINE *e, const char *cert_descrip); @@ -699,7 +699,7 @@ bad: goto err; } } - pkey = load_key(bio_err, keyfile, keyform, key, e, + pkey = load_key(bio_err, keyfile, keyform, 0, key, e, "CA private key"); if (key) memset(key,0,strlen(key)); if (pkey == NULL) diff --git a/apps/dgst.c b/apps/dgst.c index e21c3d83ac..32e40c1f53 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -277,10 +277,10 @@ int MAIN(int argc, char **argv) if(keyfile) { if (want_pub) - sigkey = load_pubkey(bio_err, keyfile, keyform, NULL, + sigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL, e, "key file"); else - sigkey = load_key(bio_err, keyfile, keyform, NULL, + sigkey = load_key(bio_err, keyfile, keyform, 0, NULL, e, "key file"); if (!sigkey) { diff --git a/apps/ocsp.c b/apps/ocsp.c index 76a11ab067..59b97a634b 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -617,7 +617,7 @@ int MAIN(int argc, char **argv) NULL, e, "responder other certificates"); if (!rother) goto end; } - rkey = load_key(bio_err, rkeyfile, FORMAT_PEM, NULL, NULL, + rkey = load_key(bio_err, rkeyfile, FORMAT_PEM, 0, NULL, NULL, "responder private key"); if (!rkey) goto end; @@ -663,7 +663,7 @@ int MAIN(int argc, char **argv) NULL, e, "signer certificates"); if (!sign_other) goto end; } - key = load_key(bio_err, keyfile, FORMAT_PEM, NULL, NULL, + key = load_key(bio_err, keyfile, FORMAT_PEM, 0, NULL, NULL, "signer private key"); if (!key) goto end; diff --git a/apps/pkcs12.c b/apps/pkcs12.c index e345cf1489..73550d1801 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -427,7 +427,7 @@ int MAIN(int argc, char **argv) CRYPTO_push_info("process -export_cert"); CRYPTO_push_info("reading private key"); #endif - key = load_key(bio_err, keyname ? keyname : infile, FORMAT_PEM, + key = load_key(bio_err, keyname ? keyname : infile, FORMAT_PEM, 1, passin, e, "private key"); if (!key) { goto export_end; diff --git a/apps/pkcs8.c b/apps/pkcs8.c index ba91caee6b..912e32006b 100644 --- a/apps/pkcs8.c +++ b/apps/pkcs8.c @@ -222,7 +222,8 @@ int MAIN(int argc, char **argv) if (topk8) { BIO_free(in); /* Not needed in this section */ - pkey = load_key(bio_err, infile, informat, passin, e, "key"); + pkey = load_key(bio_err, infile, informat, 1, + passin, e, "key"); if (!pkey) { return (1); } diff --git a/apps/req.c b/apps/req.c index 75a3604061..cc87923159 100644 --- a/apps/req.c +++ b/apps/req.c @@ -683,7 +683,7 @@ bad: if (keyfile != NULL) { - pkey = load_key(bio_err, keyfile, keyform, passin, e, + pkey = load_key(bio_err, keyfile, keyform, 0, passin, e, "Private Key"); if (!pkey) { diff --git a/apps/rsa.c b/apps/rsa.c index 60a3381527..4e19bc16fb 100644 --- a/apps/rsa.c +++ b/apps/rsa.c @@ -238,12 +238,12 @@ bad: if (pubin) pkey = load_pubkey(bio_err, infile, (informat == FORMAT_NETSCAPE && sgckey ? - FORMAT_IISSGC : informat), + FORMAT_IISSGC : informat), 1, passin, e, "Public Key"); else pkey = load_key(bio_err, infile, (informat == FORMAT_NETSCAPE && sgckey ? - FORMAT_IISSGC : informat), + FORMAT_IISSGC : informat), 1, passin, e, "Private Key"); if (pkey != NULL) diff --git a/apps/rsautl.c b/apps/rsautl.c index 9b02e6782e..36957e5b84 100644 --- a/apps/rsautl.c +++ b/apps/rsautl.c @@ -169,12 +169,12 @@ int MAIN(int argc, char **argv) switch(key_type) { case KEY_PRIVKEY: - pkey = load_key(bio_err, keyfile, keyform, + pkey = load_key(bio_err, keyfile, keyform, 0, NULL, e, "Private Key"); break; case KEY_PUBKEY: - pkey = load_pubkey(bio_err, keyfile, keyform, + pkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL, e, "Public Key"); break; diff --git a/apps/smime.c b/apps/smime.c index 90fe026f56..ef0e477464 100644 --- a/apps/smime.c +++ b/apps/smime.c @@ -428,7 +428,7 @@ int MAIN(int argc, char **argv) } else keyfile = NULL; if(keyfile) { - key = load_key(bio_err, keyfile, keyform, passin, e, + key = load_key(bio_err, keyfile, keyform, 0, passin, e, "signing key file"); if (!key) { goto end; diff --git a/apps/spkac.c b/apps/spkac.c index 049a37963c..4ce53e36c9 100644 --- a/apps/spkac.c +++ b/apps/spkac.c @@ -186,7 +186,7 @@ bad: if(keyfile) { pkey = load_key(bio_err, strcmp(keyfile, "-") ? keyfile : NULL, - FORMAT_PEM, passin, e, "private key"); + FORMAT_PEM, 1, passin, e, "private key"); if(!pkey) { goto end; } diff --git a/apps/x509.c b/apps/x509.c index dd98eb3b08..67476e34cf 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -861,8 +861,8 @@ bad: if (Upkey == NULL) { Upkey=load_key(bio_err, - keyfile,keyformat, passin, e, - "Private key"); + keyfile, keyformat, 0, + passin, e, "Private key"); if (Upkey == NULL) goto end; } #ifndef OPENSSL_NO_DSA @@ -884,8 +884,9 @@ bad: if (CAkeyfile != NULL) { CApkey=load_key(bio_err, - CAkeyfile,CAkeyformat, passin, - e, "CA Private Key"); + CAkeyfile, CAkeyformat, + 0, passin, e, + "CA Private Key"); if (CApkey == NULL) goto end; } #ifndef OPENSSL_NO_DSA @@ -916,8 +917,8 @@ bad: else { pk=load_key(bio_err, - keyfile,FORMAT_PEM, passin, e, - "request key"); + keyfile, FORMAT_PEM, 0, + passin, e, "request key"); if (pk == NULL) goto end; } |