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

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

Issue 2904633002: Replace NTLMv1 implementation with a functionally equivalent one.
Patch Set: Cleanup Created 3 years, 5 months 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
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const CompletionCallback& callback, std::string* auth_token) { 42 const CompletionCallback& callback, std::string* auth_token) {
43 #if defined(NTLM_SSPI) 43 #if defined(NTLM_SSPI)
44 return auth_sspi_.GenerateAuthToken(credentials, CreateSPN(origin_), 44 return auth_sspi_.GenerateAuthToken(credentials, CreateSPN(origin_),
45 channel_bindings_, auth_token, callback); 45 channel_bindings_, auth_token, callback);
46 #else // !defined(NTLM_SSPI) 46 #else // !defined(NTLM_SSPI)
47 // TODO(cbentzel): Shouldn't be hitting this case. 47 // TODO(cbentzel): Shouldn't be hitting this case.
48 if (!credentials) { 48 if (!credentials) {
49 LOG(ERROR) << "Username and password are expected to be non-NULL."; 49 LOG(ERROR) << "Username and password are expected to be non-NULL.";
50 return ERR_MISSING_AUTH_CREDENTIALS; 50 return ERR_MISSING_AUTH_CREDENTIALS;
51 } 51 }
52 // TODO(wtc): See if we can use char* instead of void* for in_buf and
53 // out_buf. This change will need to propagate to GetNextToken,
54 // GenerateType1Msg, and GenerateType3Msg, and perhaps further.
55 const void* in_buf;
56 void* out_buf;
57 uint32_t in_buf_len, out_buf_len;
58 std::string decoded_auth_data;
59 52
60 // The username may be in the form "DOMAIN\user". Parse it into the two 53 // The username may be in the form "DOMAIN\user". Parse it into the two
61 // components. 54 // components.
62 base::string16 domain; 55 base::string16 domain;
63 base::string16 user; 56 base::string16 user;
64 const base::string16& username = credentials->username(); 57 const base::string16& username = credentials->username();
65 const base::char16 backslash_character = '\\'; 58 const base::char16 backslash_character = '\\';
66 size_t backslash_idx = username.find(backslash_character); 59 size_t backslash_idx = username.find(backslash_character);
67 if (backslash_idx == base::string16::npos) { 60 if (backslash_idx == base::string16::npos) {
68 user = username; 61 user = username;
69 } else { 62 } else {
70 domain = username.substr(0, backslash_idx); 63 domain = username.substr(0, backslash_idx);
71 user = username.substr(backslash_idx + 1); 64 user = username.substr(backslash_idx + 1);
72 } 65 }
73 domain_ = domain; 66 domain_ = domain;
74 credentials_.Set(user, credentials->password()); 67 credentials_.Set(user, credentials->password());
75 68
76 // Initial challenge. 69 std::string decoded_auth_data;
77 if (auth_data_.empty()) { 70 if (auth_data_.empty()) {
78 in_buf_len = 0; 71 // There is no |auth_data_| because the client sends the first message.
79 in_buf = NULL;
80 int rv = InitializeBeforeFirstChallenge(); 72 int rv = InitializeBeforeFirstChallenge();
81 if (rv != OK) 73 if (rv != OK)
82 return rv; 74 return rv;
83 } else { 75 } else {
76 // When |auth_data_| is present it contains the Challenge message.
84 if (!base::Base64Decode(auth_data_, &decoded_auth_data)) { 77 if (!base::Base64Decode(auth_data_, &decoded_auth_data)) {
85 LOG(ERROR) << "Unexpected problem Base64 decoding."; 78 LOG(ERROR) << "Unexpected problem Base64 decoding.";
86 return ERR_UNEXPECTED; 79 return ERR_UNEXPECTED;
87 } 80 }
88 in_buf_len = decoded_auth_data.length();
89 in_buf = decoded_auth_data.data();
90 } 81 }
91 82
92 int rv = GetNextToken(in_buf, in_buf_len, &out_buf, &out_buf_len); 83 ntlm::Buffer next_token = GetNextToken(
93 if (rv != OK) 84 ntlm::Buffer(reinterpret_cast<const uint8_t*>(decoded_auth_data.data()),
94 return rv; 85 decoded_auth_data.size()));
86 if (next_token.empty())
87 return ERR_UNEXPECTED;
95 88
96 // Base64 encode data in output buffer and prepend "NTLM ". 89 // Base64 encode data in output buffer and prepend "NTLM ".
97 std::string encode_input(static_cast<char*>(out_buf), out_buf_len);
98 std::string encode_output; 90 std::string encode_output;
99 base::Base64Encode(encode_input, &encode_output); 91 base::Base64Encode(
100 // OK, we are done with |out_buf| 92 base::StringPiece(reinterpret_cast<const char*>(next_token.data()),
101 free(out_buf); 93 next_token.size()),
94 &encode_output);
95
102 *auth_token = std::string("NTLM ") + encode_output; 96 *auth_token = std::string("NTLM ") + encode_output;
103 return OK; 97 return OK;
104 #endif 98 #endif
105 } 99 }
106 100
107 // The NTLM challenge header looks like: 101 // The NTLM challenge header looks like:
108 // WWW-Authenticate: NTLM auth-data 102 // WWW-Authenticate: NTLM auth-data
109 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( 103 HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge(
110 HttpAuthChallengeTokenizer* tok, bool initial_challenge) { 104 HttpAuthChallengeTokenizer* tok, bool initial_challenge) {
111 #if defined(NTLM_SSPI) 105 #if defined(NTLM_SSPI)
(...skipping 29 matching lines...) Expand all
141 // static 135 // static
142 std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { 136 std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) {
143 // The service principal name of the destination server. See 137 // The service principal name of the destination server. See
144 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx 138 // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx
145 std::string target("HTTP/"); 139 std::string target("HTTP/");
146 target.append(GetHostAndPort(origin)); 140 target.append(GetHostAndPort(origin));
147 return target; 141 return target;
148 } 142 }
149 143
150 } // namespace net 144 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698