netkey.c 758 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <authsrv.h>
  4. #include <bio.h>
  5. #include "authcmdlib.h"
  6. void
  7. usage(void)
  8. {
  9. fprint(2, "usage: netkey\n");
  10. exits("usage");
  11. }
  12. void
  13. main(int argc, char *argv[])
  14. {
  15. char buf[32], pass[32], key[DESKEYLEN];
  16. char *s;
  17. int n;
  18. ARGBEGIN{
  19. default:
  20. usage();
  21. }ARGEND
  22. if(argc)
  23. usage();
  24. s = getenv("service");
  25. if(s && strcmp(s, "cpu") == 0){
  26. fprint(2, "netkey must not be run on the cpu server\n");
  27. exits("boofhead");
  28. }
  29. readln("Password: ", pass, sizeof pass, 1);
  30. passtokey(key, pass);
  31. for(;;){
  32. print("challenge: ");
  33. n = read(0, buf, sizeof buf - 1);
  34. if(n <= 0)
  35. exits(0);
  36. buf[n] = '\0';
  37. n = strtol(buf, 0, 10);
  38. sprint(buf, "%d", n);
  39. netcrypt(key, buf);
  40. print("response: %s\n", buf);
  41. }
  42. }