summaryrefslogtreecommitdiff
path: root/appl/cmd/auth/countersigner.b
blob: 57e4388d388143261edf3fc40086eb3be4131ce3 (plain)
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
64
implement Countersigner;

include "sys.m";
	sys: Sys;

include "draw.m";
	draw: Draw;

include "keyring.m";
	kr: Keyring;

include "msgio.m";
	msgio: Msgio;

include "security.m";

Countersigner: module
{
	init:	fn(ctxt: ref Draw->Context, argv: list of string);
};

stderr, stdin, stdout: ref Sys->FD;

init(nil: ref Draw->Context, nil: list of string)
{
	sys = load Sys Sys->PATH;
	kr = load Keyring Keyring->PATH;
	msgio = load Msgio Msgio->PATH;
	msgio->init();

	stdin = sys->fildes(0);
	stdout = sys->fildes(1);
	stderr = sys->fildes(2);

	sys->pctl(Sys->FORKNS, nil);
	if(sys->chdir("/keydb") < 0){
		sys->fprint(stderr, "countersigner: no key database\n");
		raise "fail:no keydb";
	}

	# get boxid
	buf := msgio->getmsg(stdin);
	if(buf == nil){
		sys->fprint(stderr, "countersigner: client hung up\n");
		raise "fail:hungup";
	}
	boxid := string buf;

	# read file
	file := "countersigned/"+boxid;
	fd := sys->open(file, Sys->OREAD);
	if(fd == nil){
		sys->fprint(stderr, "countersigner: can't open %s: %r\n", file);
		raise "fail:bad boxid";
	}
	blind := msgio->getmsg(fd);
	if(blind == nil){
		sys->fprint(stderr, "countersigner: can't read %s\n", file);
		raise "fail:no blind";
	}

	# answer client
	msgio->sendmsg(stdout, blind, len blind);
}