sigchk

sign and check files using ed25519
git clone git://z3bra.org/sick
Log | Files | Refs | Submodules | README | LICENSE

commit 8b077cdef13a6abd89c5c7e534ff6863ffd7ca0c
parent f24100e00e4478ecd96f036089af37618a36c302
Author: z3bra <willyatmailoodotorg>
Date:   Thu Apr 28 02:00:41 2016

Add verbose output

Diffstat:
 sick.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/sick.c b/sick.c @@ -36,10 +36,12 @@ int sign(char *file, char *key); int verify(char *file, char *key); int check(char *file, char *keyring); +int verbose = 0; + void usage(char *name) { - fprintf(stderr, "usage: %s [-cgs] [-f key] [file]\n", name); + fprintf(stderr, "usage: %s [-cgsv] [-f key] [file]\n", name); exit(1); } @@ -97,6 +99,8 @@ genkey(char *alias) /* write pubkey to a file name <alias>.pub */ memcpy(file+len, ".pub", 4); + if (verbose) + printf("Creating public key: %s\n", file); fd = open(file, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd < 0) { perror(file); @@ -110,6 +114,8 @@ genkey(char *alias) /* write privkey to a file name <alias>.key */ memcpy(file+len, ".key", 4); + if (verbose) + printf("Creating private key: %s\n", file); fd = open(file, O_CREAT|O_WRONLY|O_TRUNC, 0600); if (fd < 0) { perror(file); @@ -160,6 +166,8 @@ sign(char *file, char *key) ed25519_sign(sig, msg, len + 1, priv); /* write signature at the end of the file */ + if (verbose) + printf("Appending signature to %s\n", file); fd = open(file, O_WRONLY|O_APPEND); if (fd < 0) { perror(file); @@ -208,6 +216,9 @@ verify(char *file, char *key) check = ed25519_verify(sig, msg, len + 1, pub) ? 0 : -1; + if (verbose) + printf("%s: %s\n", key, check == 0 ? "VERIFIED" : "FAILED"); + free (msg); return check; } @@ -226,6 +237,9 @@ check(char *file, char *keyring) return -1; } + if (verbose) + printf("Openning keyring %s\n", keyring); + while ((dt = readdir(dirp)) != NULL) { if (dt->d_type == DT_REG) { len = strnlen(keyring, PATH_MAX); @@ -268,6 +282,9 @@ main(int argc, char **argv) case 's': action = ACTION_SIGN; break; + case 'v': + verbose = 1; + break; default: usage(argv0); }ARGEND; @@ -275,17 +292,22 @@ main(int argc, char **argv) switch(action) { case ACTION_CHECK: if (check(*argv, keyring) == 0) { - puts(*argv); + if (!verbose) + puts(*argv); + } else { + return 1; } break; case ACTION_GENKEY: genkey(key); break; case ACTION_SIGN: + /* TODO: only check the pubkey matchng the private */ if (check(*argv, keyring) != 0) { sign(*argv, key ? key : DEFAULT_ALIAS ".key"); } else { - fprintf(stderr, "%s: already signed\n", *argv); + fprintf(stderr, "%s: Already signed\n", *argv); + return -1; } break; default: