1184610Salfred/*-
2184610Salfred * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3184610Salfred *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4184610Salfred *                           Internet Initiative Japan, Inc (IIJ)
5184610Salfred * All rights reserved.
6184610Salfred *
7184610Salfred * Redistribution and use in source and binary forms, with or without
8184610Salfred * modification, are permitted provided that the following conditions
9184610Salfred * are met:
10184610Salfred * 1. Redistributions of source code must retain the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer.
12184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
13184610Salfred *    notice, this list of conditions and the following disclaimer in the
14184610Salfred *    documentation and/or other materials provided with the distribution.
15184610Salfred *
16184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26184610Salfred * SUCH DAMAGE.
27184610Salfred *
28184610Salfred * $FreeBSD$
29184610Salfred */
30184610Salfred
31184610Salfredstruct mbuf;
32184610Salfredstruct physical;
33184610Salfred
34227843Smarius#define	CHAP_CHALLENGE	1
35227843Smarius#define	CHAP_RESPONSE	2
36227843Smarius#define	CHAP_SUCCESS	3
37184610Salfred#define	CHAP_FAILURE	4
38184610Salfred
39184610Salfredstruct chap {
40184610Salfred  struct fdescriptor desc;
41184610Salfred  struct {
42184610Salfred    pid_t pid;
43184610Salfred    int fd;
44184610Salfred    struct {
45184610Salfred      char ptr[AUTHLEN * 2 + 3];	/* Allow for \r\n at the end (- NUL) */
46184610Salfred      int len;
47184610Salfred    } buf;
48184610Salfred  } child;
49184610Salfred  struct authinfo auth;
50184610Salfred  struct {
51194677Sthompsa    u_char local[CHAPCHALLENGELEN + AUTHLEN];	/* I invented this one */
52194677Sthompsa    u_char peer[CHAPCHALLENGELEN + AUTHLEN];	/* Peer gave us this one */
53194677Sthompsa  } challenge;
54194677Sthompsa#ifndef NODES
55194677Sthompsa  unsigned NTRespSent : 1;		/* Our last response */
56194677Sthompsa  int peertries;
57194677Sthompsa  u_char authresponse[CHAPAUTHRESPONSELEN];	/* CHAP 81 response */
58194677Sthompsa#endif
59194677Sthompsa};
60194677Sthompsa
61194677Sthompsa#define descriptor2chap(d) \
62194677Sthompsa  ((d)->type == CHAP_DESCRIPTOR ? (struct chap *)(d) : NULL)
63194677Sthompsa#define auth2chap(a) \
64194677Sthompsa  ((struct chap *)((char *)a - (uintptr_t)&((struct chap *)0)->auth))
65194677Sthompsa
66194677Sthompsastruct MSCHAPv2_resp {		/* rfc2759 */
67194677Sthompsa  char PeerChallenge[16];
68194677Sthompsa  char Reserved[8];
69194677Sthompsa  char NTResponse[24];
70188746Sthompsa  char Flags;
71188942Sthompsa};
72194677Sthompsa
73194677Sthompsaextern void chap_Init(struct chap *, struct physical *);
74246421Shselaskyextern void chap_ReInit(struct chap *);
75242438Shselaskyextern struct mbuf *chap_Input(struct bundle *, struct link *, struct mbuf *);
76249796Shselasky