version 1.21, 2014/01/09 21:19:38 |
version 1.22, 2014/01/10 04:15:38 |
|
|
fprintf(stderr, "usage:" |
fprintf(stderr, "usage:" |
#ifndef VERIFYONLY |
#ifndef VERIFYONLY |
"\t%s [-n] -p pubkey -s seckey -G\n" |
"\t%s [-n] -p pubkey -s seckey -G\n" |
|
"\t%s [-o sig] [-p pubkey] [-s seckey] -I\n" |
"\t%s [-e] [-o output] -s seckey -S message\n" |
"\t%s [-e] [-o output] -s seckey -S message\n" |
#endif |
#endif |
"\t%s [-e] [-o output] -p pubkey -V message\n", |
"\t%s [-e] [-o output] -p pubkey -V message\n", |
#ifndef VERIFYONLY |
#ifndef VERIFYONLY |
__progname, __progname, |
__progname, __progname, __progname, |
#endif |
#endif |
__progname); |
__progname); |
exit(1); |
exit(1); |
|
|
|
|
free(msg); |
free(msg); |
} |
} |
|
|
|
static void |
|
inspect(const char *seckeyfile, const char *pubkeyfile, const char *sigfile) |
|
{ |
|
struct sig sig; |
|
struct enckey enckey; |
|
struct pubkey pubkey; |
|
char fp[(FPLEN + 2) / 3 * 4 + 1]; |
|
|
|
if (seckeyfile) { |
|
readb64file(seckeyfile, &enckey, sizeof(enckey), NULL); |
|
b64_ntop(enckey.fingerprint, FPLEN, fp, sizeof(fp)); |
|
printf("sec fp: %s\n", fp); |
|
} |
|
if (pubkeyfile) { |
|
readb64file(pubkeyfile, &pubkey, sizeof(pubkey), NULL); |
|
b64_ntop(pubkey.fingerprint, FPLEN, fp, sizeof(fp)); |
|
printf("pub fp: %s\n", fp); |
|
} |
|
if (sigfile) { |
|
readb64file(sigfile, &sig, sizeof(sig), NULL); |
|
b64_ntop(sig.fingerprint, FPLEN, fp, sizeof(fp)); |
|
printf("sig fp: %s\n", fp); |
|
} |
|
} |
#endif |
#endif |
|
|
static void |
static void |
|
|
readb64file(sigfile, &sig, sizeof(sig), NULL); |
readb64file(sigfile, &sig, sizeof(sig), NULL); |
} |
} |
|
|
if (memcmp(pubkey.fingerprint, sig.fingerprint, FPLEN)) |
if (memcmp(pubkey.fingerprint, sig.fingerprint, FPLEN)) { |
|
#ifndef VERIFYONLY |
|
inspect(NULL, pubkeyfile, sigfile); |
|
#endif |
errx(1, "verification failed: checked against wrong key"); |
errx(1, "verification failed: checked against wrong key"); |
|
} |
|
|
verifymsg(pubkey.pubkey, msg, msglen, sig.sig); |
verifymsg(pubkey.pubkey, msg, msglen, sig.sig); |
if (embedded) { |
if (embedded) { |
|
|
enum { |
enum { |
NONE, |
NONE, |
GENERATE, |
GENERATE, |
|
INSPECT, |
SIGN, |
SIGN, |
VERIFY |
VERIFY |
} verb = NONE; |
} verb = NONE; |
|
|
|
|
rounds = 42; |
rounds = 42; |
|
|
while ((ch = getopt(argc, argv, "GSVeno:p:s:")) != -1) { |
while ((ch = getopt(argc, argv, "GISVeno:p:s:")) != -1) { |
switch (ch) { |
switch (ch) { |
#ifndef VERIFYONLY |
#ifndef VERIFYONLY |
case 'G': |
case 'G': |
|
|
usage(); |
usage(); |
verb = GENERATE; |
verb = GENERATE; |
break; |
break; |
|
case 'I': |
|
if (verb) |
|
usage(); |
|
verb = INSPECT; |
|
break; |
case 'S': |
case 'S': |
if (verb) |
if (verb) |
usage(); |
usage(); |
|
|
if (!pubkeyfile || !seckeyfile || argc != 0) |
if (!pubkeyfile || !seckeyfile || argc != 0) |
usage(); |
usage(); |
generate(pubkeyfile, seckeyfile, rounds); |
generate(pubkeyfile, seckeyfile, rounds); |
|
} else if (verb == INSPECT) { |
|
if (argc != 0) |
|
usage(); |
|
inspect(seckeyfile, pubkeyfile, sigfile); |
} else |
} else |
#endif |
#endif |
{ |
{ |