xref: /plan9/sys/src/cmd/unix/9pfreebsd/mount_9fs/9auth.h (revision 144145943e440fe30c4e4512a0856f5e3d5ca4be)
1 typedef struct	Ticket		Ticket;
2 typedef struct	Ticketreq	Ticketreq;
3 typedef struct	Authenticator	Authenticator;
4 typedef struct	Nvrsafe		Nvrsafe;
5 typedef struct	Passwordreq	Passwordreq;
6 typedef struct	Chalstate	Chalstate;
7 typedef struct	Apopchalstate	Apopchalstate;
8 typedef struct	Chapreply	Chapreply;
9 typedef struct	MSchapreply	MSchapreply;
10 
11 enum
12 {
13 	DOMLEN=		48,		/* length of an authentication domain name */
14 	U9AUTH_DESKEYLEN=	7,		/* length of a des key for encrypt/decrypt */
15 	CHALLEN=	8,		/* length of a challenge */
16 	NETCHLEN=	16,		/* max network challenge length	*/
17 	CONFIGLEN=	14,
18 	SECRETLEN=	32,		/* max length of a secret */
19 	APOPCHLEN=	256,
20 	MD5LEN=		16,
21 
22 	KEYDBOFF=	8,		/* length of random data at the start of key file */
23 	OKEYDBLEN=	U9FS_NAMELEN+U9AUTH_DESKEYLEN+4+2,	/* length of an entry in old key file */
24 	KEYDBLEN=	OKEYDBLEN+SECRETLEN,	/* length of an entry in key file */
25 	U9AUTH_TCPPORT= 567,
26 	U9AUTH_ILPORT=  566,
27 };
28 
29 /* encryption numberings (anti-replay) */
30 enum
31 {
32 	AuthTreq=1,	/* ticket request */
33 	AuthChal=2,	/* challenge box request */
34 	AuthPass=3,	/* change password */
35 	AuthOK=4,	/* fixed length reply follows */
36 	AuthErr=5,	/* error follows */
37 	AuthMod=6,	/* modify user */
38 	AuthApop=7,	/* apop authentication for pop3 */
39 	AuthOKvar=9,	/* variable length reply follows */
40 	AuthChap=10,	/* chap authentication for ppp */
41 	AuthMSchap=11,	/* MS chap authentication for ppp */
42 
43 
44 	AuthTs=64,	/* ticket encrypted with server's key */
45 	AuthTc,		/* ticket encrypted with client's key */
46 	AuthAs,		/* server generated authenticator */
47 	AuthAc,		/* client generated authenticator */
48 	AuthTp,		/* ticket encrypted with clien's key for password change */
49 };
50 
51 struct Ticketreq
52 {
53 	char	type;
54 	char	authid[U9FS_NAMELEN];	/* server's encryption id */
55 	char	authdom[DOMLEN];	/* server's authentication domain */
56 	char	chal[CHALLEN];		/* challenge from server */
57 	char	hostid[U9FS_NAMELEN];	/* host's encryption id */
58 	char	uid[U9FS_NAMELEN];		/* uid of requesting user on host */
59 };
60 #define	TICKREQLEN	(3*U9FS_NAMELEN+CHALLEN+DOMLEN+1)
61 
62 struct Ticket
63 {
64 	char	num;			/* replay protection */
65 	char	chal[CHALLEN];		/* server challenge */
66 	char	cuid[U9FS_NAMELEN];		/* uid on client */
67 	char	suid[U9FS_NAMELEN];		/* uid on server */
68 	char	key[U9AUTH_DESKEYLEN];		/* nonce DES key */
69 };
70 #define	TICKETLEN	(CHALLEN+2*U9FS_NAMELEN+U9AUTH_DESKEYLEN+1)
71 
72 struct Authenticator
73 {
74 	char	num;			/* replay protection */
75 	char	chal[CHALLEN];
76 	u_long	id;			/* authenticator id, ++'d with each auth */
77 };
78 #define	AUTHENTLEN	(CHALLEN+4+1)
79 
80 struct Passwordreq
81 {
82 	char	num;
83 	char	old[U9FS_NAMELEN];
84 	char	new[U9FS_NAMELEN];
85 	char	changesecret;
86 	char	secret[SECRETLEN];	/* new secret */
87 };
88 #define	PASSREQLEN	(2*U9FS_NAMELEN+1+1+SECRETLEN)
89 
90 struct Nvrsafe
91 {
92 	char	machkey[U9AUTH_DESKEYLEN];
93 	u_char	machsum;
94 	char	authkey[U9AUTH_DESKEYLEN];
95 	u_char	authsum;
96 	char	config[CONFIGLEN];
97 	u_char	configsum;
98 	char	authid[U9FS_NAMELEN];
99 	u_char	authidsum;
100 	char	authdom[DOMLEN];
101 	u_char	authdomsum;
102 };
103 
104 struct Chalstate
105 {
106 	int	afd;			/* /dev/authenticate */
107 	int	asfd;			/* authdial() */
108 	char	chal[NETCHLEN];		/* challenge/response */
109 };
110 
111 struct Apopchalstate
112 {
113 	int	afd;			/* /dev/authenticate */
114 	int	asfd;			/* authdial() */
115 	char	chal[APOPCHLEN];	/* challenge/response */
116 };
117 
118 struct	Chapreply
119 {
120 	u_char	id;
121 	char	uid[U9FS_NAMELEN];
122 	char	resp[MD5LEN];
123 };
124 
125 struct	MSchapreply
126 {
127 	char	uid[U9FS_NAMELEN];
128 	char	LMresp[24];		/* Lan Manager response */
129 	char	NTresp[24];		/* NT response */
130 };
131 
132 extern	int	convT2M(Ticket*, char*, char*);
133 extern	void	convM2T(char*, Ticket*, char*);
134 extern	void	convM2Tnoenc(char*, Ticket*);
135 extern	int	convA2M(Authenticator*, char*, char*);
136 extern	void	convM2A(char*, Authenticator*, char*);
137 extern	int	convTR2M(Ticketreq*, char*);
138 extern	void	convM2TR(char*, Ticketreq*);
139 extern	int	convPR2M(Passwordreq*, char*, char*);
140 extern	void	convM2PR(char*, Passwordreq*, char*);
141 extern	u_char	nvcsum(void*, int);
142 extern	int	opasstokey(char*, char*);
143 extern	int	passtokey(char*, char*);
144 extern	int	authenticate(int, int);
145 extern	int	newns(char*, char*);
146 extern	int	addns(char*, char*);
147 extern	int	authdial(void);
148 extern	int	auth(int);
149 extern	int	srvauth(int, char*);
150 extern	int	nauth(int, Ticket*);
151 extern	int	nsrvauth(int, char*, Ticket*);
152 extern	int	getchal(Chalstate*, char*);
153 extern	int	chalreply(Chalstate*, char*);
154 extern	int	amount(int, char*, int, char*);
155 extern	int	apopchal(Apopchalstate*);
156 extern	int	apopreply(Apopchalstate*, char*, char*);
157 extern	int	login(char*, char*, char*);
158 extern	int	sslnegotiate(int, Ticket*, char**, char**);
159 extern	int	srvsslnegotiate(int, Ticket*, char**, char**);
160