]> git.lizzy.rs Git - plan9front.git/blob - sys/include/authsrv.h
libauthsrv: export common readcons() routine and introduce PASSWDLEN constant
[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         AuthTs=64,      /* ticket encrypted with server's key */
65         AuthTc,         /* ticket encrypted with client's key */
66         AuthAs,         /* server generated authenticator */
67         AuthAc,         /* client generated authenticator */
68         AuthTp,         /* ticket encrypted with client's key for password change */
69         AuthHr,         /* http reply */
70 };
71
72 struct Ticketreq
73 {
74         char    type;
75         char    authid[ANAMELEN];       /* server's encryption id */
76         char    authdom[DOMLEN];        /* server's authentication domain */
77         char    chal[CHALLEN];          /* challenge from server */
78         char    hostid[ANAMELEN];       /* host's encryption id */
79         char    uid[ANAMELEN];          /* uid of requesting user on host */
80 };
81 #define TICKREQLEN      (3*ANAMELEN+CHALLEN+DOMLEN+1)
82
83 struct Ticket
84 {
85         char    num;                    /* replay protection */
86         char    chal[CHALLEN];          /* server challenge */
87         char    cuid[ANAMELEN];         /* uid on client */
88         char    suid[ANAMELEN];         /* uid on server */
89         uchar   key[NONCELEN];          /* nonce key */
90
91         char    form;                   /* (not transmitted) format (0 = des, 1 = ccpoly) */
92 };
93 #define MAXTICKETLEN    (12+CHALLEN+2*ANAMELEN+NONCELEN+16)
94
95 struct Authenticator
96 {
97         char    num;                    /* replay protection */
98         char    chal[CHALLEN];          /* server/client challenge */
99         uchar   rand[NONCELEN];         /* server/client nonce */
100 };
101 #define MAXAUTHENTLEN   (12+CHALLEN+NONCELEN+16)
102
103 struct Passwordreq
104 {
105         char    num;
106         char    old[PASSWDLEN];
107         char    new[PASSWDLEN];
108         char    changesecret;
109         char    secret[SECRETLEN];      /* new secret */
110 };
111 #define MAXPASSREQLEN   (12+2*ANAMELEN+1+SECRETLEN+16)
112
113 struct  OChapreply
114 {
115         uchar   id;
116         char    uid[ANAMELEN];
117         char    resp[OMD5LEN];
118 };
119 #define OCHAPREPLYLEN   (1+ANAMELEN+OMD5LEN)
120
121 struct  OMSchapreply
122 {
123         char    uid[ANAMELEN];
124         char    LMresp[24];             /* Lan Manager response */
125         char    NTresp[24];             /* NT response */
126 };
127 #define OMSCHAPREPLYLEN (ANAMELEN+24+24)
128
129 struct  Authkey
130 {
131         char    des[DESKEYLEN];         /* DES key from password */
132         uchar   aes[AESKEYLEN];         /* AES key from password */
133         uchar   pakkey[PAKKEYLEN];      /* shared key from AuthPAK exchange (see authpak_finish()) */
134         uchar   pakhash[PAKHASHLEN];    /* secret hash from AES key and user name (see authpak_hash()) */
135 };
136
137 /*
138  *  convert to/from wire format
139  */
140 extern  int     convT2M(Ticket*, char*, int, Authkey*);
141 extern  int     convM2T(char*, int, Ticket*, Authkey*);
142 extern  int     convA2M(Authenticator*, char*, int, Ticket*);
143 extern  int     convM2A(char*, int, Authenticator*, Ticket*);
144 extern  int     convTR2M(Ticketreq*, char*, int);
145 extern  int     convM2TR(char*, int, Ticketreq*);
146 extern  int     convPR2M(Passwordreq*, char*, int, Ticket*);
147 extern  int     convM2PR(char*, int, Passwordreq*, Ticket*);
148
149 /*
150  *  convert ascii password to auth key
151  */
152 extern  void    passtokey(Authkey*, char*);
153
154 extern  void    passtodeskey(char key[DESKEYLEN], char *p);
155 extern  void    passtoaeskey(uchar key[AESKEYLEN], char *p);
156
157 /*
158  *  Nvram interface
159  */
160 enum {
161         NVread          = 0,    /* just read */
162         NVwrite         = 1<<0, /* always prompt and rewrite nvram */
163         NVwriteonerr    = 1<<1, /* prompt and rewrite nvram when corrupt */
164         NVwritemem      = 1<<2, /* don't prompt, write nvram from argument */
165 };
166
167 /* storage layout */
168 struct Nvrsafe
169 {
170         char    machkey[DESKEYLEN];     /* file server's authid's des key */
171         uchar   machsum;
172         char    authkey[DESKEYLEN];     /* authid's des key from password */
173         uchar   authsum;
174         /*
175          * file server config string of device holding full configuration;
176          * secstore key on non-file-servers.
177          */
178         char    config[CONFIGLEN];
179         uchar   configsum;
180         char    authid[ANAMELEN];       /* auth userid, e.g., bootes */
181         uchar   authidsum;
182         char    authdom[DOMLEN];        /* auth domain, e.g., cs.bell-labs.com */
183         uchar   authdomsum;
184
185         uchar   aesmachkey[AESKEYLEN];
186         uchar   aesmachsum;
187 };
188
189 extern  uchar   nvcsum(void*, int);
190 extern  int     readnvram(Nvrsafe*, int);
191 extern  char*   readcons(char*, char*, int);
192
193 /*
194  *  call up auth server
195  */
196 extern  int     authdial(char *netroot, char *authdom);
197
198 /*
199  *  exchange messages with auth server
200  */
201 extern  int     _asgetpakkey(int, Ticketreq*, Authkey*);
202 extern  int     _asgetticket(int, Ticketreq*, char*, int);
203 extern  int     _asrequest(int, Ticketreq*);
204 extern  int     _asgetresp(int, Ticket*, Authenticator*, Authkey *);
205 extern  int     _asrdresp(int, char*, int);
206
207 /*
208  *  AuthPAK protocol
209  */
210 typedef struct PAKpriv PAKpriv;
211 struct PAKpriv
212 {
213         int     isclient;
214         uchar   x[PAKXLEN];
215         uchar   y[PAKYLEN];
216 };
217
218 extern  void    authpak_hash(Authkey *k, char *u);
219 extern  void    authpak_new(PAKpriv *p, Authkey *k, uchar y[PAKYLEN], int isclient);
220 extern  int     authpak_finish(PAKpriv *p, Authkey *k, uchar y[PAKYLEN]);