7 enum{ BufSize = 8192 };
9 char *remotesys, *logfile;
21 postnote(PNGROUP, pid, "die");
22 postnote(PNGROUP, pid, "die");
23 postnote(PNGROUP, pid, "die");
28 dump(int fd, uchar *buf, int n, char *label)
33 Binit(&bout, fd, OWRITE);
34 Bprint(&bout, "%s<%d>: ", label, n);
37 for(i = 0; i < n; i++)
38 Bprint(&bout, "%2.2x ", buf[i]);
44 xfer(int from, int to, int cfd, char *label)
54 n = read(from, buf, sizeof(buf));
56 fprint(2, "%s EOF\n", label);
61 dump(2, buf, n, label);
62 n = write(to, buf, n);
64 fprint(2, "%s write err\n", label);
78 sysfatal("can't make pipe: %r");
80 xfer(fd, p[0], p[1], "read");
81 xfer(p[0], fd, p[1], "write");
87 reporter(char *fmt, ...)
94 vsnprint(buf, sizeof buf, fmt, ap);
95 syslog(0, logfile, "%s tls reports %s", remotesys, buf);
97 fprint(2, "%s: %s tls reports ", argv0, remotesys);
108 fprint(2, "usage: tlssrv -c cert [-D] [-l logfile] [-r remotesys] [cmd args...]\n");
109 fprint(2, " after auth/secretpem key.pem > /mnt/factotum/ctl\n");
114 main(int argc, char *argv[])
130 cert = EARGF(usage());
133 logfile = EARGF(usage());
136 remotesys = EARGF(usage());
143 sysfatal("no certificate specified");
146 conn = (TLSconn*)mallocz(sizeof *conn, 1);
148 sysfatal("out of memory");
149 conn->chain = readcertchain(cert);
150 if (conn->chain == nil)
151 sysfatal("can't read certificate");
152 conn->cert = conn->chain->pem;
153 conn->certlen = conn->chain->pemlen;
154 conn->chain = conn->chain->next;
156 conn->trace = reporter;
162 fd = tlsServer(fd, conn);
164 reporter("failed: %r");
180 reporter("can't exec %s: %r", argv[0]);
193 switch(rfork(RFPROC)){
195 sysfatal("can't fork");
198 n = read(clearfd, buf, BufSize);
201 if(write(fd, buf, n) != n)
207 n = read(fd, buf, BufSize);
210 if(write(clearfd, buf, n) != n)