functionality in the programs that had that before.
Part fo PR 164
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;
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;
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);
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;
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;
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)
{
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);
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)
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)
{
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;
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;
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;
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);
}
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)
{
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)
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;
} 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;
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;
}
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
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
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;
}