| Index: net/http/http_auth_handler_ntlm_portable.cc
|
| diff --git a/net/http/http_auth_handler_ntlm_portable.cc b/net/http/http_auth_handler_ntlm_portable.cc
|
| index 035a6dc80170c091536c615c49c013332ce13b73..c7e0e9782ffd07840360a30f66519e311c75a7c8 100644
|
| --- a/net/http/http_auth_handler_ntlm_portable.cc
|
| +++ b/net/http/http_auth_handler_ntlm_portable.cc
|
| @@ -72,15 +72,15 @@ namespace net {
|
|
|
| #if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| #define IS_LITTLE_ENDIAN 1
|
| -#undef IS_BIG_ENDIAN
|
| +#undef IS_BIG_ENDIAN
|
| #elif defined(ARCH_CPU_BIG_ENDIAN)
|
| #define IS_BIG_ENDIAN 1
|
| -#undef IS_LITTLE_ENDIAN
|
| +#undef IS_LITTLE_ENDIAN
|
| #else
|
| #error "Unknown endianness"
|
| #endif
|
|
|
| -#define NTLM_LOG(x) ((void) 0)
|
| +#define NTLM_LOG(x) ((void)0)
|
|
|
| //-----------------------------------------------------------------------------
|
| // This file contains a cross-platform NTLM authentication implementation. It
|
| @@ -88,63 +88,60 @@ namespace net {
|
| //-----------------------------------------------------------------------------
|
|
|
| enum {
|
| - NTLM_NegotiateUnicode = 0x00000001,
|
| - NTLM_NegotiateOEM = 0x00000002,
|
| - NTLM_RequestTarget = 0x00000004,
|
| - NTLM_Unknown1 = 0x00000008,
|
| - NTLM_NegotiateSign = 0x00000010,
|
| - NTLM_NegotiateSeal = 0x00000020,
|
| - NTLM_NegotiateDatagramStyle = 0x00000040,
|
| - NTLM_NegotiateLanManagerKey = 0x00000080,
|
| - NTLM_NegotiateNetware = 0x00000100,
|
| - NTLM_NegotiateNTLMKey = 0x00000200,
|
| - NTLM_Unknown2 = 0x00000400,
|
| - NTLM_Unknown3 = 0x00000800,
|
| - NTLM_NegotiateDomainSupplied = 0x00001000,
|
| + NTLM_NegotiateUnicode = 0x00000001,
|
| + NTLM_NegotiateOEM = 0x00000002,
|
| + NTLM_RequestTarget = 0x00000004,
|
| + NTLM_Unknown1 = 0x00000008,
|
| + NTLM_NegotiateSign = 0x00000010,
|
| + NTLM_NegotiateSeal = 0x00000020,
|
| + NTLM_NegotiateDatagramStyle = 0x00000040,
|
| + NTLM_NegotiateLanManagerKey = 0x00000080,
|
| + NTLM_NegotiateNetware = 0x00000100,
|
| + NTLM_NegotiateNTLMKey = 0x00000200,
|
| + NTLM_Unknown2 = 0x00000400,
|
| + NTLM_Unknown3 = 0x00000800,
|
| + NTLM_NegotiateDomainSupplied = 0x00001000,
|
| NTLM_NegotiateWorkstationSupplied = 0x00002000,
|
| - NTLM_NegotiateLocalCall = 0x00004000,
|
| - NTLM_NegotiateAlwaysSign = 0x00008000,
|
| - NTLM_TargetTypeDomain = 0x00010000,
|
| - NTLM_TargetTypeServer = 0x00020000,
|
| - NTLM_TargetTypeShare = 0x00040000,
|
| - NTLM_NegotiateNTLM2Key = 0x00080000,
|
| - NTLM_RequestInitResponse = 0x00100000,
|
| - NTLM_RequestAcceptResponse = 0x00200000,
|
| - NTLM_RequestNonNTSessionKey = 0x00400000,
|
| - NTLM_NegotiateTargetInfo = 0x00800000,
|
| - NTLM_Unknown4 = 0x01000000,
|
| - NTLM_Unknown5 = 0x02000000,
|
| - NTLM_Unknown6 = 0x04000000,
|
| - NTLM_Unknown7 = 0x08000000,
|
| - NTLM_Unknown8 = 0x10000000,
|
| - NTLM_Negotiate128 = 0x20000000,
|
| - NTLM_NegotiateKeyExchange = 0x40000000,
|
| - NTLM_Negotiate56 = 0x80000000
|
| + NTLM_NegotiateLocalCall = 0x00004000,
|
| + NTLM_NegotiateAlwaysSign = 0x00008000,
|
| + NTLM_TargetTypeDomain = 0x00010000,
|
| + NTLM_TargetTypeServer = 0x00020000,
|
| + NTLM_TargetTypeShare = 0x00040000,
|
| + NTLM_NegotiateNTLM2Key = 0x00080000,
|
| + NTLM_RequestInitResponse = 0x00100000,
|
| + NTLM_RequestAcceptResponse = 0x00200000,
|
| + NTLM_RequestNonNTSessionKey = 0x00400000,
|
| + NTLM_NegotiateTargetInfo = 0x00800000,
|
| + NTLM_Unknown4 = 0x01000000,
|
| + NTLM_Unknown5 = 0x02000000,
|
| + NTLM_Unknown6 = 0x04000000,
|
| + NTLM_Unknown7 = 0x08000000,
|
| + NTLM_Unknown8 = 0x10000000,
|
| + NTLM_Negotiate128 = 0x20000000,
|
| + NTLM_NegotiateKeyExchange = 0x40000000,
|
| + NTLM_Negotiate56 = 0x80000000
|
| };
|
|
|
| // We send these flags with our type 1 message.
|
| enum {
|
| - NTLM_TYPE1_FLAGS = (NTLM_NegotiateUnicode |
|
| - NTLM_NegotiateOEM |
|
| - NTLM_RequestTarget |
|
| - NTLM_NegotiateNTLMKey |
|
| - NTLM_NegotiateAlwaysSign |
|
| - NTLM_NegotiateNTLM2Key)
|
| + NTLM_TYPE1_FLAGS =
|
| + (NTLM_NegotiateUnicode | NTLM_NegotiateOEM | NTLM_RequestTarget |
|
| + NTLM_NegotiateNTLMKey |
|
| + NTLM_NegotiateAlwaysSign |
|
| + NTLM_NegotiateNTLM2Key)
|
| };
|
|
|
| static const char NTLM_SIGNATURE[] = "NTLMSSP";
|
| -static const char NTLM_TYPE1_MARKER[] = { 0x01, 0x00, 0x00, 0x00 };
|
| -static const char NTLM_TYPE2_MARKER[] = { 0x02, 0x00, 0x00, 0x00 };
|
| -static const char NTLM_TYPE3_MARKER[] = { 0x03, 0x00, 0x00, 0x00 };
|
| +static const char NTLM_TYPE1_MARKER[] = {0x01, 0x00, 0x00, 0x00};
|
| +static const char NTLM_TYPE2_MARKER[] = {0x02, 0x00, 0x00, 0x00};
|
| +static const char NTLM_TYPE3_MARKER[] = {0x03, 0x00, 0x00, 0x00};
|
|
|
| enum {
|
| NTLM_TYPE1_HEADER_LEN = 32,
|
| NTLM_TYPE2_HEADER_LEN = 32,
|
| NTLM_TYPE3_HEADER_LEN = 64,
|
| -
|
| LM_HASH_LEN = 16,
|
| LM_RESP_LEN = 24,
|
| -
|
| NTLM_HASH_LEN = 16,
|
| NTLM_RESP_LEN = 24
|
| };
|
| @@ -167,9 +164,9 @@ static bool SendLM() {
|
|
|
| //-----------------------------------------------------------------------------
|
|
|
| -#define LogFlags(x) ((void) 0)
|
| -#define LogBuf(a, b, c) ((void) 0)
|
| -#define LogToken(a, b, c) ((void) 0)
|
| +#define LogFlags(x) ((void)0)
|
| +#define LogBuf(a, b, c) ((void)0)
|
| +#define LogToken(a, b, c) ((void)0)
|
|
|
| //-----------------------------------------------------------------------------
|
|
|
| @@ -209,11 +206,12 @@ static void* WriteSecBuf(void* buf, uint16 length, uint32 offset) {
|
| * to pass the same buffer as both input and output, which is a handy way to
|
| * convert the unicode buffer to little-endian on big-endian platforms.
|
| */
|
| -static void* WriteUnicodeLE(
|
| - void* buf, const base::char16* str, uint32 str_len) {
|
| +static void* WriteUnicodeLE(void* buf,
|
| + const base::char16* str,
|
| + uint32 str_len) {
|
| // Convert input string from BE to LE.
|
| uint8* cursor = static_cast<uint8*>(buf);
|
| - const uint8* input = reinterpret_cast<const uint8*>(str);
|
| + const uint8* input = reinterpret_cast<const uint8*>(str);
|
| for (uint32 i = 0; i < str_len; ++i, input += 2, cursor += 2) {
|
| // Allow for the case where |buf == str|.
|
| uint8 temp = input[0];
|
| @@ -225,17 +223,15 @@ static void* WriteUnicodeLE(
|
| #endif
|
|
|
| static uint16 ReadUint16(const uint8*& buf) {
|
| - uint16 x = (static_cast<uint16>(buf[0])) |
|
| - (static_cast<uint16>(buf[1]) << 8);
|
| + uint16 x = (static_cast<uint16>(buf[0])) | (static_cast<uint16>(buf[1]) << 8);
|
| buf += sizeof(x);
|
| return x;
|
| }
|
|
|
| static uint32 ReadUint32(const uint8*& buf) {
|
| - uint32 x = (static_cast<uint32>(buf[0])) |
|
| - (static_cast<uint32>(buf[1]) << 8) |
|
| - (static_cast<uint32>(buf[2]) << 16) |
|
| - (static_cast<uint32>(buf[3]) << 24);
|
| + uint32 x =
|
| + (static_cast<uint32>(buf[0])) | (static_cast<uint32>(buf[1]) << 8) |
|
| + (static_cast<uint32>(buf[2]) << 16) | (static_cast<uint32>(buf[3]) << 24);
|
| buf += sizeof(x);
|
| return x;
|
| }
|
| @@ -261,7 +257,7 @@ static void LM_Hash(const base::string16& password, uint8* hash) {
|
| passbuf.resize(14, '\0');
|
|
|
| uint8 k1[8], k2[8];
|
| - DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()) , k1);
|
| + DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()), k1);
|
| DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()) + 7, k2);
|
| ZapString(&passbuf);
|
|
|
| @@ -289,7 +285,8 @@ static void NTLM_Hash(const base::string16& password, uint8* hash) {
|
| free(passbuf);
|
| #else
|
| weak_crypto::MD4Sum(reinterpret_cast<const uint8*>(password.data()),
|
| - password.length() * 2, hash);
|
| + password.length() * 2,
|
| + hash);
|
| #endif
|
| }
|
|
|
| @@ -312,8 +309,8 @@ static void LM_Response(const uint8* hash,
|
| memcpy(keybytes, hash, 16);
|
| ZapBuf(keybytes + 16, 5);
|
|
|
| - DESMakeKey(keybytes , k1);
|
| - DESMakeKey(keybytes + 7, k2);
|
| + DESMakeKey(keybytes, k1);
|
| + DESMakeKey(keybytes + 7, k2);
|
| DESMakeKey(keybytes + 14, k3);
|
|
|
| DESEncrypt(k1, challenge, response);
|
| @@ -365,10 +362,10 @@ static int GenerateType1Msg(void** out_buf, uint32* out_len) {
|
| }
|
|
|
| struct Type2Msg {
|
| - uint32 flags; // NTLM_Xxx bitwise combination
|
| - uint8 challenge[8]; // 8 byte challenge
|
| - const void* target; // target string (type depends on flags)
|
| - uint32 target_len; // target length in bytes
|
| + uint32 flags; // NTLM_Xxx bitwise combination
|
| + uint8 challenge[8]; // 8 byte challenge
|
| + const void* target; // target string (type depends on flags)
|
| + uint32 target_len; // target length in bytes
|
| };
|
|
|
| // Returns OK or a network error code.
|
| @@ -387,7 +384,7 @@ static int ParseType2Msg(const void* in_buf, uint32 in_len, Type2Msg* msg) {
|
| if (in_len < NTLM_TYPE2_HEADER_LEN)
|
| return ERR_UNEXPECTED;
|
|
|
| - const uint8* cursor = (const uint8*) in_buf;
|
| + const uint8* cursor = (const uint8*)in_buf;
|
|
|
| // verify NTLMSSP signature
|
| if (memcmp(cursor, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE)) != 0)
|
| @@ -401,7 +398,7 @@ static int ParseType2Msg(const void* in_buf, uint32 in_len, Type2Msg* msg) {
|
|
|
| // read target name security buffer
|
| uint32 target_len = ReadUint16(cursor);
|
| - ReadUint16(cursor); // discard next 16-bit value
|
| + ReadUint16(cursor); // discard next 16-bit value
|
| uint32 offset = ReadUint32(cursor); // get offset from in_buf
|
| msg->target_len = 0;
|
| msg->target = NULL;
|
| @@ -409,7 +406,7 @@ static int ParseType2Msg(const void* in_buf, uint32 in_len, Type2Msg* msg) {
|
| // integer overflow checking.
|
| if (offset + target_len > offset && offset + target_len <= in_len) {
|
| msg->target_len = target_len;
|
| - msg->target = ((const uint8*) in_buf) + offset;
|
| + msg->target = ((const uint8*)in_buf) + offset;
|
| }
|
|
|
| // read flags
|
| @@ -420,8 +417,8 @@ static int ParseType2Msg(const void* in_buf, uint32 in_len, Type2Msg* msg) {
|
| cursor += sizeof(msg->challenge);
|
|
|
| NTLM_LOG(("NTLM type 2 message:\n"));
|
| - LogBuf("target", (const uint8*) msg->target, msg->target_len);
|
| - LogBuf("flags", (const uint8*) &msg->flags, 4);
|
| + LogBuf("target", (const uint8*)msg->target, msg->target_len);
|
| + LogBuf("flags", (const uint8*)&msg->flags, 4);
|
| LogFlags(msg->flags);
|
| LogBuf("challenge", msg->challenge, sizeof(msg->challenge));
|
|
|
| @@ -457,7 +454,7 @@ static int GenerateType3Msg(const base::string16& domain,
|
|
|
| bool unicode = (msg.flags & NTLM_NegotiateUnicode) != 0;
|
|
|
| - // Temporary buffers for unicode strings
|
| +// Temporary buffers for unicode strings
|
| #ifdef IS_BIG_ENDIAN
|
| base::string16 ucs_domain_buf, ucs_user_buf;
|
| #endif
|
| @@ -480,7 +477,7 @@ static int GenerateType3Msg(const base::string16& domain,
|
| domain_ptr = ucs_domain_buf.data();
|
| domain_len = ucs_domain_buf.length() * 2;
|
| WriteUnicodeLE(const_cast<void*>(domain_ptr),
|
| - (const base::char16*) domain_ptr,
|
| + (const base::char16*)domain_ptr,
|
| ucs_domain_buf.length());
|
| #else
|
| domain_ptr = domain.data();
|
| @@ -500,7 +497,8 @@ static int GenerateType3Msg(const base::string16& domain,
|
| ucs_user_buf = username;
|
| user_ptr = ucs_user_buf.data();
|
| user_len = ucs_user_buf.length() * 2;
|
| - WriteUnicodeLE(const_cast<void*>(user_ptr), (const base::char16*) user_ptr,
|
| + WriteUnicodeLE(const_cast<void*>(user_ptr),
|
| + (const base::char16*)user_ptr,
|
| ucs_user_buf.length());
|
| #else
|
| user_ptr = username.data();
|
| @@ -521,7 +519,8 @@ static int GenerateType3Msg(const base::string16& domain,
|
| host_ptr = ucs_host_buf.data();
|
| host_len = ucs_host_buf.length() * 2;
|
| #ifdef IS_BIG_ENDIAN
|
| - WriteUnicodeLE(const_cast<void*>(host_ptr), (const base::char16*) host_ptr,
|
| + WriteUnicodeLE(const_cast<void*>(host_ptr),
|
| + (const base::char16*)host_ptr,
|
| ucs_host_buf.length());
|
| #endif
|
| } else {
|
| @@ -625,11 +624,11 @@ static int GenerateType3Msg(const base::string16& domain,
|
|
|
| // static
|
| HttpAuthHandlerNTLM::GenerateRandomProc
|
| -HttpAuthHandlerNTLM::generate_random_proc_ = GenerateRandom;
|
| + HttpAuthHandlerNTLM::generate_random_proc_ = GenerateRandom;
|
|
|
| // static
|
| -HttpAuthHandlerNTLM::HostNameProc
|
| -HttpAuthHandlerNTLM::get_host_name_proc_ = GetHostName;
|
| +HttpAuthHandlerNTLM::HostNameProc HttpAuthHandlerNTLM::get_host_name_proc_ =
|
| + GetHostName;
|
|
|
| HttpAuthHandlerNTLM::HttpAuthHandlerNTLM() {
|
| }
|
| @@ -657,8 +656,7 @@ HttpAuthHandlerNTLM::~HttpAuthHandlerNTLM() {
|
|
|
| // static
|
| HttpAuthHandlerNTLM::GenerateRandomProc
|
| -HttpAuthHandlerNTLM::SetGenerateRandomProc(
|
| - GenerateRandomProc proc) {
|
| +HttpAuthHandlerNTLM::SetGenerateRandomProc(GenerateRandomProc proc) {
|
| GenerateRandomProc old_proc = generate_random_proc_;
|
| generate_random_proc_ = proc;
|
| return old_proc;
|
| @@ -693,9 +691,14 @@ int HttpAuthHandlerNTLM::GetNextToken(const void* in_token,
|
| uint8 rand_buf[8];
|
| generate_random_proc_(rand_buf, 8);
|
| rv = GenerateType3Msg(domain_,
|
| - credentials_.username(), credentials_.password(),
|
| - hostname, rand_buf,
|
| - in_token, in_token_len, out_token, out_token_len);
|
| + credentials_.username(),
|
| + credentials_.password(),
|
| + hostname,
|
| + rand_buf,
|
| + in_token,
|
| + in_token_len,
|
| + out_token,
|
| + out_token_len);
|
| } else {
|
| rv = GenerateType1Msg(out_token, out_token_len);
|
| }
|
|
|