91 static option_t chap_option_list[] = {
93 "Set timeout for CHAP" },
95 "Set max #xmits for challenge" },
97 "Set interval for rechallenge" },
99 {
"ms-lanman", o_bool, &ms_lanman,
100 "Use LanMan passwd when using MS-CHAP", 1 },
109 static void ChapInit (
int);
110 static void ChapLowerUp (
int);
111 static void ChapLowerDown (
int);
112 static void ChapInput (
int, u_char *,
int);
113 static void ChapProtocolReject (
int);
114 #if PPP_ADDITIONAL_CALLBACKS
115 static int ChapPrintPkt (u_char *,
int,
void (*) (
void *,
char *, ...),
void *);
127 #if PPP_ADDITIONAL_CALLBACKS
133 #if PPP_ADDITIONAL_CALLBACKS
142 static void ChapChallengeTimeout (
void *);
143 static void ChapResponseTimeout (
void *);
144 static void ChapReceiveChallenge (
chap_state *, u_char *, u_char,
int);
145 static void ChapRechallenge (
void *);
146 static void ChapReceiveResponse (
chap_state *, u_char *,
int,
int);
147 static void ChapReceiveSuccess(
chap_state *
cstate, u_char *inp, u_char
id,
int len);
148 static void ChapReceiveFailure(
chap_state *
cstate, u_char *inp, u_char
id,
int len);
149 static void ChapSendStatus (
chap_state *,
int);
162 BZERO(cstate,
sizeof(*cstate));
218 ChapGenChallenge(cstate);
219 ChapSendChallenge(cstate);
228 ChapChallengeTimeout(
void *arg)
247 ChapSendChallenge(cstate);
255 ChapResponseTimeout(
void *arg)
264 ChapSendResponse(cstate);
272 ChapRechallenge(
void *arg)
281 ChapGenChallenge(cstate);
282 ChapSendChallenge(cstate);
293 ChapLowerUp(
int unit)
306 ChapGenChallenge(cstate);
307 ChapSendChallenge(cstate);
319 ChapLowerDown(
int unit)
326 UNTIMEOUT(ChapChallengeTimeout, cstate);
329 UNTIMEOUT(ChapRechallenge, cstate);
332 UNTIMEOUT(ChapResponseTimeout, cstate);
343 ChapProtocolReject(
int unit)
363 ChapInput(
int unit, u_char *inpacket,
int packet_len)
386 if (len > packet_len) {
397 ChapReceiveChallenge(cstate, inp,
id, len);
401 ChapReceiveResponse(cstate, inp,
id, len);
405 ChapReceiveFailure(cstate, inp,
id, len);
409 ChapReceiveSuccess(cstate, inp,
id, len);
423 ChapReceiveChallenge(
chap_state *cstate, u_char *inp, u_char
id,
int len)
428 char secret[MAXSECRETLEN];
446 GETCHAR(rchallenge_len, inp);
447 len -=
sizeof (u_char) + rchallenge_len;
453 INCPTR(rchallenge_len, inp);
455 if (len >= (
int)
sizeof(rhostname)) {
456 len =
sizeof(rhostname) - 1;
458 BCOPY(inp, rhostname, len);
459 rhostname[len] =
'\000';
465 if (ppp_settings.remote_name[0] != 0 && (ppp_settings.explicit_remote || rhostname[0] == 0)) {
466 strncpy(rhostname, ppp_settings.remote_name,
sizeof(rhostname));
467 rhostname[
sizeof(rhostname) - 1] = 0;
474 secret, &secret_len, 0)) {
482 UNTIMEOUT(ChapResponseTimeout, cstate);
494 MD5Update(&mdContext, (u_char*)secret, secret_len);
495 MD5Update(&mdContext, rchallenge, rchallenge_len);
503 ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len);
512 BZERO(secret,
sizeof(secret));
513 ChapSendResponse(cstate);
521 ChapReceiveResponse(
chap_state *cstate, u_char *inp,
int id,
int len)
523 u_char *remmd, remmd_len;
524 int secret_len, old_state;
528 char secret[MAXSECRETLEN];
562 GETCHAR(remmd_len, inp);
564 INCPTR(remmd_len, inp);
566 len -=
sizeof (u_char) + remmd_len;
572 UNTIMEOUT(ChapChallengeTimeout, cstate);
574 if (len >= (
int)
sizeof(rhostname)) {
575 len =
sizeof(rhostname) - 1;
577 BCOPY(inp, rhostname, len);
578 rhostname[len] =
'\000';
589 secret, &secret_len, 1)) {
602 MD5Update(&mdContext, (u_char*)secret, secret_len);
617 BZERO(secret,
sizeof(secret));
618 ChapSendStatus(cstate, code);
640 ChapReceiveSuccess(
chap_state *cstate, u_char *inp, u_char
id,
int len)
659 UNTIMEOUT(ChapResponseTimeout, cstate);
678 ChapReceiveFailure(
chap_state *cstate, u_char *inp, u_char
id,
int len)
692 UNTIMEOUT(ChapResponseTimeout, cstate);
713 int chal_len, name_len;
717 name_len = (int)strlen(cstate->
chal_name);
719 outp = outpacket_buf[cstate->
unit];
721 MAKEHEADER(outp, PPP_CHAP);
724 PUTCHAR(cstate->
chal_id, outp);
725 PUTSHORT(outlen, outp);
727 PUTCHAR(chal_len, outp);
728 BCOPY(cstate->
challenge, outp, chal_len);
729 INCPTR(chal_len, outp);
731 BCOPY(cstate->
chal_name, outp, name_len);
733 pppWrite(cstate->
unit, outpacket_buf[cstate->
unit], outlen + PPP_HDRLEN);
737 TIMEOUT(ChapChallengeTimeout, cstate, cstate->
timeouttime);
753 strcpy(msg,
"Welcome!");
755 strcpy(msg,
"I don't like you. Go 'way.");
757 msglen = (int)strlen(msg);
760 outp = outpacket_buf[cstate->
unit];
762 MAKEHEADER(outp, PPP_CHAP);
765 PUTCHAR(cstate->
chal_id, outp);
766 PUTSHORT(outlen, outp);
767 BCOPY(msg, outp, msglen);
768 pppWrite(cstate->
unit, outpacket_buf[cstate->
unit], outlen + PPP_HDRLEN);
790 chal_len = (unsigned)
794 LWIP_ASSERT(
"chal_len <= 0xff", chal_len <= 0xffff);
795 cstate->
chal_len = (u_char)chal_len;
800 for (i = 0; i < chal_len; i++ ) {
801 *ptr++ = (char) (
magic() & 0xff);
814 int outlen, md_len, name_len;
817 name_len = (int)strlen(cstate->
resp_name);
819 outp = outpacket_buf[cstate->
unit];
821 MAKEHEADER(outp, PPP_CHAP);
824 PUTCHAR(cstate->
resp_id, outp);
825 PUTSHORT(outlen, outp);
827 PUTCHAR(md_len, outp);
828 BCOPY(cstate->
response, outp, md_len);
829 INCPTR(md_len, outp);
831 BCOPY(cstate->
resp_name, outp, name_len);
834 pppWrite(cstate->
unit, outpacket_buf[cstate->
unit], outlen + PPP_HDRLEN);
837 TIMEOUT(ChapResponseTimeout, cstate, cstate->
timeouttime);
841 #if PPP_ADDITIONAL_CALLBACKS
842 static char *ChapCodenames[] = {
843 "Challenge",
"Response",
"Success",
"Failure"
849 ChapPrintPkt( u_char *p,
int plen,
void (*printer) (
void *,
char *, ...),
void *arg)
861 if (len < CHAP_HEADERLEN || len > plen) {
865 if (code >= 1 && code <=
sizeof(ChapCodenames) /
sizeof(
char *)) {
866 printer(arg,
" %s", ChapCodenames[code-1]);
868 printer(arg,
" code=0x%x", code);
870 printer(arg,
" id=0x%x",
id);
879 if (len < clen + 1) {
883 nlen = len - clen - 1;
885 for (; clen > 0; --clen) {
887 printer(arg,
"%.2x", x);
889 printer(arg,
">, name = %.*Z", nlen, p);
893 printer(arg,
" %.*Z", len, p);
896 for (clen = len; clen > 0; --clen) {
898 printer(arg,
" %.2x", x);