Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_tlsv12/sys/src/cmd/auth/asn12rsa.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <bio.h>
4
#include <mp.h>
5
#include <libsec.h>
6
 
7
void
8
usage(void)
9
{
10
	fprint(2, "auth/asn12rsa [-t tag] [file]\n");
11
	exits("usage");
12
}
13
 
14
void
15
main(int argc, char **argv)
16
{
17
	char *s;
18
	uchar *buf;
19
	int fd;
20
	long n, tot;
21
	char *tag, *file;
22
	RSApriv *key;
23
 
24
	fmtinstall('B', mpfmt);
25
 
26
	tag = nil;
27
	ARGBEGIN{
28
	case 't':
29
		tag = EARGF(usage());
30
		break;
31
	default:
32
		usage();
33
	}ARGEND
34
 
35
	if(argc != 0 && argc != 1)
36
		usage();
37
 
38
	if(argc == 1)
39
		file = argv[0];
40
	else
41
		file = "#d/0";
42
 
43
	if((fd = open(file, OREAD)) < 0)
44
		sysfatal("open %s: %r", file);
45
	buf = nil;
46
	tot = 0;
47
	for(;;){
48
		buf = realloc(buf, tot+8192);
49
		if(buf == nil)
50
			sysfatal("realloc: %r");
51
		if((n = read(fd, buf+tot, 8192)) < 0)
52
			sysfatal("read: %r");
53
		if(n == 0)
54
			break;
55
		tot += n;
56
	}
57
 
58
	key = asn1toRSApriv(buf, tot);
59
	if(key == nil)
60
		sysfatal("couldn't parse asn1 key");
61
 
62
	s = smprint("key proto=rsa %s%ssize=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
63
		tag ? tag : "", tag ? " " : "",
64
		mpsignif(key->pub.n), key->pub.ek,
65
		key->dk, key->pub.n, key->p, key->q,
66
		key->kp, key->kq, key->c2);
67
	if(s == nil)
68
		sysfatal("smprint: %r");
69
	write(1, s, strlen(s));
70
	exits(0);
71
}