pushssl.c 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <u.h>
  2. #include <libc.h>
  3. /*
  4. * Since the SSL device uses decimal file descriptors to name channels,
  5. * it is impossible for a user-level file server to stand in for the kernel device.
  6. * Thus we hard-code #D rather than use /net/ssl.
  7. */
  8. int
  9. pushssl(int fd, char *alg, char *secin, char *secout, int *cfd)
  10. {
  11. char buf[8];
  12. char dname[64];
  13. int n, data, ctl;
  14. ctl = open("#D/ssl/clone", ORDWR);
  15. if(ctl < 0)
  16. return -1;
  17. n = read(ctl, buf, sizeof(buf)-1);
  18. if(n < 0)
  19. goto error;
  20. buf[n] = 0;
  21. sprint(dname, "#D/ssl/%s/data", buf);
  22. data = open(dname, ORDWR);
  23. if(data < 0)
  24. goto error;
  25. if(fprint(ctl, "fd %d", fd) < 0 ||
  26. fprint(ctl, "secretin %s", secin) < 0 ||
  27. fprint(ctl, "secretout %s", secout) < 0 ||
  28. fprint(ctl, "alg %s", alg) < 0){
  29. close(data);
  30. goto error;
  31. }
  32. close(fd);
  33. if(cfd != 0)
  34. *cfd = ctl;
  35. else
  36. close(ctl);
  37. return data;
  38. error:
  39. close(ctl);
  40. return -1;
  41. }