summaryrefslogtreecommitdiffstats
path: root/apps/apps.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2002-08-01 16:28:40 +0000
committerRichard Levitte <levitte@openssl.org>2002-08-01 16:28:40 +0000
commitda9b97246695c370702d15be2b3778427cf57082 (patch)
tree9ef594c01fa55c710cc254495f366e6763b368fc /apps/apps.c
parentbd45950f4a85d04eb23a4d3846ed5a3c13bd19e0 (diff)
Make it possible to load keys from stdin, and restore that
functionality in the programs that had that before. Part fo PR 164
Diffstat (limited to 'apps/apps.c')
-rw-r--r--apps/apps.c38
1 files changed, 26 insertions, 12 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)
{