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