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