summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2005-05-29 08:54:14 +0000
committerDamien Miller <djm@cvs.openbsd.org>2005-05-29 08:54:14 +0000
commit2c7f95dcb85ac26b6086c5f230ae435f4f77765e (patch)
tree49cb3066cb5bf67142885b625daefab5f5533f44
parentd037b86561dc45ed839346caf57e74b5bafd5456 (diff)
replace the morally-hazardous -p option (passphrase on commandline) with a
safer, more gentle -f (passphrase in file) option; ok marius@
-rw-r--r--usr.bin/gzsig/gzsig.111
-rw-r--r--usr.bin/gzsig/sign.c26
2 files changed, 22 insertions, 15 deletions
diff --git a/usr.bin/gzsig/gzsig.1 b/usr.bin/gzsig/gzsig.1
index e2ab81718e5..6bc37e82f55 100644
--- a/usr.bin/gzsig/gzsig.1
+++ b/usr.bin/gzsig/gzsig.1
@@ -1,5 +1,5 @@
-.\" $OpenBSD: gzsig.1,v 1.3 2005/05/29 07:34:34 djm Exp $
-.\" $Id: gzsig.1,v 1.3 2005/05/29 07:34:34 djm Exp $
+.\" $OpenBSD: gzsig.1,v 1.4 2005/05/29 08:54:13 djm Exp $
+.\" $Id: gzsig.1,v 1.4 2005/05/29 08:54:13 djm Exp $
.\"
.\" Copyright (c) 2001 Dug Song <dugsong@arbor.net>
.\" Copyright (c) 2001 Arbor Networks, Inc.
@@ -41,6 +41,7 @@
.Pp
.Nm gzsig verify
.Op Fl q
+.Op Fl f Ar secret_file
.Ar pubkey
.Op Ar
.Sh DESCRIPTION
@@ -69,8 +70,10 @@ Verify the signature using the public key in
.Ar pubkey .
.It Fl q
Enable quiet mode.
-.It Fl p
-Supply a passphrase for decrypting private keys when signing.
+.It Fl f Ar secret_file
+Indicates that the passphrase for the key should be read from
+.Ar secret_file
+instead of being supplied manually.
.El
.Pp
The
diff --git a/usr.bin/gzsig/sign.c b/usr.bin/gzsig/sign.c
index 6171f1b4d7c..4373c379c49 100644
--- a/usr.bin/gzsig/sign.c
+++ b/usr.bin/gzsig/sign.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sign.c,v 1.3 2005/05/29 07:34:34 djm Exp $ */
+/* $OpenBSD: sign.c,v 1.4 2005/05/29 08:54:13 djm Exp $ */
/*
* sign.c
@@ -46,13 +46,14 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <err.h>
#include "extern.h"
#include "gzip.h"
#include "key.h"
#include "util.h"
-static char *passphrase = NULL;
+static char *passphrase_file = NULL;
static int
embed_signature(struct key *key, FILE *fin, FILE *fout)
@@ -191,10 +192,16 @@ int
sign_passwd_cb(char *buf, int size, int rwflag, void *u)
{
char *p;
+ FILE *f;
- if (passphrase != NULL) {
- if (strlcpy(buf, passphrase, size) >= size)
- errx(1, "Passphrase too long");
+ if (passphrase_file != NULL) {
+ if ((f = fopen(passphrase_file, "r")) == NULL)
+ err(1, "fopen(%.64s)", passphrase_file);
+ if (fgets(buf, size, f) == NULL)
+ err(1, "fgets(%.64s)", passphrase_file);
+ fclose(f);
+ if ((p = strchr(buf, '\n')) != NULL)
+ *p = '\0';
} else {
p = getpass("Enter passphrase: ");
if (strlcpy(buf, p, size) >= size)
@@ -215,7 +222,7 @@ sign(int argc, char *argv[])
qflag = 0;
- while ((i = getopt(argc, argv, "qvh?p:")) != -1) {
+ while ((i = getopt(argc, argv, "qvh?f:")) != -1) {
switch (i) {
case 'q':
qflag = 1;
@@ -223,8 +230,8 @@ sign(int argc, char *argv[])
case 'v':
qflag = 0;
break;
- case 'p':
- passphrase = optarg;
+ case 'f':
+ passphrase_file = optarg;
break;
default:
sign_usage();
@@ -303,7 +310,4 @@ sign(int argc, char *argv[])
}
}
key_free(key);
-
- if (passphrase != NULL)
- memset(passphrase, 0, strlen(passphrase));
}