summaryrefslogtreecommitdiff
path: root/usr.bin/signify
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2014-01-09 20:37:26 +0000
committerMarc Espie <espie@cvs.openbsd.org>2014-01-09 20:37:26 +0000
commit44676d468d56778de7ec7bc950c61d0893e24a8e (patch)
tree5819cde47b8d0e5f1be0eb0db6dcc84e3b9d9656 /usr.bin/signify
parent20c8fb077fabca27fdc1b4ff351ab894a4a003a3 (diff)
revert to O_EXCL for generating keys, so we don't erase them by accident.
internal code a bit yucky, can be fixed some more later. okay tedu@
Diffstat (limited to 'usr.bin/signify')
-rw-r--r--usr.bin/signify/signify.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c
index bf0fd3ebb22..0400168af42 100644
--- a/usr.bin/signify/signify.c
+++ b/usr.bin/signify/signify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: signify.c,v 1.19 2014/01/09 19:05:21 tedu Exp $ */
+/* $OpenBSD: signify.c,v 1.20 2014/01/09 20:37:25 espie Exp $ */
/*
* Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
*
@@ -208,13 +208,13 @@ appendall(const char *filename, const void *buf, size_t len)
static void
writeb64file(const char *filename, const char *comment, const void *buf,
- size_t len, mode_t mode)
+ size_t len, int flags, mode_t mode)
{
char header[1024];
char b64[1024];
int fd, rv;
- fd = xopen(filename, O_CREAT|O_TRUNC|O_NOFOLLOW|O_RDWR, mode);
+ fd = xopen(filename, O_CREAT|flags|O_NOFOLLOW|O_RDWR, mode);
snprintf(header, sizeof(header), "%ssignify %s\n", COMMENTHDR,
comment);
writeall(fd, header, strlen(header), filename);
@@ -288,13 +288,13 @@ generate(const char *pubkeyfile, const char *seckeyfile, int rounds)
memset(xorkey, 0, sizeof(xorkey));
writeb64file(seckeyfile, "secret key", &enckey,
- sizeof(enckey), 0600);
+ sizeof(enckey), O_EXCL, 0600);
memset(&enckey, 0, sizeof(enckey));
memcpy(pubkey.pkalg, PKALG, 2);
memcpy(pubkey.fingerprint, fingerprint, FPLEN);
writeb64file(pubkeyfile, "public key", &pubkey,
- sizeof(pubkey), 0666);
+ sizeof(pubkey), O_EXCL, 0666);
}
static void
@@ -335,7 +335,7 @@ sign(const char *seckeyfile, const char *msgfile, const char *sigfile,
memcpy(sig.pkalg, PKALG, 2);
snprintf(sigcomment, sizeof(sigcomment), "signature from %s", comment);
- writeb64file(sigfile, sigcomment, &sig, sizeof(sig), 0666);
+ writeb64file(sigfile, sigcomment, &sig, sizeof(sig), O_TRUNC, 0666);
if (embedded)
appendall(sigfile, msg, msglen);