#include #include #include #include #include uchar* factotum_sign(RSApub *pub, uchar *in, int inlen, int *olen) { int afd, rv; char *s; uchar *out; AuthRpc *rpc; out = nil; // start talking to factotum if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0) return nil; if((rpc = auth_allocrpc(afd)) == nil){ close(afd); return nil; } s = smprint("proto=rsa role=sign n=%B", pub->n); if(s == nil) goto Error; rv = auth_rpc(rpc, "start", s, strlen(s)); free(s); if(rv != ARok) goto Error; if(auth_rpc(rpc, "write", in, inlen) != ARok) goto Error; if(auth_rpc(rpc, "read", nil, 0) != ARok) goto Error; out = mallocz(rpc->narg, 1); if(out == nil) goto Error; memcpy(out, rpc->arg, rpc->narg); *olen = rpc->narg; Error: close(afd); auth_freerpc(rpc); return out; } int factotum_write_ctl(char *format, ...) { int cfd, len, n; va_list args; char *data; if((cfd = open("/mnt/factotum/ctl", OWRITE)) < 0) return -1; va_start(args, format); data = vsmprint(format, args); va_end(args); if(data == nil){ close(cfd); return -1; } len = strlen(data); n = write(cfd, data, len); free(data); close(cfd); if(n != len) return -1; return 0; }