| 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 #if !defined(NTLM_SSPI) | 7 #if !defined(NTLM_SSPI) |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #endif | 9 #endif |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::HandleAnotherChallenge( |
| 19 HttpAuth::ChallengeTokenizer* challenge) { |
| 20 return ParseChallenge(challenge, false); |
| 21 } |
| 22 |
| 23 bool HttpAuthHandlerNTLM::Init(HttpAuth::ChallengeTokenizer* tok) { |
| 24 auth_scheme_ = HttpAuth::AUTH_SCHEME_NTLM; |
| 25 score_ = 3; |
| 26 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; |
| 27 |
| 28 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT; |
| 29 } |
| 30 |
| 18 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( | 31 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( |
| 19 const string16* username, | 32 const string16* username, |
| 20 const string16* password, | 33 const string16* password, |
| 21 const HttpRequestInfo* request, | 34 const HttpRequestInfo* request, |
| 22 CompletionCallback* callback, | 35 CompletionCallback* callback, |
| 23 std::string* auth_token) { | 36 std::string* auth_token) { |
| 24 #if defined(NTLM_SSPI) | 37 #if defined(NTLM_SSPI) |
| 25 return auth_sspi_.GenerateAuthToken( | 38 return auth_sspi_.GenerateAuthToken( |
| 26 username, | 39 username, |
| 27 password, | 40 password, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 free(out_buf); | 98 free(out_buf); |
| 86 if (!base64_rv) { | 99 if (!base64_rv) { |
| 87 LOG(ERROR) << "Unexpected problem Base64 encoding."; | 100 LOG(ERROR) << "Unexpected problem Base64 encoding."; |
| 88 return ERR_UNEXPECTED; | 101 return ERR_UNEXPECTED; |
| 89 } | 102 } |
| 90 *auth_token = std::string("NTLM ") + encode_output; | 103 *auth_token = std::string("NTLM ") + encode_output; |
| 91 return OK; | 104 return OK; |
| 92 #endif | 105 #endif |
| 93 } | 106 } |
| 94 | 107 |
| 95 bool HttpAuthHandlerNTLM::Init(HttpAuth::ChallengeTokenizer* tok) { | |
| 96 auth_scheme_ = HttpAuth::AUTH_SCHEME_NTLM; | |
| 97 score_ = 3; | |
| 98 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; | |
| 99 | |
| 100 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT; | |
| 101 } | |
| 102 | |
| 103 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::HandleAnotherChallenge( | |
| 104 HttpAuth::ChallengeTokenizer* challenge) { | |
| 105 return ParseChallenge(challenge, false); | |
| 106 } | |
| 107 | |
| 108 // The NTLM challenge header looks like: | 108 // The NTLM challenge header looks like: |
| 109 // WWW-Authenticate: NTLM auth-data | 109 // WWW-Authenticate: NTLM auth-data |
| 110 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( | 110 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( |
| 111 HttpAuth::ChallengeTokenizer* tok, bool initial_challenge) { | 111 HttpAuth::ChallengeTokenizer* tok, bool initial_challenge) { |
| 112 #if defined(NTLM_SSPI) | 112 #if defined(NTLM_SSPI) |
| 113 // auth_sspi_ contains state for whether or not this is the initial challenge. | 113 // auth_sspi_ contains state for whether or not this is the initial challenge. |
| 114 return auth_sspi_.ParseChallenge(tok); | 114 return auth_sspi_.ParseChallenge(tok); |
| 115 #else | 115 #else |
| 116 // TODO(cbentzel): Most of the logic between SSPI, GSSAPI, and portable NTLM | 116 // TODO(cbentzel): Most of the logic between SSPI, GSSAPI, and portable NTLM |
| 117 // authentication parsing could probably be shared - just need to know if | 117 // authentication parsing could probably be shared - just need to know if |
| (...skipping 24 matching lines...) Expand all Loading... |
| 142 // static | 142 // static |
| 143 std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { | 143 std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { |
| 144 // The service principal name of the destination server. See | 144 // The service principal name of the destination server. See |
| 145 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx | 145 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx |
| 146 std::wstring target(L"HTTP/"); | 146 std::wstring target(L"HTTP/"); |
| 147 target.append(ASCIIToWide(GetHostAndPort(origin))); | 147 target.append(ASCIIToWide(GetHostAndPort(origin))); |
| 148 return target; | 148 return target; |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace net | 151 } // namespace net |
| OLD | NEW |