2011-03-30 13:47:56 +00:00
|
|
|
#pragma src "/sys/src/libauthsrv"
|
|
|
|
#pragma lib "libauthsrv.a"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface for talking to authentication server.
|
|
|
|
*/
|
|
|
|
typedef struct Ticket Ticket;
|
|
|
|
typedef struct Ticketreq Ticketreq;
|
|
|
|
typedef struct Authenticator Authenticator;
|
|
|
|
typedef struct Nvrsafe Nvrsafe;
|
|
|
|
typedef struct Passwordreq Passwordreq;
|
|
|
|
typedef struct OChapreply OChapreply;
|
|
|
|
typedef struct OMSchapreply OMSchapreply;
|
|
|
|
|
2015-08-19 19:06:17 +00:00
|
|
|
typedef struct Authkey Authkey;
|
|
|
|
|
2011-03-30 13:47:56 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ANAMELEN= 28, /* name max size in previous proto */
|
|
|
|
AERRLEN= 64, /* errstr max size in previous proto */
|
|
|
|
DOMLEN= 48, /* authentication domain name length */
|
|
|
|
DESKEYLEN= 7, /* encrypt/decrypt des key length */
|
2016-01-06 02:09:00 +00:00
|
|
|
AESKEYLEN= 16, /* encrypt/decrypt aes key length */
|
|
|
|
|
2011-03-30 13:47:56 +00:00
|
|
|
CHALLEN= 8, /* plan9 sk1 challenge length */
|
|
|
|
NETCHLEN= 16, /* max network challenge length (used in AS protocol) */
|
|
|
|
CONFIGLEN= 14,
|
|
|
|
SECRETLEN= 32, /* secret max size */
|
2016-07-31 18:04:02 +00:00
|
|
|
PASSWDLEN= 28, /* password max size */
|
2011-03-30 13:47:56 +00:00
|
|
|
|
2016-01-06 02:09:00 +00:00
|
|
|
NONCELEN= 32,
|
|
|
|
|
2011-03-30 13:47:56 +00:00
|
|
|
KEYDBOFF= 8, /* bytes of random data at key file's start */
|
|
|
|
OKEYDBLEN= ANAMELEN+DESKEYLEN+4+2, /* old key file entry length */
|
|
|
|
KEYDBLEN= OKEYDBLEN+SECRETLEN, /* key file entry length */
|
|
|
|
OMD5LEN= 16,
|
2016-01-06 02:09:00 +00:00
|
|
|
|
|
|
|
/* AuthPAK constants */
|
|
|
|
PAKKEYLEN= 32,
|
|
|
|
PAKSLEN= (448+7)/8, /* ed448 scalar */
|
|
|
|
PAKPLEN= 4*PAKSLEN, /* point in extended format X,Y,Z,T */
|
|
|
|
PAKHASHLEN= 2*PAKPLEN, /* hashed points PM,PN */
|
|
|
|
PAKXLEN= PAKSLEN, /* random scalar secret key */
|
|
|
|
PAKYLEN= PAKSLEN, /* decaf encoded public key */
|
2011-03-30 13:47:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* encryption numberings (anti-replay) */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
AuthTreq=1, /* ticket request */
|
|
|
|
AuthChal=2, /* challenge box request */
|
|
|
|
AuthPass=3, /* change password */
|
|
|
|
AuthOK=4, /* fixed length reply follows */
|
|
|
|
AuthErr=5, /* error follows */
|
|
|
|
AuthMod=6, /* modify user */
|
|
|
|
AuthApop=7, /* apop authentication for pop3 */
|
|
|
|
AuthOKvar=9, /* variable length reply follows */
|
|
|
|
AuthChap=10, /* chap authentication for ppp */
|
|
|
|
AuthMSchap=11, /* MS chap authentication for ppp */
|
|
|
|
AuthCram=12, /* CRAM verification for IMAP (RFC2195 & rfc2104) */
|
|
|
|
AuthHttp=13, /* http domain login */
|
|
|
|
AuthVNC=14, /* VNC server login (deprecated) */
|
2016-01-06 02:09:00 +00:00
|
|
|
AuthPAK=19, /* authenticated diffie hellman key agreement */
|
2018-01-21 21:32:34 +00:00
|
|
|
AuthMSchapv2=21,/* MS chap v2 authentication for ppp */
|
2011-03-30 13:47:56 +00:00
|
|
|
AuthTs=64, /* ticket encrypted with server's key */
|
|
|
|
AuthTc, /* ticket encrypted with client's key */
|
|
|
|
AuthAs, /* server generated authenticator */
|
|
|
|
AuthAc, /* client generated authenticator */
|
|
|
|
AuthTp, /* ticket encrypted with client's key for password change */
|
|
|
|
AuthHr, /* http reply */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Ticketreq
|
|
|
|
{
|
|
|
|
char type;
|
|
|
|
char authid[ANAMELEN]; /* server's encryption id */
|
|
|
|
char authdom[DOMLEN]; /* server's authentication domain */
|
|
|
|
char chal[CHALLEN]; /* challenge from server */
|
|
|
|
char hostid[ANAMELEN]; /* host's encryption id */
|
|
|
|
char uid[ANAMELEN]; /* uid of requesting user on host */
|
|
|
|
};
|
|
|
|
#define TICKREQLEN (3*ANAMELEN+CHALLEN+DOMLEN+1)
|
|
|
|
|
|
|
|
struct Ticket
|
|
|
|
{
|
|
|
|
char num; /* replay protection */
|
|
|
|
char chal[CHALLEN]; /* server challenge */
|
|
|
|
char cuid[ANAMELEN]; /* uid on client */
|
|
|
|
char suid[ANAMELEN]; /* uid on server */
|
2016-01-06 02:09:00 +00:00
|
|
|
uchar key[NONCELEN]; /* nonce key */
|
|
|
|
|
|
|
|
char form; /* (not transmitted) format (0 = des, 1 = ccpoly) */
|
2011-03-30 13:47:56 +00:00
|
|
|
};
|
2016-01-06 02:09:00 +00:00
|
|
|
#define MAXTICKETLEN (12+CHALLEN+2*ANAMELEN+NONCELEN+16)
|
2011-03-30 13:47:56 +00:00
|
|
|
|
|
|
|
struct Authenticator
|
|
|
|
{
|
|
|
|
char num; /* replay protection */
|
2016-01-06 02:09:00 +00:00
|
|
|
char chal[CHALLEN]; /* server/client challenge */
|
|
|
|
uchar rand[NONCELEN]; /* server/client nonce */
|
2011-03-30 13:47:56 +00:00
|
|
|
};
|
2016-01-06 02:09:00 +00:00
|
|
|
#define MAXAUTHENTLEN (12+CHALLEN+NONCELEN+16)
|
2011-03-30 13:47:56 +00:00
|
|
|
|
|
|
|
struct Passwordreq
|
|
|
|
{
|
|
|
|
char num;
|
2016-07-31 18:04:02 +00:00
|
|
|
char old[PASSWDLEN];
|
|
|
|
char new[PASSWDLEN];
|
2011-03-30 13:47:56 +00:00
|
|
|
char changesecret;
|
|
|
|
char secret[SECRETLEN]; /* new secret */
|
|
|
|
};
|
2016-08-05 17:09:42 +00:00
|
|
|
#define MAXPASSREQLEN (12+2*PASSWDLEN+1+SECRETLEN+16)
|
2011-03-30 13:47:56 +00:00
|
|
|
|
|
|
|
struct OChapreply
|
|
|
|
{
|
|
|
|
uchar id;
|
|
|
|
char uid[ANAMELEN];
|
|
|
|
char resp[OMD5LEN];
|
|
|
|
};
|
2014-02-15 18:57:13 +00:00
|
|
|
#define OCHAPREPLYLEN (1+ANAMELEN+OMD5LEN)
|
2011-03-30 13:47:56 +00:00
|
|
|
|
|
|
|
struct OMSchapreply
|
|
|
|
{
|
|
|
|
char uid[ANAMELEN];
|
|
|
|
char LMresp[24]; /* Lan Manager response */
|
|
|
|
char NTresp[24]; /* NT response */
|
|
|
|
};
|
2014-02-15 18:57:13 +00:00
|
|
|
#define OMSCHAPREPLYLEN (ANAMELEN+24+24)
|
2011-03-30 13:47:56 +00:00
|
|
|
|
2015-08-19 19:06:17 +00:00
|
|
|
struct Authkey
|
|
|
|
{
|
2016-01-06 02:09:00 +00:00
|
|
|
char des[DESKEYLEN]; /* DES key from password */
|
|
|
|
uchar aes[AESKEYLEN]; /* AES key from password */
|
|
|
|
uchar pakkey[PAKKEYLEN]; /* shared key from AuthPAK exchange (see authpak_finish()) */
|
|
|
|
uchar pakhash[PAKHASHLEN]; /* secret hash from AES key and user name (see authpak_hash()) */
|
2015-08-19 19:06:17 +00:00
|
|
|
};
|
|
|
|
|
2011-03-30 13:47:56 +00:00
|
|
|
/*
|
|
|
|
* convert to/from wire format
|
|
|
|
*/
|
2015-08-19 19:06:17 +00:00
|
|
|
extern int convT2M(Ticket*, char*, int, Authkey*);
|
|
|
|
extern int convM2T(char*, int, Ticket*, Authkey*);
|
|
|
|
extern int convA2M(Authenticator*, char*, int, Ticket*);
|
|
|
|
extern int convM2A(char*, int, Authenticator*, Ticket*);
|
|
|
|
extern int convTR2M(Ticketreq*, char*, int);
|
|
|
|
extern int convM2TR(char*, int, Ticketreq*);
|
|
|
|
extern int convPR2M(Passwordreq*, char*, int, Ticket*);
|
|
|
|
extern int convM2PR(char*, int, Passwordreq*, Ticket*);
|
2011-03-30 13:47:56 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-06 02:09:00 +00:00
|
|
|
* convert ascii password to auth key
|
2011-03-30 13:47:56 +00:00
|
|
|
*/
|
2015-08-21 00:43:31 +00:00
|
|
|
extern void passtokey(Authkey*, char*);
|
2011-03-30 13:47:56 +00:00
|
|
|
|
2016-01-06 02:09:00 +00:00
|
|
|
extern void passtodeskey(char key[DESKEYLEN], char *p);
|
|
|
|
extern void passtoaeskey(uchar key[AESKEYLEN], char *p);
|
|
|
|
|
2011-03-30 13:47:56 +00:00
|
|
|
/*
|
|
|
|
* Nvram interface
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
NVread = 0, /* just read */
|
|
|
|
NVwrite = 1<<0, /* always prompt and rewrite nvram */
|
|
|
|
NVwriteonerr = 1<<1, /* prompt and rewrite nvram when corrupt */
|
|
|
|
NVwritemem = 1<<2, /* don't prompt, write nvram from argument */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* storage layout */
|
|
|
|
struct Nvrsafe
|
|
|
|
{
|
2015-08-21 00:43:31 +00:00
|
|
|
char machkey[DESKEYLEN]; /* file server's authid's des key */
|
2011-03-30 13:47:56 +00:00
|
|
|
uchar machsum;
|
|
|
|
char authkey[DESKEYLEN]; /* authid's des key from password */
|
|
|
|
uchar authsum;
|
|
|
|
/*
|
|
|
|
* file server config string of device holding full configuration;
|
|
|
|
* secstore key on non-file-servers.
|
|
|
|
*/
|
|
|
|
char config[CONFIGLEN];
|
|
|
|
uchar configsum;
|
|
|
|
char authid[ANAMELEN]; /* auth userid, e.g., bootes */
|
|
|
|
uchar authidsum;
|
2015-08-21 00:43:31 +00:00
|
|
|
char authdom[DOMLEN]; /* auth domain, e.g., cs.bell-labs.com */
|
2011-03-30 13:47:56 +00:00
|
|
|
uchar authdomsum;
|
2015-08-21 00:43:31 +00:00
|
|
|
|
|
|
|
uchar aesmachkey[AESKEYLEN];
|
|
|
|
uchar aesmachsum;
|
2011-03-30 13:47:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern uchar nvcsum(void*, int);
|
2016-01-06 02:09:00 +00:00
|
|
|
extern int readnvram(Nvrsafe*, int);
|
2016-07-31 18:04:02 +00:00
|
|
|
extern char* readcons(char*, char*, int);
|
2011-03-30 13:47:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call up auth server
|
|
|
|
*/
|
|
|
|
extern int authdial(char *netroot, char *authdom);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* exchange messages with auth server
|
|
|
|
*/
|
2016-01-06 02:09:00 +00:00
|
|
|
extern int _asgetpakkey(int, Ticketreq*, Authkey*);
|
2015-08-19 19:06:17 +00:00
|
|
|
extern int _asgetticket(int, Ticketreq*, char*, int);
|
|
|
|
extern int _asrequest(int, Ticketreq*);
|
|
|
|
extern int _asgetresp(int, Ticket*, Authenticator*, Authkey *);
|
2011-03-30 13:47:56 +00:00
|
|
|
extern int _asrdresp(int, char*, int);
|
2016-01-06 02:09:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AuthPAK protocol
|
|
|
|
*/
|
|
|
|
typedef struct PAKpriv PAKpriv;
|
|
|
|
struct PAKpriv
|
|
|
|
{
|
|
|
|
int isclient;
|
|
|
|
uchar x[PAKXLEN];
|
|
|
|
uchar y[PAKYLEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
extern void authpak_hash(Authkey *k, char *u);
|
|
|
|
extern void authpak_new(PAKpriv *p, Authkey *k, uchar y[PAKYLEN], int isclient);
|
|
|
|
extern int authpak_finish(PAKpriv *p, Authkey *k, uchar y[PAKYLEN]);
|