| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( | 16 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( |
| 17 const std::wstring* username, | 17 const string16* username, |
| 18 const std::wstring* password, | 18 const string16* password, |
| 19 const HttpRequestInfo* request, | 19 const HttpRequestInfo* request, |
| 20 CompletionCallback* callback, | 20 CompletionCallback* callback, |
| 21 std::string* auth_token) { | 21 std::string* auth_token) { |
| 22 #if defined(NTLM_SSPI) | 22 #if defined(NTLM_SSPI) |
| 23 return auth_sspi_.GenerateAuthToken( | 23 return auth_sspi_.GenerateAuthToken( |
| 24 username, | 24 username, |
| 25 password, | 25 password, |
| 26 CreateSPN(origin_), | 26 CreateSPN(origin_), |
| 27 auth_token); | 27 auth_token); |
| 28 #else // !defined(NTLM_SSPI) | 28 #else // !defined(NTLM_SSPI) |
| 29 // TODO(wtc): See if we can use char* instead of void* for in_buf and | 29 // TODO(wtc): See if we can use char* instead of void* for in_buf and |
| 30 // out_buf. This change will need to propagate to GetNextToken, | 30 // out_buf. This change will need to propagate to GetNextToken, |
| 31 // GenerateType1Msg, and GenerateType3Msg, and perhaps further. | 31 // GenerateType1Msg, and GenerateType3Msg, and perhaps further. |
| 32 const void* in_buf; | 32 const void* in_buf; |
| 33 void* out_buf; | 33 void* out_buf; |
| 34 uint32 in_buf_len, out_buf_len; | 34 uint32 in_buf_len, out_buf_len; |
| 35 std::string decoded_auth_data; | 35 std::string decoded_auth_data; |
| 36 | 36 |
| 37 // |username| may be in the form "DOMAIN\user". Parse it into the two | 37 // |username| may be in the form "DOMAIN\user". Parse it into the two |
| 38 // components. | 38 // components. |
| 39 std::wstring domain; | 39 string16 domain; |
| 40 std::wstring user; | 40 string16 user; |
| 41 size_t backslash_idx = username->find(L'\\'); | 41 size_t backslash_idx = username->find(L'\\'); |
| 42 if (backslash_idx == std::wstring::npos) { | 42 if (backslash_idx == std::wstring::npos) { |
| 43 user = *username; | 43 user = *username; |
| 44 } else { | 44 } else { |
| 45 domain = username->substr(0, backslash_idx); | 45 domain = username->substr(0, backslash_idx); |
| 46 user = username->substr(backslash_idx + 1); | 46 user = username->substr(backslash_idx + 1); |
| 47 } | 47 } |
| 48 domain_ = WideToUTF16(domain); | 48 domain_ = domain; |
| 49 username_ = WideToUTF16(user); | 49 username_ = user; |
| 50 password_ = WideToUTF16(*password); | 50 password_ = *password; |
| 51 | 51 |
| 52 // Initial challenge. | 52 // Initial challenge. |
| 53 if (auth_data_.empty()) { | 53 if (auth_data_.empty()) { |
| 54 in_buf_len = 0; | 54 in_buf_len = 0; |
| 55 in_buf = NULL; | 55 in_buf = NULL; |
| 56 int rv = InitializeBeforeFirstChallenge(); | 56 int rv = InitializeBeforeFirstChallenge(); |
| 57 if (rv != OK) | 57 if (rv != OK) |
| 58 return rv; | 58 return rv; |
| 59 } else { | 59 } else { |
| 60 if (!base::Base64Decode(auth_data_, &decoded_auth_data)) { | 60 if (!base::Base64Decode(auth_data_, &decoded_auth_data)) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // static | 111 // static |
| 112 std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { | 112 std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { |
| 113 // The service principal name of the destination server. See | 113 // The service principal name of the destination server. See |
| 114 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx | 114 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx |
| 115 std::wstring target(L"HTTP/"); | 115 std::wstring target(L"HTTP/"); |
| 116 target.append(ASCIIToWide(GetHostAndPort(origin))); | 116 target.append(ASCIIToWide(GetHostAndPort(origin))); |
| 117 return target; | 117 return target; |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace net | 120 } // namespace net |
| OLD | NEW |