X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fchap_ms.c;h=eb0c2c14e5d3b6c7b55fe5840fa5ef236133fd31;hp=68026299bff1a50031d08c870c567a32f7030b9d;hb=561ca44f6fd1eb282cb5998dd5ecf8a8aa34f77a;hpb=36fd2fc5935d930a724007be7990b5b82d53e72a diff --git a/pppd/chap_ms.c b/pppd/chap_ms.c index 6802629..eb0c2c1 100644 --- a/pppd/chap_ms.c +++ b/pppd/chap_ms.c @@ -31,23 +31,31 @@ * You should also use DOMAIN\\USERNAME as described in README.MSCHAP80 */ -#ifndef lint -static char rcsid[] = "$Id: chap_ms.c,v 1.3 1997/04/30 05:51:40 paulus Exp $"; -#endif +#define RCSID "$Id: chap_ms.c,v 1.15 1999/08/13 06:46:12 paulus Exp $" #ifdef CHAPMS #include +#include +#include +#include #include #include -#include +#include +#ifdef HAVE_CRYPT_H +#include +#endif #include "pppd.h" #include "chap.h" #include "chap_ms.h" #include "md4.h" +#ifndef USE_CRYPT #include +#endif + +static const char rcsid[] = RCSID; typedef struct { u_char LANManResp[24]; @@ -58,14 +66,25 @@ typedef struct { in case this struct gets padded. */ +static void ChallengeResponse __P((u_char *, u_char *, u_char *)); static void DesEncrypt __P((u_char *, u_char *, u_char *)); static void MakeKey __P((u_char *, u_char *)); +static u_char Get7Bits __P((u_char *, int)); +static void ChapMS_NT __P((char *, int, char *, int, MS_ChapResponse *)); +#ifdef MSLANMAN +static void ChapMS_LANMan __P((char *, int, char *, int, MS_ChapResponse *)); +#endif #ifdef USE_CRYPT static void Expand __P((u_char *, u_char *)); static void Collapse __P((u_char *, u_char *)); #endif +#ifdef MSLANMAN +bool ms_lanman = 0; /* Use LanMan password instead of NT */ + /* Has meaning only with MS-CHAP challenges */ +#endif + static void ChallengeResponse(challenge, pwHash, response) u_char *challenge; /* IN 8 octets */ @@ -75,10 +94,11 @@ ChallengeResponse(challenge, pwHash, response) char ZPasswordHash[21]; BZERO(ZPasswordHash, sizeof(ZPasswordHash)); - BCOPY(pwHash, ZPasswordHash, 16); + BCOPY(pwHash, ZPasswordHash, MD4_SIGNATURE_SIZE); #if 0 - log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG); + dbglog("ChallengeResponse - ZPasswordHash %.*B", + sizeof(ZPasswordHash), ZPasswordHash); #endif DesEncrypt(challenge, ZPasswordHash + 0, response + 0); @@ -86,7 +106,7 @@ ChallengeResponse(challenge, pwHash, response) DesEncrypt(challenge, ZPasswordHash + 14, response + 16); #if 0 - log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG); + dbglog("ChallengeResponse - response %.24B", response); #endif } @@ -108,8 +128,7 @@ DesEncrypt(clear, key, cipher) setkey(crypt_key); #if 0 - CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X", - clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7])); + CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %.8B", clear)); #endif Expand(clear, des_input); @@ -117,8 +136,7 @@ DesEncrypt(clear, key, cipher) Collapse(des_input, cipher); #if 0 - CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X", - cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7])); + CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %.8B", cipher)); #endif } @@ -138,15 +156,13 @@ DesEncrypt(clear, key, cipher) des_set_key(&des_key, key_schedule); #if 0 - CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X", - clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7])); + CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %.8B", clear)); #endif des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1); #if 0 - CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X", - cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7])); + CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %.8B", cipher)); #endif } @@ -225,10 +241,8 @@ static void MakeKey(key, des_key) #endif #if 0 - CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X", - key[0], key[1], key[2], key[3], key[4], key[5], key[6])); - CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X", - des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7])); + CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %.7B", key)); + CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %.8B", des_key)); #endif } @@ -241,9 +255,15 @@ ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, response) MS_ChapResponse *response; { int i; - MDstruct md4Context; +#ifdef __NetBSD__ + /* NetBSD uses the libc md4 routines which take bytes instead of bits */ + int mdlen = secret_len * 2; +#else + int mdlen = secret_len * 2 * 8; +#endif + MD4_CTX md4Context; + u_char hash[MD4_SIGNATURE_SIZE]; u_char unicodePassword[MAX_NT_PASSWORD * 2]; - static int low_byte_first = -1; /* Initialize the Unicode version of the secret (== password). */ /* This implicitly supports 8-bit ISO8859/1 characters. */ @@ -251,22 +271,19 @@ ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, response) for (i = 0; i < secret_len; i++) unicodePassword[i * 2] = (u_char)secret[i]; - MDbegin(&md4Context); - MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */ + MD4Init(&md4Context); + MD4Update(&md4Context, unicodePassword, mdlen); - if (low_byte_first == -1) - low_byte_first = (htons((unsigned short int)1) != 1); - if (low_byte_first == 0) - MDreverse(&md4Context); /* sfb 961105 */ + MD4Final(hash, &md4Context); /* Tell MD4 we're done */ - MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */ - - ChallengeResponse(rchallenge, (char *)md4Context.buffer, response->NTResp); + ChallengeResponse(rchallenge, hash, response->NTResp); } -static u_char *StdText = "KGS!@#$%"; /* key from rasapi32.dll */ +#ifdef MSLANMAN +static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */ -static ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, response) +static void +ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, response) char *rchallenge; int rchallenge_len; char *secret; @@ -275,7 +292,7 @@ static ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, response) { int i; u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */ - u_char PasswordHash[16]; + u_char PasswordHash[MD4_SIGNATURE_SIZE]; /* LANMan password is case insensitive */ BZERO(UcasePassword, sizeof(UcasePassword)); @@ -285,6 +302,7 @@ static ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, response) DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 ); ChallengeResponse(rchallenge, PasswordHash, response->LANManResp); } +#endif void ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len) @@ -303,10 +321,15 @@ ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len) /* Calculate both always */ ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response); + +#ifdef MSLANMAN ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response); /* prefered method is set by option */ response.UseNT = !ms_lanman; +#else + response.UseNT = 1; +#endif BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN); cstate->resp_length = MS_CHAP_RESPONSE_LEN;