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

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

Issue 399068: Move base64 from 'net/base' into 'base'. (Closed)
Patch Set: rebase Created 11 years 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_basic.cc ('k') | net/net.gyp » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/string_util.h" 8 #include "base/string_util.h"
8 #include "net/base/base64.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 std::string HttpAuthHandlerNTLM::GenerateCredentials( 13 std::string HttpAuthHandlerNTLM::GenerateCredentials(
14 const std::wstring& username, 14 const std::wstring& username,
15 const std::wstring& password, 15 const std::wstring& password,
16 const HttpRequestInfo* request, 16 const HttpRequestInfo* request,
17 const ProxyInfo* proxy) { 17 const ProxyInfo* proxy) {
18 // TODO(wtc): See if we can use char* instead of void* for in_buf and 18 // TODO(wtc): See if we can use char* instead of void* for in_buf and
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 int len = auth_data_.length(); 50 int len = auth_data_.length();
51 51
52 // Strip off any padding. 52 // Strip off any padding.
53 // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.) 53 // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.)
54 // 54 //
55 // Our base64 decoder requires that the length be a multiple of 4. 55 // Our base64 decoder requires that the length be a multiple of 4.
56 while (len > 0 && len % 4 != 0 && auth_data_[len - 1] == '=') 56 while (len > 0 && len % 4 != 0 && auth_data_[len - 1] == '=')
57 len--; 57 len--;
58 auth_data_.erase(len); 58 auth_data_.erase(len);
59 59
60 if (!Base64Decode(auth_data_, &decoded_auth_data)) 60 if (!base::Base64Decode(auth_data_, &decoded_auth_data))
61 return std::string(); // Improper base64 encoding 61 return std::string(); // Improper base64 encoding
62 in_buf_len = decoded_auth_data.length(); 62 in_buf_len = decoded_auth_data.length();
63 in_buf = decoded_auth_data.data(); 63 in_buf = decoded_auth_data.data();
64 } 64 }
65 65
66 int rv = GetNextToken(in_buf, in_buf_len, &out_buf, &out_buf_len); 66 int rv = GetNextToken(in_buf, in_buf_len, &out_buf, &out_buf_len);
67 if (rv != OK) 67 if (rv != OK)
68 return std::string(); 68 return std::string();
69 69
70 // Base64 encode data in output buffer and prepend "NTLM ". 70 // Base64 encode data in output buffer and prepend "NTLM ".
71 std::string encode_input(static_cast<char*>(out_buf), out_buf_len); 71 std::string encode_input(static_cast<char*>(out_buf), out_buf_len);
72 std::string encode_output; 72 std::string encode_output;
73 bool ok = Base64Encode(encode_input, &encode_output); 73 bool ok = base::Base64Encode(encode_input, &encode_output);
74 // OK, we are done with |out_buf| 74 // OK, we are done with |out_buf|
75 free(out_buf); 75 free(out_buf);
76 if (!ok) 76 if (!ok)
77 return std::string(); 77 return std::string();
78 return std::string("NTLM ") + encode_output; 78 return std::string("NTLM ") + encode_output;
79 } 79 }
80 80
81 // The NTLM challenge header looks like: 81 // The NTLM challenge header looks like:
82 // WWW-Authenticate: NTLM auth-data 82 // WWW-Authenticate: NTLM auth-data
83 bool HttpAuthHandlerNTLM::ParseChallenge( 83 bool HttpAuthHandlerNTLM::ParseChallenge(
(...skipping 15 matching lines...) Expand all
99 // which would be mistaken for a name=value pair. 99 // which would be mistaken for a name=value pair.
100 challenge_begin += 4; // Skip over "NTLM". 100 challenge_begin += 4; // Skip over "NTLM".
101 HttpUtil::TrimLWS(&challenge_begin, &challenge_end); 101 HttpUtil::TrimLWS(&challenge_begin, &challenge_end);
102 102
103 auth_data_.assign(challenge_begin, challenge_end); 103 auth_data_.assign(challenge_begin, challenge_end);
104 104
105 return true; 105 return true;
106 } 106 }
107 107
108 } // namespace net 108 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_basic.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698