OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
11 #elif defined(OS_WIN) | 11 #elif defined(OS_WIN) |
12 #include <winsock2.h> | 12 #include <winsock2.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include "base/md5.h" | 15 #include "base/md5.h" |
16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/sys_string_conversions.h" | 18 #include "base/sys_string_conversions.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 #include "net/base/zap.h" |
22 #include "net/http/des.h" | 23 #include "net/http/des.h" |
23 #include "net/http/md4.h" | 24 #include "net/http/md4.h" |
24 | 25 |
25 namespace net { | 26 namespace net { |
26 | 27 |
27 // Based on mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, | 28 // Based on mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, |
28 // CVS rev. 1.14. | 29 // CVS rev. 1.14. |
29 // | 30 // |
30 // TODO(wtc): | 31 // TODO(wtc): |
31 // - The IS_BIG_ENDIAN code is not tested. | 32 // - The IS_BIG_ENDIAN code is not tested. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 uint32 x = (static_cast<uint32>(buf[0])) | | 232 uint32 x = (static_cast<uint32>(buf[0])) | |
232 (static_cast<uint32>(buf[1]) << 8) | | 233 (static_cast<uint32>(buf[1]) << 8) | |
233 (static_cast<uint32>(buf[2]) << 16) | | 234 (static_cast<uint32>(buf[2]) << 16) | |
234 (static_cast<uint32>(buf[3]) << 24); | 235 (static_cast<uint32>(buf[3]) << 24); |
235 buf += sizeof(x); | 236 buf += sizeof(x); |
236 return x; | 237 return x; |
237 } | 238 } |
238 | 239 |
239 //----------------------------------------------------------------------------- | 240 //----------------------------------------------------------------------------- |
240 | 241 |
241 static void ZapBuf(void* buf, size_t buf_len) { | |
242 memset(buf, 0, buf_len); | |
243 } | |
244 | |
245 // TODO(wtc): Can we implement ZapString as | |
246 // s.replace(0, s.size(), s.size(), '\0)? | |
247 static void ZapString(std::string* s) { | |
248 ZapBuf(&(*s)[0], s->length()); | |
249 } | |
250 | |
251 static void ZapString(string16* s) { | |
252 ZapBuf(&(*s)[0], s->length() * 2); | |
253 } | |
254 | |
255 // LM_Hash computes the LM hash of the given password. | 242 // LM_Hash computes the LM hash of the given password. |
256 // | 243 // |
257 // param password | 244 // param password |
258 // unicode password. | 245 // unicode password. |
259 // param hash | 246 // param hash |
260 // 16-byte result buffer | 247 // 16-byte result buffer |
261 // | 248 // |
262 // Note: This function is not being used because our SendLM() function always | 249 // Note: This function is not being used because our SendLM() function always |
263 // returns false. | 250 // returns false. |
264 static void LM_Hash(const string16& password, uint8* hash) { | 251 static void LM_Hash(const string16& password, uint8* hash) { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 // Default credentials are not supported in the portable implementation of | 641 // Default credentials are not supported in the portable implementation of |
655 // NTLM, but are supported in the SSPI implementation. | 642 // NTLM, but are supported in the SSPI implementation. |
656 return false; | 643 return false; |
657 } | 644 } |
658 | 645 |
659 int HttpAuthHandlerNTLM::InitializeBeforeFirstChallenge() { | 646 int HttpAuthHandlerNTLM::InitializeBeforeFirstChallenge() { |
660 return OK; | 647 return OK; |
661 } | 648 } |
662 | 649 |
663 HttpAuthHandlerNTLM::~HttpAuthHandlerNTLM() { | 650 HttpAuthHandlerNTLM::~HttpAuthHandlerNTLM() { |
664 // Wipe our copy of the password from memory, to reduce the chance of being | 651 credentials_.Zap(); |
665 // written to the paging file on disk. | |
666 ZapString(&password_); | |
667 } | 652 } |
668 | 653 |
669 // static | 654 // static |
670 HttpAuthHandlerNTLM::GenerateRandomProc | 655 HttpAuthHandlerNTLM::GenerateRandomProc |
671 HttpAuthHandlerNTLM::SetGenerateRandomProc( | 656 HttpAuthHandlerNTLM::SetGenerateRandomProc( |
672 GenerateRandomProc proc) { | 657 GenerateRandomProc proc) { |
673 GenerateRandomProc old_proc = generate_random_proc_; | 658 GenerateRandomProc old_proc = generate_random_proc_; |
674 generate_random_proc_ = proc; | 659 generate_random_proc_ = proc; |
675 return old_proc; | 660 return old_proc; |
676 } | 661 } |
(...skipping 19 matching lines...) Expand all Loading... |
696 int rv = 0; | 681 int rv = 0; |
697 | 682 |
698 // If in_token is non-null, then assume it contains a type 2 message... | 683 // If in_token is non-null, then assume it contains a type 2 message... |
699 if (in_token) { | 684 if (in_token) { |
700 LogToken("in-token", in_token, in_token_len); | 685 LogToken("in-token", in_token, in_token_len); |
701 std::string hostname = get_host_name_proc_(); | 686 std::string hostname = get_host_name_proc_(); |
702 if (hostname.empty()) | 687 if (hostname.empty()) |
703 return ERR_UNEXPECTED; | 688 return ERR_UNEXPECTED; |
704 uint8 rand_buf[8]; | 689 uint8 rand_buf[8]; |
705 generate_random_proc_(rand_buf, 8); | 690 generate_random_proc_(rand_buf, 8); |
706 rv = GenerateType3Msg(domain_, username_, password_, hostname, rand_buf, | 691 rv = GenerateType3Msg(domain_, |
| 692 credentials_.username(), credentials_.password(), |
| 693 hostname, rand_buf, |
707 in_token, in_token_len, out_token, out_token_len); | 694 in_token, in_token_len, out_token, out_token_len); |
708 } else { | 695 } else { |
709 rv = GenerateType1Msg(out_token, out_token_len); | 696 rv = GenerateType1Msg(out_token, out_token_len); |
710 } | 697 } |
711 | 698 |
712 if (rv == OK) | 699 if (rv == OK) |
713 LogToken("out-token", *out_token, *out_token_len); | 700 LogToken("out-token", *out_token, *out_token_len); |
714 | 701 |
715 return rv; | 702 return rv; |
716 } | 703 } |
(...skipping 13 matching lines...) Expand all Loading... |
730 // NOTE: Default credentials are not supported for the portable implementation | 717 // NOTE: Default credentials are not supported for the portable implementation |
731 // of NTLM. | 718 // of NTLM. |
732 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM); | 719 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM); |
733 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 720 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
734 return ERR_INVALID_RESPONSE; | 721 return ERR_INVALID_RESPONSE; |
735 handler->swap(tmp_handler); | 722 handler->swap(tmp_handler); |
736 return OK; | 723 return OK; |
737 } | 724 } |
738 | 725 |
739 } // namespace net | 726 } // namespace net |
OLD | NEW |