Commit da9b9724 authored by Richard Levitte's avatar Richard Levitte
Browse files

Make it possible to load keys from stdin, and restore that

functionality in the programs that had that before.
Part fo PR 164
parent bd45950f
Loading
Loading
Loading
Loading
+26 −12
Original line number Diff line number Diff line
@@ -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,9 +828,16 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format,
		ERR_print_errors(err);
		goto end;
		}
	if (file == NULL && maybe_stdin)
		{
		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);
			BIO_printf(err, "Error opening %s %s\n",
				key_descrip, file);
			ERR_print_errors(err);
			goto end;
			}
@@ -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,9 +904,16 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
		ERR_print_errors(err);
		goto end;
		}
	if (file == NULL && maybe_stdin)
		{
		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);
			BIO_printf(err, "Error opening %s %s\n",
				key_descrip, file);
			ERR_print_errors(err);
			goto end;
		}
+2 −2
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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)
+2 −2
Original line number Diff line number Diff line
@@ -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)
			{
+2 −2
Original line number Diff line number Diff line
@@ -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;
Loading