authsrv.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Interface for talking to authentication server.
  11. */
  12. typedef struct Ticket Ticket;
  13. typedef struct Ticketreq Ticketreq;
  14. typedef struct Authenticator Authenticator;
  15. typedef struct Nvrsafe Nvrsafe;
  16. typedef struct Passwordreq Passwordreq;
  17. typedef struct OChapreply OChapreply;
  18. typedef struct OMSchapreply OMSchapreply;
  19. enum
  20. {
  21. ANAMELEN= 28, /* name max size in previous proto */
  22. AERRLEN= 64, /* errstr max size in previous proto */
  23. DOMLEN= 48, /* authentication domain name length */
  24. DESKEYLEN= 7, /* encrypt/decrypt des key length */
  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. KEYDBOFF= 8, /* bytes of random data at key file's start */
  30. OKEYDBLEN= ANAMELEN+DESKEYLEN+4+2, /* old key file entry length */
  31. KEYDBLEN= OKEYDBLEN+SECRETLEN, /* key file entry length */
  32. OMD5LEN= 16,
  33. };
  34. /* encryption numberings (anti-replay) */
  35. enum
  36. {
  37. AuthTreq=1, /* ticket request */
  38. AuthChal=2, /* challenge box request */
  39. AuthPass=3, /* change password */
  40. AuthOK=4, /* fixed length reply follows */
  41. AuthErr=5, /* error follows */
  42. AuthMod=6, /* modify user */
  43. AuthApop=7, /* apop authentication for pop3 */
  44. AuthOKvar=9, /* variable length reply follows */
  45. AuthChap=10, /* chap authentication for ppp */
  46. AuthMSchap=11, /* MS chap authentication for ppp */
  47. AuthCram=12, /* CRAM verification for IMAP (RFC2195 & rfc2104) */
  48. AuthHttp=13, /* http domain login */
  49. AuthVNC=14, /* VNC server login (deprecated) */
  50. AuthTs=64, /* ticket encrypted with server's key */
  51. AuthTc, /* ticket encrypted with client's key */
  52. AuthAs, /* server generated authenticator */
  53. AuthAc, /* client generated authenticator */
  54. AuthTp, /* ticket encrypted with client's key for password change */
  55. AuthHr, /* http reply */
  56. };
  57. struct Ticketreq
  58. {
  59. char type;
  60. char authid[ANAMELEN]; /* server's encryption id */
  61. char authdom[DOMLEN]; /* server's authentication domain */
  62. char chal[CHALLEN]; /* challenge from server */
  63. char hostid[ANAMELEN]; /* host's encryption id */
  64. char uid[ANAMELEN]; /* uid of requesting user on host */
  65. };
  66. #define TICKREQLEN (3*ANAMELEN+CHALLEN+DOMLEN+1)
  67. struct Ticket
  68. {
  69. char num; /* replay protection */
  70. char chal[CHALLEN]; /* server challenge */
  71. char cuid[ANAMELEN]; /* uid on client */
  72. char suid[ANAMELEN]; /* uid on server */
  73. char key[DESKEYLEN]; /* nonce DES key */
  74. };
  75. #define TICKETLEN (CHALLEN+2*ANAMELEN+DESKEYLEN+1)
  76. struct Authenticator
  77. {
  78. char num; /* replay protection */
  79. char chal[CHALLEN];
  80. uint32_t id; /* authenticator id, ++'d with each auth */
  81. };
  82. #define AUTHENTLEN (CHALLEN+4+1)
  83. struct Passwordreq
  84. {
  85. char num;
  86. char old[ANAMELEN];
  87. char new[ANAMELEN];
  88. char changesecret;
  89. char secret[SECRETLEN]; /* new secret */
  90. };
  91. #define PASSREQLEN (2*ANAMELEN+1+1+SECRETLEN)
  92. struct OChapreply
  93. {
  94. uint8_t id;
  95. char uid[ANAMELEN];
  96. char resp[OMD5LEN];
  97. };
  98. struct OMSchapreply
  99. {
  100. char uid[ANAMELEN];
  101. char LMresp[24]; /* Lan Manager response */
  102. char NTresp[24]; /* NT response */
  103. };
  104. /*
  105. * convert to/from wire format
  106. */
  107. extern int convT2M(Ticket*, char*, char*);
  108. extern void convM2T(char*, Ticket*, char*);
  109. extern void convM2Tnoenc(char*, Ticket*);
  110. extern int convA2M(Authenticator*, char*, char*);
  111. extern void convM2A(char*, Authenticator*, char*);
  112. extern int convTR2M(Ticketreq*, char*);
  113. extern void convM2TR(char*, Ticketreq*);
  114. extern int convPR2M(Passwordreq*, char*, char*);
  115. extern void convM2PR(char*, Passwordreq*, char*);
  116. /*
  117. * convert ascii password to DES key
  118. */
  119. extern int opasstokey(char*, char*);
  120. extern int passtokey(char*, char*);
  121. /*
  122. * Nvram interface
  123. */
  124. enum {
  125. NVread = 0, /* just read */
  126. NVwrite = 1<<0, /* always prompt and rewrite nvram */
  127. NVwriteonerr = 1<<1, /* prompt and rewrite nvram when corrupt */
  128. NVwritemem = 1<<2, /* don't prompt, write nvram from argument */
  129. };
  130. /* storage layout */
  131. struct Nvrsafe
  132. {
  133. char machkey[DESKEYLEN]; /* was file server's authid's des key */
  134. uint8_t machsum;
  135. char authkey[DESKEYLEN]; /* authid's des key from password */
  136. uint8_t authsum;
  137. /*
  138. * file server config string of device holding full configuration;
  139. * secstore key on non-file-servers.
  140. */
  141. char config[CONFIGLEN];
  142. uint8_t configsum;
  143. char authid[ANAMELEN]; /* auth userid, e.g., bootes */
  144. uint8_t authidsum;
  145. char authdom[DOMLEN]; /* auth domain, e.g., cs.bell-labs.com */
  146. uint8_t authdomsum;
  147. };
  148. extern uint8_t nvcsum(void*, int);
  149. extern int readnvram(Nvrsafe*, int);
  150. /*
  151. * call up auth server
  152. */
  153. extern int authdial(char *netroot, char *authdom);
  154. /*
  155. * exchange messages with auth server
  156. */
  157. extern int _asgetticket(int, char*, char*);
  158. extern int _asrdresp(int, char*, int);
  159. extern int sslnegotiate(int, Ticket*, char**, char**);
  160. extern int srvsslnegotiate(int, Ticket*, char**, char**);