xref: /inferno-os/appl/cmd/auth/countersigner.b (revision 66f5808b81b1df84bc57c4f7b9d487201bc162fb)
1implement Countersigner;
2
3include "sys.m";
4	sys: Sys;
5
6include "draw.m";
7	draw: Draw;
8
9include "keyring.m";
10	kr: Keyring;
11
12include "msgio.m";
13	msgio: Msgio;
14
15include "security.m";
16
17Countersigner: module
18{
19	init:	fn(ctxt: ref Draw->Context, argv: list of string);
20};
21
22stderr, stdin, stdout: ref Sys->FD;
23
24init(nil: ref Draw->Context, nil: list of string)
25{
26	sys = load Sys Sys->PATH;
27	kr = load Keyring Keyring->PATH;
28	msgio = load Msgio Msgio->PATH;
29	msgio->init();
30
31	stdin = sys->fildes(0);
32	stdout = sys->fildes(1);
33	stderr = sys->fildes(2);
34
35	sys->pctl(Sys->FORKNS, nil);
36	if(sys->chdir("/keydb") < 0){
37		sys->fprint(stderr, "countersigner: no key database\n");
38		raise "fail:no keydb";
39	}
40
41	# get boxid
42	buf := msgio->getmsg(stdin);
43	if(buf == nil){
44		sys->fprint(stderr, "countersigner: client hung up\n");
45		raise "fail:hungup";
46	}
47	boxid := string buf;
48
49	# read file
50	file := "countersigned/"+boxid;
51	fd := sys->open(file, Sys->OREAD);
52	if(fd == nil){
53		sys->fprint(stderr, "countersigner: can't open %s: %r\n", file);
54		raise "fail:bad boxid";
55	}
56	blind := msgio->getmsg(fd);
57	if(blind == nil){
58		sys->fprint(stderr, "countersigner: can't read %s\n", file);
59		raise "fail:no blind";
60	}
61
62	# answer client
63	msgio->sendmsg(stdout, blind, len blind);
64}
65