-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnskey.c
58 lines (53 loc) · 1.21 KB
/
dnskey.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include "dnssec.h"
#include "arg.h"
static void
usage(void)
{
fprintf(stderr, "usage: dnskey [-k] [-a algorithm] [-t ttl] [-c class] domain keyfile\n");
exit(2);
}
int
main(int argc, char *argv[])
{
int algorithm = 0, class = CLASS_IN, flags = DNSKEY_ZONE;
unsigned long ttl = 0;
char *end;
ARGBEGIN {
case 'a':
algorithm = algorithm_from_string(EARGF(usage()));
break;
case 'k':
flags |= DNSKEY_SEP;
break;
case 't':
ttl = strtoul(EARGF(usage()), &end, 10);
if (*end)
errx(1, "invalid TTL");
break;
case 'c':
class = class_from_string(EARGF(usage()));
break;
default:
usage();
} ARGEND
if (argc != 2)
usage();
struct key *sk = key_new_from_file(argv[1], algorithm);
struct dnskey *pk = dnskey_new(flags, sk);
fputs(argv[0], stdout);
if (ttl)
printf("\t%lu", ttl);
printf("\t%s\tDNSKEY\t%u %d %d ", class_to_string(class), pk->flags, pk->protocol, pk->algorithm);
for (size_t i = 0; i < pk->data_len; i += 300) {
char data[401];
base64_encode(data, pk->data + i, i + 300 < pk->data_len ? 300 : pk->data_len - i);
fputs(data, stdout);
}
putchar('\n');
fflush(stdout);
if (ferror(stdout))
errx(1, "write failed");
}