| 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 #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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 bool HttpAuthHandlerNTLM::Init(HttpAuthChallengeTokenizer* tok) { | 24 bool HttpAuthHandlerNTLM::Init(HttpAuthChallengeTokenizer* tok) { |
| 25 auth_scheme_ = HttpAuth::AUTH_SCHEME_NTLM; | 25 auth_scheme_ = HttpAuth::AUTH_SCHEME_NTLM; |
| 26 score_ = 3; | 26 score_ = 3; |
| 27 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; | 27 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; |
| 28 | 28 |
| 29 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT; | 29 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT; |
| 30 } | 30 } |
| 31 | 31 |
| 32 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( | 32 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( |
| 33 const AuthCredentials* credentials, const HttpRequestInfo* request, | 33 const AuthCredentials* credentials, |
| 34 const CompletionCallback& callback, std::string* auth_token) { | 34 const HttpRequestInfo* request, |
| 35 const CompletionCallback& callback, |
| 36 std::string* auth_token) { |
| 35 #if defined(NTLM_SSPI) | 37 #if defined(NTLM_SSPI) |
| 36 return auth_sspi_.GenerateAuthToken( | 38 return auth_sspi_.GenerateAuthToken( |
| 37 credentials, | 39 credentials, CreateSPN(origin_), auth_token); |
| 38 CreateSPN(origin_), | |
| 39 auth_token); | |
| 40 #else // !defined(NTLM_SSPI) | 40 #else // !defined(NTLM_SSPI) |
| 41 // TODO(cbentzel): Shouldn't be hitting this case. | 41 // TODO(cbentzel): Shouldn't be hitting this case. |
| 42 if (!credentials) { | 42 if (!credentials) { |
| 43 LOG(ERROR) << "Username and password are expected to be non-NULL."; | 43 LOG(ERROR) << "Username and password are expected to be non-NULL."; |
| 44 return ERR_MISSING_AUTH_CREDENTIALS; | 44 return ERR_MISSING_AUTH_CREDENTIALS; |
| 45 } | 45 } |
| 46 // TODO(wtc): See if we can use char* instead of void* for in_buf and | 46 // TODO(wtc): See if we can use char* instead of void* for in_buf and |
| 47 // out_buf. This change will need to propagate to GetNextToken, | 47 // out_buf. This change will need to propagate to GetNextToken, |
| 48 // GenerateType1Msg, and GenerateType3Msg, and perhaps further. | 48 // GenerateType1Msg, and GenerateType3Msg, and perhaps further. |
| 49 const void* in_buf; | 49 const void* in_buf; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // OK, we are done with |out_buf| | 94 // OK, we are done with |out_buf| |
| 95 free(out_buf); | 95 free(out_buf); |
| 96 *auth_token = std::string("NTLM ") + encode_output; | 96 *auth_token = std::string("NTLM ") + encode_output; |
| 97 return OK; | 97 return OK; |
| 98 #endif | 98 #endif |
| 99 } | 99 } |
| 100 | 100 |
| 101 // The NTLM challenge header looks like: | 101 // The NTLM challenge header looks like: |
| 102 // WWW-Authenticate: NTLM auth-data | 102 // WWW-Authenticate: NTLM auth-data |
| 103 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( | 103 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( |
| 104 HttpAuthChallengeTokenizer* tok, bool initial_challenge) { | 104 HttpAuthChallengeTokenizer* tok, |
| 105 bool initial_challenge) { |
| 105 #if defined(NTLM_SSPI) | 106 #if defined(NTLM_SSPI) |
| 106 // auth_sspi_ contains state for whether or not this is the initial challenge. | 107 // auth_sspi_ contains state for whether or not this is the initial challenge. |
| 107 return auth_sspi_.ParseChallenge(tok); | 108 return auth_sspi_.ParseChallenge(tok); |
| 108 #else | 109 #else |
| 109 // TODO(cbentzel): Most of the logic between SSPI, GSSAPI, and portable NTLM | 110 // TODO(cbentzel): Most of the logic between SSPI, GSSAPI, and portable NTLM |
| 110 // authentication parsing could probably be shared - just need to know if | 111 // authentication parsing could probably be shared - just need to know if |
| 111 // there was previously a challenge round. | 112 // there was previously a challenge round. |
| 112 // TODO(cbentzel): Write a test case to validate that auth_data_ is left empty | 113 // TODO(cbentzel): Write a test case to validate that auth_data_ is left empty |
| 113 // in all failure conditions. | 114 // in all failure conditions. |
| 114 auth_data_.clear(); | 115 auth_data_.clear(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 135 // static | 136 // static |
| 136 std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { | 137 std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { |
| 137 // The service principal name of the destination server. See | 138 // The service principal name of the destination server. See |
| 138 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx | 139 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx |
| 139 std::string target("HTTP/"); | 140 std::string target("HTTP/"); |
| 140 target.append(GetHostAndPort(origin)); | 141 target.append(GetHostAndPort(origin)); |
| 141 return target; | 142 return target; |
| 142 } | 143 } |
| 143 | 144 |
| 144 } // namespace net | 145 } // namespace net |
| OLD | NEW |