Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Side by Side Diff: net/http/http_auth_handler_ntlm.cc

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_auth_handler_ntlm.h ('k') | net/http/http_auth_handler_ntlm_portable.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 11 matching lines...) Expand all
22 22
23 bool HttpAuthHandlerNTLM::Init(HttpAuth::ChallengeTokenizer* tok) { 23 bool HttpAuthHandlerNTLM::Init(HttpAuth::ChallengeTokenizer* tok) {
24 auth_scheme_ = HttpAuth::AUTH_SCHEME_NTLM; 24 auth_scheme_ = HttpAuth::AUTH_SCHEME_NTLM;
25 score_ = 3; 25 score_ = 3;
26 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED; 26 properties_ = ENCRYPTS_IDENTITY | IS_CONNECTION_BASED;
27 27
28 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT; 28 return ParseChallenge(tok, true) == HttpAuth::AUTHORIZATION_RESULT_ACCEPT;
29 } 29 }
30 30
31 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( 31 int HttpAuthHandlerNTLM::GenerateAuthTokenImpl(
32 const string16* username, 32 const AuthCredentials* credentials,
33 const string16* password,
34 const HttpRequestInfo* request, 33 const HttpRequestInfo* request,
35 OldCompletionCallback* callback, 34 OldCompletionCallback* callback,
36 std::string* auth_token) { 35 std::string* auth_token) {
37 #if defined(NTLM_SSPI) 36 #if defined(NTLM_SSPI)
38 return auth_sspi_.GenerateAuthToken( 37 return auth_sspi_.GenerateAuthToken(
39 username, 38 credentials,
40 password,
41 CreateSPN(origin_), 39 CreateSPN(origin_),
42 auth_token); 40 auth_token);
43 #else // !defined(NTLM_SSPI) 41 #else // !defined(NTLM_SSPI)
44 // TODO(cbentzel): Shouldn't be hitting this case. 42 // TODO(cbentzel): Shouldn't be hitting this case.
45 if (!username || !password) { 43 if (!credentials) {
46 LOG(ERROR) << "Username and password are expected to be non-NULL."; 44 LOG(ERROR) << "Username and password are expected to be non-NULL.";
47 return ERR_MISSING_AUTH_CREDENTIALS; 45 return ERR_MISSING_AUTH_CREDENTIALS;
48 } 46 }
49 // TODO(wtc): See if we can use char* instead of void* for in_buf and 47 // TODO(wtc): See if we can use char* instead of void* for in_buf and
50 // out_buf. This change will need to propagate to GetNextToken, 48 // out_buf. This change will need to propagate to GetNextToken,
51 // GenerateType1Msg, and GenerateType3Msg, and perhaps further. 49 // GenerateType1Msg, and GenerateType3Msg, and perhaps further.
52 const void* in_buf; 50 const void* in_buf;
53 void* out_buf; 51 void* out_buf;
54 uint32 in_buf_len, out_buf_len; 52 uint32 in_buf_len, out_buf_len;
55 std::string decoded_auth_data; 53 std::string decoded_auth_data;
56 54
57 // |username| may be in the form "DOMAIN\user". Parse it into the two 55 // The username may be in the form "DOMAIN\user". Parse it into the two
58 // components. 56 // components.
59 string16 domain; 57 string16 domain;
60 string16 user; 58 string16 user;
59 const string16& username = credentials->username();
61 const char16 backslash_character = '\\'; 60 const char16 backslash_character = '\\';
62 size_t backslash_idx = username->find(backslash_character); 61 size_t backslash_idx = username.find(backslash_character);
63 if (backslash_idx == string16::npos) { 62 if (backslash_idx == string16::npos) {
64 user = *username; 63 user = username;
65 } else { 64 } else {
66 domain = username->substr(0, backslash_idx); 65 domain = username.substr(0, backslash_idx);
67 user = username->substr(backslash_idx + 1); 66 user = username.substr(backslash_idx + 1);
68 } 67 }
69 domain_ = domain; 68 domain_ = domain;
70 username_ = user; 69 credentials_.Set(user, credentials->password());
71 password_ = *password;
72 70
73 // Initial challenge. 71 // Initial challenge.
74 if (auth_data_.empty()) { 72 if (auth_data_.empty()) {
75 in_buf_len = 0; 73 in_buf_len = 0;
76 in_buf = NULL; 74 in_buf = NULL;
77 int rv = InitializeBeforeFirstChallenge(); 75 int rv = InitializeBeforeFirstChallenge();
78 if (rv != OK) 76 if (rv != OK)
79 return rv; 77 return rv;
80 } else { 78 } else {
81 if (!base::Base64Decode(auth_data_, &decoded_auth_data)) { 79 if (!base::Base64Decode(auth_data_, &decoded_auth_data)) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // static 140 // static
143 std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { 141 std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) {
144 // The service principal name of the destination server. See 142 // The service principal name of the destination server. See
145 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx 143 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx
146 std::wstring target(L"HTTP/"); 144 std::wstring target(L"HTTP/");
147 target.append(ASCIIToWide(GetHostAndPort(origin))); 145 target.append(ASCIIToWide(GetHostAndPort(origin)));
148 return target; 146 return target;
149 } 147 }
150 148
151 } // namespace net 149 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_ntlm.h ('k') | net/http/http_auth_handler_ntlm_portable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698