From f2adbe288d6357fe50228ee0dd091282eecda915 Mon Sep 17 00:00:00 2001 From: tedu Date: Mon, 13 Jan 2014 01:40:43 +0000 Subject: [PATCH] new day, new options. -m message and -x signature. this should be less confusing and more consistent in various modes. also support stdin/stdout where feasible. touch up usage to be helpful. ok deraadt --- usr.bin/signify/Makefile | 3 +- usr.bin/signify/signify.1 | 54 +++++++++++++++----------- usr.bin/signify/signify.c | 81 ++++++++++++++++++++++----------------- 3 files changed, 79 insertions(+), 59 deletions(-) diff --git a/usr.bin/signify/Makefile b/usr.bin/signify/Makefile index 3f9f3ff1b7e..f09c0dc45a7 100644 --- a/usr.bin/signify/Makefile +++ b/usr.bin/signify/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.7 2014/01/10 04:28:57 tedu Exp $ +# $OpenBSD: Makefile,v 1.8 2014/01/13 01:40:43 tedu Exp $ .PATH: ${.CURDIR}/../ssh CPPFLAGS += -I${.CURDIR}/../ssh @@ -7,6 +7,7 @@ SRCS= signify.c SRCS+= fe25519.c sc25519.c smult_curve25519_ref.c SRCS+= mod_ed25519.c mod_ge25519.c SRCS+= crypto_api.c +SRCS+= base64.c PROG= signify diff --git a/usr.bin/signify/signify.1 b/usr.bin/signify/signify.1 index ea254608462..e7680236638 100644 --- a/usr.bin/signify/signify.1 +++ b/usr.bin/signify/signify.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: signify.1,v 1.18 2014/01/12 17:17:12 rpe Exp $ +.\" $OpenBSD: signify.1,v 1.19 2014/01/13 01:40:43 tedu Exp $ .\" .\"Copyright (c) 2013 Marc Espie .\"Copyright (c) 2013 Ted Unangst @@ -14,7 +14,7 @@ .\"WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\"ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\"OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.Dd $Mdocdate: January 12 2014 $ +.Dd $Mdocdate: January 13 2014 $ .Dt SIGNIFY 1 .Os .Sh NAME @@ -29,26 +29,26 @@ .Fl s Ar seckey .Nm signify .Fl I -.Op Fl o Ar sigfile .Op Fl p Ar pubkey .Op Fl s Ar seckey +.Op Fl x Ar sigfile .Nm signify .Fl S .Op Fl e -.Op Fl o Ar sigfile +.Op Fl x Ar sigfile .Fl s Ar seckey -.Ar message +.Fl m Ar message .Nm signify .Fl V .Op Fl e -.Op Fl o Ar sigfile +.Op Fl x Ar sigfile .Fl p Ar pubkey -.Ar message +.Fl m Ar message .Sh DESCRIPTION The .Nm -utility creates and verifies cryptographic signatures for -an input file +utility creates and verifies cryptographic signatures. +A signature verifies the integrity of a .Ar message . The mode of operation is selected with the following options: .Bl -tag -width Dsssigfile @@ -57,9 +57,9 @@ Generate a new keypair. .It Fl I Inspect the specified keys or signature and print their fingerprint. .It Fl S -Sign the input file. +Sign the specified message file and create a signature. .It Fl V -Verify the input file and signature match. +Verify the message and signature match. .El .Pp The other options are as follows: @@ -67,17 +67,22 @@ The other options are as follows: .It Fl c Ar comment Specify the comment to be added during key generation. .It Fl e -Embed the message after the signature when signing. -For verification, extract the message from the signature. +When signing, embed the message after the signature. +When verifying, extract the message from the signature. +(This requires that the signature was created using +.Fl e +and creates a new message file as output.) +.It Fl m Ar message +When signing, the file containing the message to sign. +When verifying, the file containing the message to verify. +When verifying with +.Fl e , +the file to create. .It Fl n Do not ask for a passphrase during key generation. Otherwise, .Nm -will prompt the user for a passphrase on the terminal. -.It Fl o Ar sigfile -The signature file to create or verify. -The default is -.Ar message Ns .sig . +will prompt the user for a passphrase to protect the secret key. .It Fl p Ar pubkey Public key produced by .Fl G , @@ -90,6 +95,10 @@ Secret (private) key produced by and used by .Fl S to sign a message. +.It Fl x Ar sigfile +The signature file to create or verify. +The default is +.Ar message Ns .sig . .El .Pp The key and signature files created by @@ -117,16 +126,15 @@ Create a new keypair: .Dl $ signify -G -p newkey.pub -s newkey.sec .Pp Sign a file, specifying a signature name: -.Dl $ signify -S -s key.sec -o msg.sig message.txt +.Dl $ signify -S -s key.sec -m message.txt -x msg.sig .Pp Verify a signature, using the default signature name: -.Dl $ signify -V -p key.pub generalsorders.txt +.Dl $ signify -V -p key.pub -m generalsorders.txt .Pp Verify a release directory containing -.Pa SHA256.sig , -.Pa SHA256 , +.Pa SHA256.sig and a full set of release files: -.Dl $ signify -V -p /etc/signify/55base.pub SHA256 && sha256 -c SHA256 +.Dl $ signify -V -e -p /etc/signify/55base.pub -x SHA256.sig -m - && sha256 -c - .Sh SEE ALSO .Xr fw_update 1 , .Xr pkg_add 1 , diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c index 15bd6dcd4f8..f018921edec 100644 --- a/usr.bin/signify/signify.c +++ b/usr.bin/signify/signify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: signify.c,v 1.30 2014/01/12 21:18:52 tedu Exp $ */ +/* $OpenBSD: signify.c,v 1.31 2014/01/13 01:40:43 tedu Exp $ */ /* * Copyright (c) 2013 Ted Unangst * @@ -68,15 +68,17 @@ struct sig { extern char *__progname; static void -usage(void) +usage(const char *error) { + if (error) + fprintf(stderr, "%s\n", error); fprintf(stderr, "usage:" #ifndef VERIFYONLY - "\t%1$s -G [-c comment] [-n] -p pubkey -s seckey\n" - "\t%1$s -I [-o sigfile] [-p pubkey] [-s seckey]\n" - "\t%1$s -S [-e] [-o sigfile] -s seckey message\n" + "\t%1$s -G [-n] [-c comment] -p pubkey -s seckey\n" + "\t%1$s -I [-p pubkey] [-s seckey] [-x sigfile]\n" + "\t%1$s -S [-e] [-x sigfile] -s seckey -m message\n" #endif - "\t%1$s -V [-e] [-o sigfile] -p pubkey message\n", + "\t%1$s -V [-e] [-x sigfile] -p pubkey -m message\n", __progname); exit(1); } @@ -86,9 +88,19 @@ xopen(const char *fname, int flags, mode_t mode) { int fd; - fd = open(fname, flags, mode); - if (fd == -1) - err(1, "open %s", fname); + if (strcmp(fname, "-") == 0) { + if ((flags & O_WRONLY)) + fd = dup(STDOUT_FILENO); + else + fd = dup(STDIN_FILENO); + if (fd == -1) + err(1, "dup failed"); + } else { + fd = open(fname, flags, mode); + if (fd == -1) + err(1, "can't open %s for %s", fname, + (flags & O_WRONLY) ? "writing" : "reading"); + } return fd; } @@ -216,8 +228,7 @@ writeb64file(const char *filename, const char *comment, const void *buf, int fd, rv; fd = xopen(filename, O_CREAT|flags|O_NOFOLLOW|O_WRONLY, mode); - snprintf(header, sizeof(header), "%s%s\n", COMMENTHDR, - comment); + snprintf(header, sizeof(header), "%s%s\n", COMMENTHDR, comment); writeall(fd, header, strlen(header), filename); if ((rv = b64_ntop(buf, len, b64, sizeof(b64)-1)) == -1) errx(1, "b64 encode failed"); @@ -451,28 +462,28 @@ main(int argc, char **argv) rounds = 42; - while ((ch = getopt(argc, argv, "GISVc:eno:p:s:")) != -1) { + while ((ch = getopt(argc, argv, "GISVc:em:n:p:s:x:")) != -1) { switch (ch) { #ifndef VERIFYONLY case 'G': if (verb) - usage(); + usage(NULL); verb = GENERATE; break; case 'I': if (verb) - usage(); + usage(NULL); verb = INSPECT; break; case 'S': if (verb) - usage(); + usage(NULL); verb = SIGN; break; #endif case 'V': if (verb) - usage(); + usage(NULL); verb = VERIFY; break; case 'c': @@ -481,51 +492,51 @@ main(int argc, char **argv) case 'e': embedded = 1; break; + case 'm': + msgfile = optarg; + break; case 'n': rounds = 0; break; - case 'o': - sigfile = optarg; - break; case 'p': pubkeyfile = optarg; break; case 's': seckeyfile = optarg; break; + case 'x': + sigfile = optarg; + break; default: - usage(); + usage(NULL); break; } } argc -= optind; argv += optind; -#ifdef VERIFYONLY - if (verb != VERIFY) -#else + if (argc != 0) + usage(NULL); + if (verb == NONE) -#endif - usage(); + usage(NULL); #ifndef VERIFYONLY if (verb == GENERATE) { - if (!pubkeyfile || !seckeyfile || argc != 0) - usage(); + if (!pubkeyfile || !seckeyfile) + usage("need pubkey and seckey"); generate(pubkeyfile, seckeyfile, rounds, comment); } else if (verb == INSPECT) { - if (argc != 0) - usage(); inspect(seckeyfile, pubkeyfile, sigfile); } else #endif { - if (argc != 1) - usage(); - - msgfile = argv[0]; + if (!msgfile) + usage("need message"); if (!sigfile) { + if (strcmp(msgfile, "-") == 0) + errx(1, "must specify sigfile with - message"); if (snprintf(sigfilebuf, sizeof(sigfilebuf), "%s.sig", msgfile) >= sizeof(sigfilebuf)) errx(1, "path too long"); @@ -534,13 +545,13 @@ main(int argc, char **argv) #ifndef VERIFYONLY if (verb == SIGN) { if (!seckeyfile) - usage(); + usage("need seckey"); sign(seckeyfile, msgfile, sigfile, embedded); } else #endif if (verb == VERIFY) { if (!pubkeyfile) - usage(); + usage("need pubkey"); verify(pubkeyfile, msgfile, sigfile, embedded); } } -- 2.20.1