chap.c (37d818fb2166801abdc0719d4ddcc3278d43b495) chap.c (972a1bcf5db5ee4c5520a1d29d3c81e81bdec84f)
1/*
2 * PPP CHAP Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP CHAP Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: chap.c,v 1.36 1998/08/07 18:42:47 brian Exp $
20 * $Id: chap.c,v 1.37 1998/08/26 18:07:56 brian Exp $
21 *
22 * TODO:
23 */
21 *
22 * TODO:
23 */
24#include <sys/types.h>
24#include <sys/param.h>
25#include <netinet/in.h>
26#include <netinet/in_systm.h>
27#include <netinet/ip.h>
28#include <sys/un.h>
29
30#ifdef HAVE_DES
31#include <md4.h>
32#endif

--- 19 unchanged lines hidden (view full) ---

52#include "iplist.h"
53#include "slcompress.h"
54#include "ipcp.h"
55#include "filter.h"
56#include "ccp.h"
57#include "link.h"
58#include "physical.h"
59#include "mp.h"
25#include <netinet/in.h>
26#include <netinet/in_systm.h>
27#include <netinet/ip.h>
28#include <sys/un.h>
29
30#ifdef HAVE_DES
31#include <md4.h>
32#endif

--- 19 unchanged lines hidden (view full) ---

52#include "iplist.h"
53#include "slcompress.h"
54#include "ipcp.h"
55#include "filter.h"
56#include "ccp.h"
57#include "link.h"
58#include "physical.h"
59#include "mp.h"
60#ifndef NORADIUS
61#include "radius.h"
62#endif
60#include "bundle.h"
61#include "chat.h"
62#include "cbcp.h"
63#include "datalink.h"
64#ifdef HAVE_DES
65#include "chap_ms.h"
66#endif
67

--- 29 unchanged lines hidden (view full) ---

97chap_SendChallenge(struct authinfo *auth, int chapid, struct physical *physical)
98{
99 struct chap *chap = auth2chap(auth);
100 int len, i;
101 char *cp;
102
103 randinit();
104 cp = chap->challenge_data;
63#include "bundle.h"
64#include "chat.h"
65#include "cbcp.h"
66#include "datalink.h"
67#ifdef HAVE_DES
68#include "chap_ms.h"
69#endif
70

--- 29 unchanged lines hidden (view full) ---

100chap_SendChallenge(struct authinfo *auth, int chapid, struct physical *physical)
101{
102 struct chap *chap = auth2chap(auth);
103 int len, i;
104 char *cp;
105
106 randinit();
107 cp = chap->challenge_data;
105 *cp++ = chap->challenge_len = random() % 32 + 16;
106 for (i = 0; i < chap->challenge_len; i++)
107 *cp++ = random() & 0xff;
108 len = strlen(physical->dl->bundle->cfg.auth.name);
109 memcpy(cp, physical->dl->bundle->cfg.auth.name, len);
110 cp += len;
108#ifndef NORADIUS
109 if (*physical->dl->bundle->radius.cfg.file) {
110 /* For radius, our challenge is 16 readable NUL terminated bytes :*/
111 *cp++ = chap->challenge_len = 16;
112 for (i = 0; i < chap->challenge_len; i++)
113 *cp++ = (random() & (0x7f - 0x20)) + 0x20;
114 *cp = '\0';
115 } else {
116#endif
117 *cp++ = chap->challenge_len = random() % (CHAPCHALLENGELEN-16) + 16;
118 for (i = 0; i < chap->challenge_len; i++)
119 *cp++ = random() & 0xff;
120 len = strlen(physical->dl->bundle->cfg.auth.name);
121 memcpy(cp, physical->dl->bundle->cfg.auth.name, len);
122 cp += len;
123#ifndef NORADIUS
124 }
125#endif
111 ChapOutput(physical, CHAP_CHALLENGE, chapid, chap->challenge_data,
112 cp - chap->challenge_data, NULL);
113}
114
115static void
116RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
117 struct physical *physical)
118{
119 int valsize, len;
120 int arglen, keylen, namelen;
121 char *cp, *argp, *ap, *name, *digest;
122 char *keyp;
123 MD5_CTX MD5context; /* context for MD5 */
126 ChapOutput(physical, CHAP_CHALLENGE, chapid, chap->challenge_data,
127 cp - chap->challenge_data, NULL);
128}
129
130static void
131RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
132 struct physical *physical)
133{
134 int valsize, len;
135 int arglen, keylen, namelen;
136 char *cp, *argp, *ap, *name, *digest;
137 char *keyp;
138 MD5_CTX MD5context; /* context for MD5 */
124 char answer[100];
139 char answer[CHAPDIGESTLEN];
125 char cdigest[16];
126#ifdef HAVE_DES
127 int ix;
128 MD4_CTX MD4context; /* context for MD4 */
129#endif
130
131 len = ntohs(chp->length);
132 log_Printf(LogDEBUG, "RecvChapTalk: length: %d\n", len);

--- 76 unchanged lines hidden (view full) ---

209 free(argp);
210 if (*name == '\0')
211 log_Printf(LogWARN, "Sending empty CHAP authname!\n");
212 break;
213 case CHAP_RESPONSE:
214 /*
215 * Get a secret key corresponds to the peer
216 */
140 char cdigest[16];
141#ifdef HAVE_DES
142 int ix;
143 MD4_CTX MD4context; /* context for MD4 */
144#endif
145
146 len = ntohs(chp->length);
147 log_Printf(LogDEBUG, "RecvChapTalk: length: %d\n", len);

--- 76 unchanged lines hidden (view full) ---

224 free(argp);
225 if (*name == '\0')
226 log_Printf(LogWARN, "Sending empty CHAP authname!\n");
227 break;
228 case CHAP_RESPONSE:
229 /*
230 * Get a secret key corresponds to the peer
231 */
217 keyp = auth_GetSecret(bundle, name, namelen, physical);
218 if (keyp) {
219 /*
220 * Compute correct digest value
221 */
232#ifndef NORADIUS
233 if (*bundle->radius.cfg.file) {
234 char chapname[AUTHLEN];
235
236 if (namelen > AUTHLEN - 1)
237 namelen = AUTHLEN - 1;
238 strncpy(chapname, name, namelen);
239 chapname[namelen] = '\0';
240 strncpy(answer, cp-1, 17);
241 answer[17] = '\0';
242
243 if (radius_Authenticate(&bundle->radius, bundle, chapname, answer,
244 physical->dl->chap.challenge_data + 1))
245 break; /* And there was much rejoicing ! */
246
247 } else
248#endif
249 if ((keyp = auth_GetSecret(bundle, name, namelen, physical))) {
250 /* Compute correct digest value */
222 keylen = strlen(keyp);
223 ap = answer;
224 *ap++ = chp->id;
225 memcpy(ap, keyp, keylen);
226 ap += keylen;
227 MD5Init(&MD5context);
228 MD5Update(&MD5context, answer, ap - answer);
229 MD5Update(&MD5context, physical->dl->chap.challenge_data + 1,

--- 92 unchanged lines hidden ---
251 keylen = strlen(keyp);
252 ap = answer;
253 *ap++ = chp->id;
254 memcpy(ap, keyp, keylen);
255 ap += keylen;
256 MD5Init(&MD5context);
257 MD5Update(&MD5context, answer, ap - answer);
258 MD5Update(&MD5context, physical->dl->chap.challenge_data + 1,

--- 92 unchanged lines hidden ---