| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_auth_handler_ntlm.h" | 5 #include "net/http/http_auth_handler_ntlm.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 // For gethostname | 8 // For gethostname |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // param hash | 250 // param hash |
| 251 // 16-byte result buffer | 251 // 16-byte result buffer |
| 252 // | 252 // |
| 253 // Note: This function is not being used because our SendLM() function always | 253 // Note: This function is not being used because our SendLM() function always |
| 254 // returns false. | 254 // returns false. |
| 255 static void LM_Hash(const base::string16& password, uint8* hash) { | 255 static void LM_Hash(const base::string16& password, uint8* hash) { |
| 256 static const uint8 LM_MAGIC[] = "KGS!@#$%"; | 256 static const uint8 LM_MAGIC[] = "KGS!@#$%"; |
| 257 | 257 |
| 258 // Convert password to OEM character set. We'll just use the native | 258 // Convert password to OEM character set. We'll just use the native |
| 259 // filesystem charset. | 259 // filesystem charset. |
| 260 std::string passbuf = base::SysWideToNativeMB(UTF16ToWide(password)); | 260 std::string passbuf = base::SysWideToNativeMB(base::UTF16ToWide(password)); |
| 261 StringToUpperASCII(&passbuf); | 261 StringToUpperASCII(&passbuf); |
| 262 passbuf.resize(14, '\0'); | 262 passbuf.resize(14, '\0'); |
| 263 | 263 |
| 264 uint8 k1[8], k2[8]; | 264 uint8 k1[8], k2[8]; |
| 265 DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()) , k1); | 265 DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()) , k1); |
| 266 DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()) + 7, k2); | 266 DESMakeKey(reinterpret_cast<const uint8*>(passbuf.data()) + 7, k2); |
| 267 ZapString(&passbuf); | 267 ZapString(&passbuf); |
| 268 | 268 |
| 269 // Use password keys to hash LM magic string twice. | 269 // Use password keys to hash LM magic string twice. |
| 270 DESEncrypt(k1, LM_MAGIC, hash); | 270 DESEncrypt(k1, LM_MAGIC, hash); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 ucs_domain_buf = domain; | 480 ucs_domain_buf = domain; |
| 481 domain_ptr = ucs_domain_buf.data(); | 481 domain_ptr = ucs_domain_buf.data(); |
| 482 domain_len = ucs_domain_buf.length() * 2; | 482 domain_len = ucs_domain_buf.length() * 2; |
| 483 WriteUnicodeLE(const_cast<void*>(domain_ptr), (const char16*) domain_ptr, | 483 WriteUnicodeLE(const_cast<void*>(domain_ptr), (const char16*) domain_ptr, |
| 484 ucs_domain_buf.length()); | 484 ucs_domain_buf.length()); |
| 485 #else | 485 #else |
| 486 domain_ptr = domain.data(); | 486 domain_ptr = domain.data(); |
| 487 domain_len = domain.length() * 2; | 487 domain_len = domain.length() * 2; |
| 488 #endif | 488 #endif |
| 489 } else { | 489 } else { |
| 490 oem_domain_buf = base::SysWideToNativeMB(UTF16ToWide(domain)); | 490 oem_domain_buf = base::SysWideToNativeMB(base::UTF16ToWide(domain)); |
| 491 domain_ptr = oem_domain_buf.data(); | 491 domain_ptr = oem_domain_buf.data(); |
| 492 domain_len = oem_domain_buf.length(); | 492 domain_len = oem_domain_buf.length(); |
| 493 } | 493 } |
| 494 | 494 |
| 495 // | 495 // |
| 496 // Get user name. | 496 // Get user name. |
| 497 // | 497 // |
| 498 if (unicode) { | 498 if (unicode) { |
| 499 #ifdef IS_BIG_ENDIAN | 499 #ifdef IS_BIG_ENDIAN |
| 500 ucs_user_buf = username; | 500 ucs_user_buf = username; |
| 501 user_ptr = ucs_user_buf.data(); | 501 user_ptr = ucs_user_buf.data(); |
| 502 user_len = ucs_user_buf.length() * 2; | 502 user_len = ucs_user_buf.length() * 2; |
| 503 WriteUnicodeLE(const_cast<void*>(user_ptr), (const char16*) user_ptr, | 503 WriteUnicodeLE(const_cast<void*>(user_ptr), (const char16*) user_ptr, |
| 504 ucs_user_buf.length()); | 504 ucs_user_buf.length()); |
| 505 #else | 505 #else |
| 506 user_ptr = username.data(); | 506 user_ptr = username.data(); |
| 507 user_len = username.length() * 2; | 507 user_len = username.length() * 2; |
| 508 #endif | 508 #endif |
| 509 } else { | 509 } else { |
| 510 oem_user_buf = base::SysWideToNativeMB(UTF16ToWide(username)); | 510 oem_user_buf = base::SysWideToNativeMB(base::UTF16ToWide(username)); |
| 511 user_ptr = oem_user_buf.data(); | 511 user_ptr = oem_user_buf.data(); |
| 512 user_len = oem_user_buf.length(); | 512 user_len = oem_user_buf.length(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 // | 515 // |
| 516 // Get workstation name (use local machine's hostname). | 516 // Get workstation name (use local machine's hostname). |
| 517 // | 517 // |
| 518 if (unicode) { | 518 if (unicode) { |
| 519 // hostname is ASCII, so we can do a simple zero-pad expansion: | 519 // hostname is ASCII, so we can do a simple zero-pad expansion: |
| 520 ucs_host_buf.assign(hostname.begin(), hostname.end()); | 520 ucs_host_buf.assign(hostname.begin(), hostname.end()); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // NOTE: Default credentials are not supported for the portable implementation | 721 // NOTE: Default credentials are not supported for the portable implementation |
| 722 // of NTLM. | 722 // of NTLM. |
| 723 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM); | 723 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM); |
| 724 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 724 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
| 725 return ERR_INVALID_RESPONSE; | 725 return ERR_INVALID_RESPONSE; |
| 726 handler->swap(tmp_handler); | 726 handler->swap(tmp_handler); |
| 727 return OK; | 727 return OK; |
| 728 } | 728 } |
| 729 | 729 |
| 730 } // namespace net | 730 } // namespace net |
| OLD | NEW |