]> git.lizzy.rs Git - plan9front.git/blob - sys/include/authsrv.h
5c0b368e77a4a5782af79057f8f07c8654074734
[plan9front.git] / sys / include / authsrv.h
1 #pragma src     "/sys/src/libauthsrv"
2 #pragma lib     "libauthsrv.a"
3
4 /*
5  * Interface for talking to authentication server.
6  */
7 typedef struct  Ticket          Ticket;
8 typedef struct  Ticketreq       Ticketreq;
9 typedef struct  Authenticator   Authenticator;
10 typedef struct  Nvrsafe         Nvrsafe;
11 typedef struct  Passwordreq     Passwordreq;
12 typedef struct  OChapreply      OChapreply;
13 typedef struct  OMSchapreply    OMSchapreply;
14
15 typedef struct  Authkey         Authkey;
16
17 enum
18 {
19         ANAMELEN=       28,     /* name max size in previous proto */
20         AERRLEN=        64,     /* errstr max size in previous proto */
21         DOMLEN=         48,     /* authentication domain name length */
22         DESKEYLEN=      7,      /* encrypt/decrypt des key length */
23         AESKEYLEN=      16,     /* encrypt/decrypt aes key length */
24
25         CHALLEN=        8,      /* plan9 sk1 challenge length */
26         NETCHLEN=       16,     /* max network challenge length (used in AS protocol) */
27         CONFIGLEN=      14,
28         SECRETLEN=      32,     /* secret max size */
29         PASSWDLEN=      28,     /* password max size */
30
31         NONCELEN=       32,
32
33         KEYDBOFF=       8,      /* bytes of random data at key file's start */
34         OKEYDBLEN=      ANAMELEN+DESKEYLEN+4+2, /* old key file entry length */
35         KEYDBLEN=       OKEYDBLEN+SECRETLEN,    /* key file entry length */
36         OMD5LEN=        16,
37
38         /* AuthPAK constants */
39         PAKKEYLEN=      32,
40         PAKSLEN=        (448+7)/8,      /* ed448 scalar */
41         PAKPLEN=        4*PAKSLEN,      /* point in extended format X,Y,Z,T */
42         PAKHASHLEN=     2*PAKPLEN,      /* hashed points PM,PN */
43         PAKXLEN=        PAKSLEN,        /* random scalar secret key */ 
44         PAKYLEN=        PAKSLEN,        /* decaf encoded public key */
45 };
46
47 /* encryption numberings (anti-replay) */
48 enum
49 {
50         AuthTreq=1,     /* ticket request */
51         AuthChal=2,     /* challenge box request */
52         AuthPass=3,     /* change password */
53         AuthOK=4,       /* fixed length reply follows */
54         AuthErr=5,      /* error follows */
55         AuthMod=6,      /* modify user */
56         AuthApop=7,     /* apop authentication for pop3 */
57         AuthOKvar=9,    /* variable length reply follows */
58         AuthChap=10,    /* chap authentication for ppp */
59         AuthMSchap=11,  /* MS chap authentication for ppp */
60         AuthCram=12,    /* CRAM verification for IMAP (RFC2195 & rfc2104) */
61         AuthHttp=13,    /* http domain login */
62         AuthVNC=14,     /* VNC server login (deprecated) */
63         AuthPAK=19,     /* authenticated diffie hellman key agreement */
64         AuthMSchapv2=21,/* MS chap v2 authentication for ppp */
65         AuthTs=64,      /* ticket encrypted with server's key */
66         AuthTc,         /* ticket encrypted with client's key */
67         AuthAs,         /* server generated authenticator */
68         AuthAc,         /* client generated authenticator */
69         AuthTp,         /* ticket encrypted with client's key for password change */
70         AuthHr,         /* http reply */
71 };
72
73 struct Ticketreq
74 {
75         char    type;
76         char    authid[ANAMELEN];       /* server's encryption id */
77         char    authdom[DOMLEN];        /* server's authentication domain */
78         char    chal[CHALLEN];          /* challenge from server */
79         char    hostid[ANAMELEN];       /* host's encryption id */
80         char    uid[ANAMELEN];          /* uid of requesting user on host */
81 };
82 #define TICKREQLEN      (3*ANAMELEN+CHALLEN+DOMLEN+1)
83
84 struct Ticket
85 {
86         char    num;                    /* replay protection */
87         char    chal[CHALLEN];          /* server challenge */
88         char    cuid[ANAMELEN];         /* uid on client */
89         char    suid[ANAMELEN];         /* uid on server */
90         uchar   key[NONCELEN];          /* nonce key */
91
92         char    form;                   /* (not transmitted) format (0 = des, 1 = ccpoly) */
93 };
94 #define MAXTICKETLEN    (12+CHALLEN+2*ANAMELEN+NONCELEN+16)
95
96 struct Authenticator
97 {
98         char    num;                    /* replay protection */
99         char    chal[CHALLEN];          /* server/client challenge */
100         uchar   rand[NONCELEN];         /* server/client nonce */
101 };
102 #define MAXAUTHENTLEN   (12+CHALLEN+NONCELEN+16)
103
104 struct Passwordreq
105 {
106         char    num;
107         char    old[PASSWDLEN];
108         char    new[PASSWDLEN];
109         char    changesecret;
110         char    secret[SECRETLEN];      /* new secret */
111 };
112 #define MAXPASSREQLEN   (12+2*PASSWDLEN+1+SECRETLEN+16)
113
114 struct  OChapreply
115 {
116         uchar   id;
117         char    uid[ANAMELEN];
118         char    resp[OMD5LEN];
119 };
120 #define OCHAPREPLYLEN   (1+ANAMELEN+OMD5LEN)
121
122 struct  OMSchapreply
123 {
124         char    uid[ANAMELEN];
125         char    LMresp[24];             /* Lan Manager response */
126         char    NTresp[24];             /* NT response */
127 };
128 #define OMSCHAPREPLYLEN (ANAMELEN+24+24)
129
130 struct  Authkey
131 {
132         char    des[DESKEYLEN];         /* DES key from password */
133         uchar   aes[AESKEYLEN];         /* AES key from password */
134         uchar   pakkey[PAKKEYLEN];      /* shared key from AuthPAK exchange (see authpak_finish()) */
135         uchar   pakhash[PAKHASHLEN];    /* secret hash from AES key and user name (see authpak_hash()) */
136 };
137
138 /*
139  *  convert to/from wire format
140  */
141 extern  int     convT2M(Ticket*, char*, int, Authkey*);
142 extern  int     convM2T(char*, int, Ticket*, Authkey*);
143 extern  int     convA2M(Authenticator*, char*, int, Ticket*);
144 extern  int     convM2A(char*, int, Authenticator*, Ticket*);
145 extern  int     convTR2M(Ticketreq*, char*, int);
146 extern  int     convM2TR(char*, int, Ticketreq*);
147 extern  int     convPR2M(Passwordreq*, char*, int, Ticket*);
148 extern  int     convM2PR(char*, int, Passwordreq*, Ticket*);
149
150 /*
151  *  convert ascii password to auth key
152  */
153 extern  void    passtokey(Authkey*, char*);
154
155 extern  void    passtodeskey(char key[DESKEYLEN], char *p);
156 extern  void    passtoaeskey(uchar key[AESKEYLEN], char *p);
157
158 /*
159  *  Nvram interface
160  */
161 enum {
162         NVread          = 0,    /* just read */
163         NVwrite         = 1<<0, /* always prompt and rewrite nvram */
164         NVwriteonerr    = 1<<1, /* prompt and rewrite nvram when corrupt */
165         NVwritemem      = 1<<2, /* don't prompt, write nvram from argument */
166 };
167
168 /* storage layout */
169 struct Nvrsafe
170 {
171         char    machkey[DESKEYLEN];     /* file server's authid's des key */
172         uchar   machsum;
173         char    authkey[DESKEYLEN];     /* authid's des key from password */
174         uchar   authsum;
175         /*
176          * file server config string of device holding full configuration;
177          * secstore key on non-file-servers.
178          */
179         char    config[CONFIGLEN];
180         uchar   configsum;
181         char    authid[ANAMELEN];       /* auth userid, e.g., bootes */
182         uchar   authidsum;
183         char    authdom[DOMLEN];        /* auth domain, e.g., cs.bell-labs.com */
184         uchar   authdomsum;
185
186         uchar   aesmachkey[AESKEYLEN];
187         uchar   aesmachsum;
188 };
189
190 extern  uchar   nvcsum(void*, int);
191 extern  int     readnvram(Nvrsafe*, int);
192 extern  char*   readcons(char*, char*, int);
193
194 /*
195  *  call up auth server
196  */
197 extern  int     authdial(char *netroot, char *authdom);
198
199 /*
200  *  exchange messages with auth server
201  */
202 extern  int     _asgetpakkey(int, Ticketreq*, Authkey*);
203 extern  int     _asgetticket(int, Ticketreq*, char*, int);
204 extern  int     _asrequest(int, Ticketreq*);
205 extern  int     _asgetresp(int, Ticket*, Authenticator*, Authkey *);
206 extern  int     _asrdresp(int, char*, int);
207
208 /*
209  *  AuthPAK protocol
210  */
211 typedef struct PAKpriv PAKpriv;
212 struct PAKpriv
213 {
214         int     isclient;
215         uchar   x[PAKXLEN];
216         uchar   y[PAKYLEN];
217 };
218
219 extern  void    authpak_hash(Authkey *k, char *u);
220 extern  void    authpak_new(PAKpriv *p, Authkey *k, uchar y[PAKYLEN], int isclient);
221 extern  int     authpak_finish(PAKpriv *p, Authkey *k, uchar y[PAKYLEN]);