77 #include "netif/ppp/ppp_opts.h" 78 #if PPP_SUPPORT && MSCHAP_SUPPORT 85 #include <sys/types.h> 90 #include "netif/ppp/ppp_impl.h" 92 #include "netif/ppp/chap-new.h" 93 #include "netif/ppp/chap_ms.h" 94 #include "netif/ppp/pppcrypt.h" 95 #include "netif/ppp/magic.h" 97 #include "netif/ppp/mppe.h" 100 #define SHA1_SIGNATURE_SIZE 20 101 #define MD4_SIGNATURE_SIZE 16 102 #define MAX_NT_PASSWORD 256 104 #define MS_CHAP_RESPONSE_LEN 49 105 #define MS_CHAP2_RESPONSE_LEN 49 106 #define MS_AUTH_RESPONSE_LENGTH 40 110 #define MS_CHAP_ERROR_RESTRICTED_LOGON_HOURS 646 111 #define MS_CHAP_ERROR_ACCT_DISABLED 647 112 #define MS_CHAP_ERROR_PASSWD_EXPIRED 648 113 #define MS_CHAP_ERROR_NO_DIALIN_PERMISSION 649 114 #define MS_CHAP_ERROR_AUTHENTICATION_FAILURE 691 115 #define MS_CHAP_ERROR_CHANGING_PASSWORD 709 120 #define MS_CHAP_LANMANRESP 0 121 #define MS_CHAP_LANMANRESP_LEN 24 122 #define MS_CHAP_NTRESP 24 123 #define MS_CHAP_NTRESP_LEN 24 124 #define MS_CHAP_USENT 48 129 #define MS_CHAP2_PEER_CHALLENGE 0 130 #define MS_CHAP2_PEER_CHAL_LEN 16 131 #define MS_CHAP2_RESERVED_LEN 8 132 #define MS_CHAP2_NTRESP 24 133 #define MS_CHAP2_NTRESP_LEN 24 134 #define MS_CHAP2_FLAGS 48 139 #define MPPE_ENC_POL_ENC_ALLOWED 1 140 #define MPPE_ENC_POL_ENC_REQUIRED 2 141 #define MPPE_ENC_TYPES_RC4_40 2 142 #define MPPE_ENC_TYPES_RC4_128 4 145 extern void set_mppe_enc_types(
int,
int);
150 #define MS_CHAP2_AUTHENTICATEE 0 151 #define MS_CHAP2_AUTHENTICATOR 1 153 static void ascii2unicode (
const char[],
int, u_char[]);
154 static void NTPasswordHash (u_char *,
int, u_char[MD4_SIGNATURE_SIZE]);
155 static void ChallengeResponse (
const u_char *,
const u_char *, u_char[24]);
156 static void ChallengeHash (
const u_char[16],
const u_char *,
const char *, u_char[8]);
157 static void ChapMS_NT (
const u_char *,
const char *,
int, u_char[24]);
158 static void ChapMS2_NT (
const u_char *,
const u_char[16],
const char *,
const char *,
int,
160 static void GenerateAuthenticatorResponsePlain
161 (
const char*,
int, u_char[24],
const u_char[16],
const u_char *,
162 const char *, u_char[41]);
164 static void ChapMS_LANMan (u_char *,
char *,
int, u_char *);
167 static void GenerateAuthenticatorResponse(
const u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
168 u_char NTResponse[24],
const u_char PeerChallenge[16],
169 const u_char *rchallenge,
const char *username,
170 u_char authResponse[MS_AUTH_RESPONSE_LENGTH+1]);
173 static void Set_Start_Key (ppp_pcb *pcb,
const u_char *,
const char *,
int);
174 static void SetMasterKeys (ppp_pcb *pcb,
const char *,
int, u_char[24],
int);
177 static void ChapMS (ppp_pcb *pcb,
const u_char *,
const char *,
int, u_char *);
178 static void ChapMS2 (ppp_pcb *pcb,
const u_char *,
const u_char *,
const char *,
const char *,
int,
179 u_char *, u_char[MS_AUTH_RESPONSE_LENGTH+1],
int);
190 static char *mschap_challenge = NULL;
192 static char *mschap2_peer_challenge = NULL;
195 #include "netif/ppp/fsm.h" 196 #include "netif/ppp/ccp.h" 203 static option_t chapms_option_list[] = {
205 {
"ms-lanman", o_bool, &ms_lanman,
206 "Use LanMan passwd when using MS-CHAP", 1 },
209 {
"mschap-challenge", o_string, &mschap_challenge,
210 "specify CHAP challenge" },
211 {
"mschap2-peer-challenge", o_string, &mschap2_peer_challenge,
212 "specify CHAP peer challenge" },
225 static void chapms_generate_challenge(ppp_pcb *pcb,
unsigned char *challenge) {
230 if (mschap_challenge && strlen(mschap_challenge) == 8)
231 memcpy(challenge, mschap_challenge, 8);
234 magic_random_bytes(challenge, 8);
237 static void chapms2_generate_challenge(ppp_pcb *pcb,
unsigned char *challenge) {
242 if (mschap_challenge && strlen(mschap_challenge) == 16)
243 memcpy(challenge, mschap_challenge, 16);
246 magic_random_bytes(challenge, 16);
249 static int chapms_verify_response(ppp_pcb *pcb,
int id,
const char *name,
250 const unsigned char *secret,
int secret_len,
251 const unsigned char *challenge,
const unsigned char *response,
252 char *message,
int message_space) {
253 unsigned char md[MS_CHAP_RESPONSE_LEN];
255 int challenge_len, response_len;
259 challenge_len = *challenge++;
260 response_len = *response++;
261 if (response_len != MS_CHAP_RESPONSE_LEN)
265 if (!response[MS_CHAP_USENT]) {
267 ppp_notice(
"Peer request for LANMAN auth not supported");
273 ChapMS(pcb, (
const u_char *)challenge, (
const char *)secret, secret_len, md);
277 if (!response[MS_CHAP_USENT])
278 diff = memcmp(&response[MS_CHAP_LANMANRESP],
279 &md[MS_CHAP_LANMANRESP], MS_CHAP_LANMANRESP_LEN);
282 diff = memcmp(&response[MS_CHAP_NTRESP], &md[MS_CHAP_NTRESP],
286 ppp_slprintf(message, message_space,
"Access granted");
292 ppp_slprintf(message, message_space,
"E=691 R=1 C=%0.*B V=0",
293 challenge_len, challenge);
297 static int chapms2_verify_response(ppp_pcb *pcb,
int id,
const char *name,
298 const unsigned char *secret,
int secret_len,
299 const unsigned char *challenge,
const unsigned char *response,
300 char *message,
int message_space) {
301 unsigned char md[MS_CHAP2_RESPONSE_LEN];
302 char saresponse[MS_AUTH_RESPONSE_LENGTH+1];
303 int challenge_len, response_len;
306 challenge_len = *challenge++;
307 response_len = *response++;
308 if (response_len != MS_CHAP2_RESPONSE_LEN)
312 ChapMS2(pcb, (
const u_char*)challenge, (
const u_char*)&response[MS_CHAP2_PEER_CHALLENGE], name,
313 (
const char *)secret, secret_len, md,
314 (
unsigned char *)saresponse, MS_CHAP2_AUTHENTICATOR);
336 if (memcmp(&md[MS_CHAP2_NTRESP], &response[MS_CHAP2_NTRESP],
337 MS_CHAP2_NTRESP_LEN) == 0) {
338 if (response[MS_CHAP2_FLAGS])
339 ppp_slprintf(message, message_space,
"S=%s", saresponse);
341 ppp_slprintf(message, message_space,
"S=%s M=%s",
342 saresponse,
"Access granted");
368 ppp_slprintf(message, message_space,
"E=691 R=1 C=%0.*B V=0 M=%s",
369 challenge_len, challenge,
"Access denied");
374 static void chapms_make_response(ppp_pcb *pcb,
unsigned char *response,
int id,
const char *our_name,
375 const unsigned char *challenge,
const char *secret,
int secret_len,
376 unsigned char *private_) {
381 *response++ = MS_CHAP_RESPONSE_LEN;
382 ChapMS(pcb, challenge, secret, secret_len, response);
385 static void chapms2_make_response(ppp_pcb *pcb,
unsigned char *response,
int id,
const char *our_name,
386 const unsigned char *challenge,
const char *secret,
int secret_len,
387 unsigned char *private_) {
390 *response++ = MS_CHAP2_RESPONSE_LEN;
391 ChapMS2(pcb, challenge,
393 mschap2_peer_challenge,
397 our_name, secret, secret_len, response, private_,
398 MS_CHAP2_AUTHENTICATEE);
401 static int chapms2_check_success(ppp_pcb *pcb,
unsigned char *msg,
int len,
unsigned char *private_) {
404 if ((len < MS_AUTH_RESPONSE_LENGTH + 2) ||
405 strncmp((
char *)msg,
"S=", 2) != 0) {
407 ppp_error(
"MS-CHAPv2 Success packet is badly formed.");
412 if (len < MS_AUTH_RESPONSE_LENGTH
413 || memcmp(msg, private_, MS_AUTH_RESPONSE_LENGTH)) {
415 ppp_error(
"MS-CHAPv2 mutual authentication failed.");
419 msg += MS_AUTH_RESPONSE_LENGTH;
420 len -= MS_AUTH_RESPONSE_LENGTH;
421 if ((len >= 3) && !strncmp((
char *)msg,
" M=", 3)) {
425 ppp_error(
"MS-CHAPv2 Success packet is badly formed.");
431 static void chapms_handle_failure(ppp_pcb *pcb,
unsigned char *inp,
int len) {
438 len = LWIP_MIN(len, 63);
439 MEMCPY(msg, inp, len);
449 if (!strncmp(p,
"E=", 2))
450 err = strtol(p+2, NULL, 10);
454 if (len && ((p = strstr(p,
" M=")) != NULL)) {
460 case MS_CHAP_ERROR_RESTRICTED_LOGON_HOURS:
461 p =
"E=646 Restricted logon hours";
464 case MS_CHAP_ERROR_ACCT_DISABLED:
465 p =
"E=647 Account disabled";
468 case MS_CHAP_ERROR_PASSWD_EXPIRED:
469 p =
"E=648 Password expired";
472 case MS_CHAP_ERROR_NO_DIALIN_PERMISSION:
473 p =
"E=649 No dialin permission";
476 case MS_CHAP_ERROR_AUTHENTICATION_FAILURE:
477 p =
"E=691 Authentication failure";
480 case MS_CHAP_ERROR_CHANGING_PASSWORD:
482 p =
"E=709 Error changing password";
486 ppp_error(
"Unknown MS-CHAP authentication failure: %.*v",
493 ppp_error(
"MS-CHAP authentication failed: %v", p);
496 static void ChallengeResponse(
const u_char *challenge,
497 const u_char PasswordHash[MD4_SIGNATURE_SIZE],
498 u_char response[24]) {
499 u_char ZPasswordHash[21];
500 lwip_des_context des;
503 BZERO(ZPasswordHash,
sizeof(ZPasswordHash));
504 MEMCPY(ZPasswordHash, PasswordHash, MD4_SIGNATURE_SIZE);
507 dbglog(
"ChallengeResponse - ZPasswordHash %.*B",
508 sizeof(ZPasswordHash), ZPasswordHash);
511 pppcrypt_56_to_64_bit_key(ZPasswordHash + 0, des_key);
513 lwip_des_setkey_enc(&des, des_key);
514 lwip_des_crypt_ecb(&des, challenge, response +0);
517 pppcrypt_56_to_64_bit_key(ZPasswordHash + 7, des_key);
519 lwip_des_setkey_enc(&des, des_key);
520 lwip_des_crypt_ecb(&des, challenge, response +8);
523 pppcrypt_56_to_64_bit_key(ZPasswordHash + 14, des_key);
525 lwip_des_setkey_enc(&des, des_key);
526 lwip_des_crypt_ecb(&des, challenge, response +16);
530 dbglog(
"ChallengeResponse - response %.24B", response);
534 static void ChallengeHash(
const u_char PeerChallenge[16],
const u_char *rchallenge,
535 const char *username, u_char Challenge[8]) {
536 lwip_sha1_context sha1Context;
537 u_char sha1Hash[SHA1_SIGNATURE_SIZE];
541 if ((user = strrchr(username,
'\\')) != NULL)
546 lwip_sha1_init(&sha1Context);
547 lwip_sha1_starts(&sha1Context);
548 lwip_sha1_update(&sha1Context, PeerChallenge, 16);
549 lwip_sha1_update(&sha1Context, rchallenge, 16);
550 lwip_sha1_update(&sha1Context, (
const unsigned char*)user, strlen(user));
551 lwip_sha1_finish(&sha1Context, sha1Hash);
552 lwip_sha1_free(&sha1Context);
554 MEMCPY(Challenge, sha1Hash, 8);
564 static void ascii2unicode(
const char ascii[],
int ascii_len, u_char unicode[]) {
567 BZERO(unicode, ascii_len * 2);
568 for (i = 0; i < ascii_len; i++)
569 unicode[i * 2] = (u_char) ascii[i];
572 static void NTPasswordHash(u_char *secret,
int secret_len, u_char hash[MD4_SIGNATURE_SIZE]) {
573 lwip_md4_context md4Context;
575 lwip_md4_init(&md4Context);
576 lwip_md4_starts(&md4Context);
577 lwip_md4_update(&md4Context, secret, secret_len);
578 lwip_md4_finish(&md4Context, hash);
579 lwip_md4_free(&md4Context);
582 static void ChapMS_NT(
const u_char *rchallenge,
const char *secret,
int secret_len,
583 u_char NTResponse[24]) {
584 u_char unicodePassword[MAX_NT_PASSWORD * 2];
585 u_char PasswordHash[MD4_SIGNATURE_SIZE];
588 ascii2unicode(secret, secret_len, unicodePassword);
589 NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash);
591 ChallengeResponse(rchallenge, PasswordHash, NTResponse);
594 static void ChapMS2_NT(
const u_char *rchallenge,
const u_char PeerChallenge[16],
const char *username,
595 const char *secret,
int secret_len, u_char NTResponse[24]) {
596 u_char unicodePassword[MAX_NT_PASSWORD * 2];
597 u_char PasswordHash[MD4_SIGNATURE_SIZE];
600 ChallengeHash(PeerChallenge, rchallenge, username, Challenge);
603 ascii2unicode(secret, secret_len, unicodePassword);
604 NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash);
606 ChallengeResponse(Challenge, PasswordHash, NTResponse);
610 static u_char *StdText = (u_char *)
"KGS!@#$%";
612 static void ChapMS_LANMan(u_char *rchallenge,
char *secret,
int secret_len,
613 unsigned char *response) {
615 u_char UcasePassword[MAX_NT_PASSWORD];
616 u_char PasswordHash[MD4_SIGNATURE_SIZE];
617 lwip_des_context des;
621 BZERO(UcasePassword,
sizeof(UcasePassword));
622 for (i = 0; i < secret_len; i++)
623 UcasePassword[i] = (u_char)toupper(secret[i]);
625 pppcrypt_56_to_64_bit_key(UcasePassword +0, des_key);
627 lwip_des_setkey_enc(&des, des_key);
628 lwip_des_crypt_ecb(&des, StdText, PasswordHash +0);
631 pppcrypt_56_to_64_bit_key(UcasePassword +7, des_key);
633 lwip_des_setkey_enc(&des, des_key);
634 lwip_des_crypt_ecb(&des, StdText, PasswordHash +8);
637 ChallengeResponse(rchallenge, PasswordHash, &response[MS_CHAP_LANMANRESP]);
642 static void GenerateAuthenticatorResponse(
const u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
643 u_char NTResponse[24],
const u_char PeerChallenge[16],
644 const u_char *rchallenge,
const char *username,
645 u_char authResponse[MS_AUTH_RESPONSE_LENGTH+1]) {
649 static const u_char Magic1[39] =
650 { 0x4D, 0x61, 0x67, 0x69, 0x63, 0x20, 0x73, 0x65, 0x72, 0x76,
651 0x65, 0x72, 0x20, 0x74, 0x6F, 0x20, 0x63, 0x6C, 0x69, 0x65,
652 0x6E, 0x74, 0x20, 0x73, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67,
653 0x20, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x74 };
654 static const u_char Magic2[41] =
655 { 0x50, 0x61, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x6D, 0x61, 0x6B,
656 0x65, 0x20, 0x69, 0x74, 0x20, 0x64, 0x6F, 0x20, 0x6D, 0x6F,
657 0x72, 0x65, 0x20, 0x74, 0x68, 0x61, 0x6E, 0x20, 0x6F, 0x6E,
658 0x65, 0x20, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6F,
662 lwip_sha1_context sha1Context;
663 u_char Digest[SHA1_SIGNATURE_SIZE];
666 lwip_sha1_init(&sha1Context);
667 lwip_sha1_starts(&sha1Context);
668 lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
669 lwip_sha1_update(&sha1Context, NTResponse, 24);
670 lwip_sha1_update(&sha1Context, Magic1,
sizeof(Magic1));
671 lwip_sha1_finish(&sha1Context, Digest);
672 lwip_sha1_free(&sha1Context);
674 ChallengeHash(PeerChallenge, rchallenge, username, Challenge);
676 lwip_sha1_init(&sha1Context);
677 lwip_sha1_starts(&sha1Context);
678 lwip_sha1_update(&sha1Context, Digest,
sizeof(Digest));
679 lwip_sha1_update(&sha1Context, Challenge,
sizeof(Challenge));
680 lwip_sha1_update(&sha1Context, Magic2,
sizeof(Magic2));
681 lwip_sha1_finish(&sha1Context, Digest);
682 lwip_sha1_free(&sha1Context);
685 for (i = 0; i < LWIP_MAX((MS_AUTH_RESPONSE_LENGTH / 2), (
int)
sizeof(Digest)); i++)
686 sprintf((
char *)&authResponse[i * 2],
"%02X", Digest[i]);
690 static void GenerateAuthenticatorResponsePlain(
691 const char *secret,
int secret_len,
692 u_char NTResponse[24],
const u_char PeerChallenge[16],
693 const u_char *rchallenge,
const char *username,
694 u_char authResponse[MS_AUTH_RESPONSE_LENGTH+1]) {
695 u_char unicodePassword[MAX_NT_PASSWORD * 2];
696 u_char PasswordHash[MD4_SIGNATURE_SIZE];
697 u_char PasswordHashHash[MD4_SIGNATURE_SIZE];
700 ascii2unicode(secret, secret_len, unicodePassword);
701 NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash);
702 NTPasswordHash(PasswordHash,
sizeof(PasswordHash),
705 GenerateAuthenticatorResponse(PasswordHashHash, NTResponse, PeerChallenge,
706 rchallenge, username, authResponse);
714 static void Set_Start_Key(ppp_pcb *pcb,
const u_char *rchallenge,
const char *secret,
int secret_len) {
715 u_char unicodePassword[MAX_NT_PASSWORD * 2];
716 u_char PasswordHash[MD4_SIGNATURE_SIZE];
717 u_char PasswordHashHash[MD4_SIGNATURE_SIZE];
718 lwip_sha1_context sha1Context;
719 u_char Digest[SHA1_SIGNATURE_SIZE];
722 ascii2unicode(secret, secret_len, unicodePassword);
723 NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash);
724 NTPasswordHash(PasswordHash,
sizeof(PasswordHash), PasswordHashHash);
726 lwip_sha1_init(&sha1Context);
727 lwip_sha1_starts(&sha1Context);
728 lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
729 lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
730 lwip_sha1_update(&sha1Context, rchallenge, 8);
731 lwip_sha1_finish(&sha1Context, Digest);
732 lwip_sha1_free(&sha1Context);
735 mppe_set_key(pcb, &pcb->mppe_comp, Digest);
736 mppe_set_key(pcb, &pcb->mppe_decomp, Digest);
738 pcb->mppe_keys_set = 1;
744 static void SetMasterKeys(ppp_pcb *pcb,
const char *secret,
int secret_len, u_char NTResponse[24],
int IsServer) {
745 u_char unicodePassword[MAX_NT_PASSWORD * 2];
746 u_char PasswordHash[MD4_SIGNATURE_SIZE];
747 u_char PasswordHashHash[MD4_SIGNATURE_SIZE];
748 lwip_sha1_context sha1Context;
749 u_char MasterKey[SHA1_SIGNATURE_SIZE];
750 u_char Digest[SHA1_SIGNATURE_SIZE];
754 static const u_char Magic1[27] =
755 { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74,
756 0x68, 0x65, 0x20, 0x4d, 0x50, 0x50, 0x45, 0x20, 0x4d,
757 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x4b, 0x65, 0x79 };
760 static const u_char Magic2[84] =
761 { 0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x69,
762 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20,
763 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
764 0x65, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
765 0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73,
766 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x73, 0x69, 0x64, 0x65,
767 0x2c, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
768 0x65, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
769 0x6b, 0x65, 0x79, 0x2e };
772 static const u_char Magic3[84] =
773 { 0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x69,
774 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20,
775 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
776 0x65, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
777 0x6b, 0x65, 0x79, 0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68,
778 0x65, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x73,
779 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73,
780 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x20,
781 0x6b, 0x65, 0x79, 0x2e };
784 ascii2unicode(secret, secret_len, unicodePassword);
785 NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash);
786 NTPasswordHash(PasswordHash,
sizeof(PasswordHash), PasswordHashHash);
788 lwip_sha1_init(&sha1Context);
789 lwip_sha1_starts(&sha1Context);
790 lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
791 lwip_sha1_update(&sha1Context, NTResponse, 24);
792 lwip_sha1_update(&sha1Context, Magic1,
sizeof(Magic1));
793 lwip_sha1_finish(&sha1Context, MasterKey);
794 lwip_sha1_free(&sha1Context);
803 lwip_sha1_init(&sha1Context);
804 lwip_sha1_starts(&sha1Context);
805 lwip_sha1_update(&sha1Context, MasterKey, 16);
806 lwip_sha1_update(&sha1Context, mppe_sha1_pad1, SHA1_PAD_SIZE);
807 lwip_sha1_update(&sha1Context, s, 84);
808 lwip_sha1_update(&sha1Context, mppe_sha1_pad2, SHA1_PAD_SIZE);
809 lwip_sha1_finish(&sha1Context, Digest);
810 lwip_sha1_free(&sha1Context);
812 mppe_set_key(pcb, &pcb->mppe_comp, Digest);
821 lwip_sha1_init(&sha1Context);
822 lwip_sha1_starts(&sha1Context);
823 lwip_sha1_update(&sha1Context, MasterKey, 16);
824 lwip_sha1_update(&sha1Context, mppe_sha1_pad1, SHA1_PAD_SIZE);
825 lwip_sha1_update(&sha1Context, s, 84);
826 lwip_sha1_update(&sha1Context, mppe_sha1_pad2, SHA1_PAD_SIZE);
827 lwip_sha1_finish(&sha1Context, Digest);
828 lwip_sha1_free(&sha1Context);
830 mppe_set_key(pcb, &pcb->mppe_decomp, Digest);
832 pcb->mppe_keys_set = 1;
838 static void ChapMS(ppp_pcb *pcb,
const u_char *rchallenge,
const char *secret,
int secret_len,
839 unsigned char *response) {
843 BZERO(response, MS_CHAP_RESPONSE_LEN);
845 ChapMS_NT(rchallenge, secret, secret_len, &response[MS_CHAP_NTRESP]);
848 ChapMS_LANMan(rchallenge, secret, secret_len,
849 &response[MS_CHAP_LANMANRESP]);
852 response[MS_CHAP_USENT] = !ms_lanman;
854 response[MS_CHAP_USENT] = 1;
858 Set_Start_Key(pcb, rchallenge, secret, secret_len);
873 static void ChapMS2(ppp_pcb *pcb,
const u_char *rchallenge,
const u_char *PeerChallenge,
874 const char *user,
const char *secret,
int secret_len,
unsigned char *response,
875 u_char authResponse[],
int authenticator) {
882 BZERO(response, MS_CHAP2_RESPONSE_LEN);
886 magic_random_bytes(&response[MS_CHAP2_PEER_CHALLENGE], MS_CHAP2_PEER_CHAL_LEN);
888 MEMCPY(&response[MS_CHAP2_PEER_CHALLENGE], PeerChallenge,
889 MS_CHAP2_PEER_CHAL_LEN);
892 ChapMS2_NT(rchallenge, &response[MS_CHAP2_PEER_CHALLENGE], user,
893 secret, secret_len, &response[MS_CHAP2_NTRESP]);
896 GenerateAuthenticatorResponsePlain(secret, secret_len,
897 &response[MS_CHAP2_NTRESP],
898 &response[MS_CHAP2_PEER_CHALLENGE],
899 rchallenge, user, authResponse);
902 SetMasterKeys(pcb, secret, secret_len,
903 &response[MS_CHAP2_NTRESP], authenticator);
912 void set_mppe_enc_types(
int policy,
int types) {
914 if (policy != MPPE_ENC_POL_ENC_ALLOWED ||
915 policy != MPPE_ENC_POL_ENC_REQUIRED)
919 if (policy == MPPE_ENC_POL_ENC_ALLOWED && !ccp_wantoptions[0].mppe)
927 case MPPE_ENC_TYPES_RC4_40:
928 ccp_wantoptions[0].mppe &= ~MPPE_OPT_128;
930 case MPPE_ENC_TYPES_RC4_128:
931 ccp_wantoptions[0].mppe &= ~MPPE_OPT_40;
940 const struct chap_digest_type chapms_digest = {
943 chapms_generate_challenge,
944 chapms_verify_response,
946 chapms_make_response,
948 chapms_handle_failure,
951 const struct chap_digest_type chapms2_digest = {
954 chapms2_generate_challenge,
955 chapms2_verify_response,
957 chapms2_make_response,
958 chapms2_check_success,
959 chapms_handle_failure,
#define LWIP_UNUSED_ARG(x)