summaryrefslogtreecommitdiff
path: root/usr.bin/signify/signify.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-05-14 15:52:25 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-05-14 15:52:25 +0000
commit16412b3e014514713c7561174b0088b152140980 (patch)
tree79b5ee321fb627f97717f504654aebca5d4754ca /usr.bin/signify/signify.c
parent7bd84baef08d2b7ae881873f42f4f4a0ed019951 (diff)
recode base64 hashes if necessary
Diffstat (limited to 'usr.bin/signify/signify.c')
-rw-r--r--usr.bin/signify/signify.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c
index 0e0101d43c4..64d51503150 100644
--- a/usr.bin/signify/signify.c
+++ b/usr.bin/signify/signify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: signify.c,v 1.79 2014/05/14 15:33:41 tedu Exp $ */
+/* $OpenBSD: signify.c,v 1.80 2014/05/14 15:52:24 tedu Exp $ */
/*
* Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
*
@@ -538,6 +538,21 @@ struct checksum {
};
static void
+recodehash(char *hash)
+{
+ uint8_t data[512];
+ int i, rv;
+
+ if (strlen(hash) == SHA256_DIGEST_STRING_LENGTH ||
+ strlen(hash) == SHA512_DIGEST_STRING_LENGTH)
+ return;
+ if ((rv = b64_pton(hash, data, sizeof(data))) == -1)
+ errx(1, "invalid base64 encoding");
+ for (i = 0; i < rv; i++)
+ snprintf(hash + i * 2, 1024 - i * 2, "%2.2x", data[i]);
+}
+
+static void
verifychecksums(char *msg, int argc, char **argv, int quiet)
{
char buf[1024];
@@ -562,6 +577,7 @@ verifychecksums(char *msg, int argc, char **argv, int quiet)
c->algo, buf, c->hash);
if (rv != 3 || buf[0] != '(' || buf[strlen(buf) - 1] != ')')
errx(1, "unable to parse checksum line %s", line);
+ recodehash(c->hash);
buf[strlen(buf) - 1] = 0;
strlcpy(c->file, buf + 1, sizeof(c->file));
line = endline;