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
59
60
61
62
63
|
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <auth.h>
#include <mp.h>
#include <libsec.h>
int fd;
int req = 0;
char subject[1024];
void
usage(void)
{
fprint(2, "usage: auth/x5092pub [-r] [file]\n");
exits("usage");
}
void
main(int argc, char **argv)
{
int tot, n;
uchar *buf;
RSApub *pub;
quotefmtinstall();
fmtinstall('B', mpfmt);
fmtinstall('H', encodefmt);
ARGBEGIN{
case 'r':
req = 1;
break;
default:
usage();
}ARGEND
fd = 0;
if(argc == 1)
fd = open(argv[0], OREAD);
else if(argc != 0)
usage();
buf = nil;
tot = 0;
for(;;){
buf = realloc(buf, tot+8192);
if(buf == nil)
sysfatal("realloc: %r");
if((n = read(fd, buf+tot, 8192)) < 0)
sysfatal("read: %r");
if(n == 0)
break;
tot += n;
}
if(req)
pub = X509reqtoRSApub(buf, tot, subject, sizeof(subject));
else
pub = X509toRSApub(buf, tot, subject, sizeof(subject));
if(pub == nil)
sysfatal("X509toRSApub: %r");
print("key proto=rsa size=%d ek=%B n=%B subject=%q \n", mpsignif(pub->n), pub->ek, pub->n, subject);
exits(nil);
}
|