#include #include /* * https://code.google.com/p/plan9front/source/detail?r=7bb3e313fdc5c501988f4c58251f70bbd27bafe4 */ int mypushssl(int fd, char *alg, uchar *secret, int nsecret) { int ctl, data, secin, secout; char buf[8], dname[64], secinname[64], secoutname[64]; int n; if((ctl = open("#D/ssl/clone", ORDWR)) < 0) { werrstr("open clone: %r"); return -1; } if((n = read(ctl, buf, sizeof(buf) - 1)) < 0) { werrstr("read ctl: %r"); goto cleanupctl; } buf[n] = '\0'; sprint(dname, "#D/ssl/%s/data", buf); sprint(secinname, "#D/ssl/%s/secretin", buf); sprint(secoutname, "#D/ssl/%s/secretout", buf); if((data = open(dname, ORDWR)) < 0) { werrstr("open data: %r"); goto cleanupctl; } if((secin = open(secinname, OWRITE)) < 0) { werrstr("open secretin: %r"); goto cleanupdata; } if(write(secin, secret, nsecret) != nsecret) { werrstr("write secretin: %r"); goto cleanupdata; } close(secin); if((secout = open(secoutname, OWRITE)) < 0) { werrstr("open secretout: %r"); goto cleanupdata; } if(write(secout, secret, nsecret) != nsecret) { werrstr("write secretout: %r"); goto cleanupdata; } close(secout); if(fprint(ctl, "fd %d", fd) < 0 || fprint(ctl, "alg %s", alg) < 0) { werrstr("write ctl: %r"); goto cleanupdata; } close(fd); close(ctl); return data; cleanupdata: close(data); cleanupctl: close(ctl); return -1; }