sigchk

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

commit 90d54f352d87fa5d78ad774fbf13f6039dc825dd
parent e21dd3ee49a2fbb43726a63446f6d81cf25bf971
Author: z3bra <willyatmailoodotorg>
Date:   Fri Apr 29 20:39:31 2016

Implement unsign() to remove the signature from a file

Diffstat:
 sick.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/sick.c b/sick.c @@ -25,6 +25,7 @@ enum { ACTION_GENKEY, ACTION_SIGN, ACTION_CHECK, + ACTION_UNSIGN, ACTION_DEFAULT = ACTION_CHECK }; @@ -33,6 +34,7 @@ void usage(char *name); char *base_name(char *path); int check_magic(char *file); unsigned char *read_sig(char *file); +int unsign(char *file); int keygen(char *alias); int sign(char *file, char *key); int verify(char *file, char *key); @@ -43,7 +45,7 @@ int verbose = 0; void usage(char *name) { - fprintf(stderr, "usage: %s [-cgsv] [-f key] [file]\n", name); + fprintf(stderr, "usage: %s [-f key] [-cgsuv] [file]\n", name); exit(1); } @@ -81,6 +83,9 @@ check_magic(char *file) is_magic = strcmp(magic, MAGIC); + if (verbose) + printf("%s: %s\n", file, is_magic ? "not signed" : "signed"); + free(magic); return is_magic; } @@ -110,6 +115,35 @@ read_sig(char *file) } +/* + * Fucking yankees took the revoke() name... + * Truncate a file to remove the signature. Will only perform if the magic + * string is found + */ +int +unsign(char *file) +{ + size_t len = 0; + struct stat sb; + + if (check_magic(file)) { + return -1; + } + + if (stat(file, &sb) < 0) { + perror(file); + return NULL; + } + + len = sb.st_size - 64 - strlen(MAGIC); + + if (truncate(file, len) < 0) { + perror(file); + return -1; + } + return 0; +} + int keygen(char *alias) { @@ -272,7 +306,6 @@ check(char *file, char *keyring) if (check_magic(file) != 0) { - fprintf(stderr, "%s: Not signed\n", file); return -1; } @@ -283,7 +316,7 @@ check(char *file, char *keyring) } if (verbose) - printf("Openning keyring %s\n", keyring); + printf(": %s\n", keyring); while ((dt = readdir(dirp)) != NULL) { if (dt->d_type == DT_REG) { @@ -327,6 +360,9 @@ main(int argc, char **argv) case 's': action = ACTION_SIGN; break; + case 'u': + action = ACTION_UNSIGN; + break; case 'v': verbose = 1; break; @@ -346,6 +382,9 @@ main(int argc, char **argv) case ACTION_GENKEY: keygen(key); break; + case ACTION_UNSIGN: + unsign(*argv); + break; case ACTION_SIGN: /* TODO: only check the pubkey matchng the private */ if (check_magic(*argv) != 0) { @@ -360,4 +399,4 @@ main(int argc, char **argv) } return 0; -}- \ No newline at end of file +}