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

Side by Side Diff: chrome/browser/spdyproxy/http_auth_handler_spdyproxy.cc

Issue 10913238: SPDY proxy authentication support. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/spdyproxy/http_auth_handler_spdyproxy.h"
6
7 #include <string>
8
9 #include "base/i18n/icu_string_conversions.h"
10 #include "base/metrics/histogram.h"
11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h"
13 #include "net/base/net_errors.h"
14 #include "net/http/http_auth.h"
15 #include "net/http/http_request_info.h"
16
17
18 namespace spdyproxy {
19
20 using net::AuthCredentials;
21 using net::BoundNetLog;
22 using net::CompletionCallback;
23 using net::HttpAuth;
24 using net::HttpAuthHandler;
25 using net::HttpAuthHandlerFactory;
26 using net::HttpRequestInfo;
27 using net::HttpUtil;
28
29 HttpAuthHandlerSpdyProxy::Factory::Factory(
30 const GURL& authorized_spdyproxy_origin)
31 : authorized_spdyproxy_origin_(authorized_spdyproxy_origin) {
32 }
33
34 HttpAuthHandlerSpdyProxy::Factory::~Factory() {
35 }
36
37 int HttpAuthHandlerSpdyProxy::Factory::CreateAuthHandler(
38 HttpAuth::ChallengeTokenizer* challenge,
39 HttpAuth::Target target,
40 const GURL& origin,
41 CreateReason reason,
42 int digest_nonce_count,
43 const BoundNetLog& net_log,
44 scoped_ptr<HttpAuthHandler>* handler) {
45 // If a spdyproxy auth proxy has not been set, refuse all requests to use this
46 // auth handler.
47 if (authorized_spdyproxy_origin_.possibly_invalid_spec().empty()) {
48 VLOG(1) << "SpdyProxy auth without configuring authorized origin.";
49 return net::ERR_UNSUPPORTED_AUTH_SCHEME;
50 }
51
52 // We ensure that this authentication handler is used only with an authorized
53 // SPDY proxy, since otherwise a user's authentication token can be
54 // sniffed by a malicious proxy that presents an appropriate challenge.
55 const GURL origin_origin = origin.GetOrigin();
56 if (!(target == HttpAuth::AUTH_PROXY &&
57 origin_origin.SchemeIs("https") &&
cbentzel 2012/09/18 15:30:52 The SchemeIs check here is not needed - it's conta
Michael Piatek 2012/09/18 20:32:05 Done.
58 origin_origin == authorized_spdyproxy_origin_)) {
59 UMA_HISTOGRAM_COUNTS("Net.UnexpectedSpdyProxyAuth", 1);
60 VLOG(1) << "SpdyProxy auth request with an unexpected config."
61 << " origin: " << origin_origin.possibly_invalid_spec()
62 << " authorized_origin: "
63 << authorized_spdyproxy_origin_.possibly_invalid_spec();
64 return net::ERR_UNSUPPORTED_AUTH_SCHEME;
65 }
66
67 scoped_ptr<HttpAuthHandler> tmp_handler(
68 new HttpAuthHandlerSpdyProxy(authorized_spdyproxy_origin_));
69 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
70 return net::ERR_INVALID_RESPONSE;
71 handler->swap(tmp_handler);
72 return net::OK;
73 }
74
75 HttpAuthHandlerSpdyProxy::HttpAuthHandlerSpdyProxy(
76 const GURL& authorized_spdyproxy_origin)
77 : HttpAuthHandler(),
78 authorized_spdyproxy_origin_(authorized_spdyproxy_origin) {
79 }
80
81 HttpAuth::AuthorizationResult
82 HttpAuthHandlerSpdyProxy::HandleAnotherChallenge(
83 HttpAuth::ChallengeTokenizer* challenge) {
84 // SpdyProxy authentication is always a single round, so any responses
85 // should be treated as a rejection.
86 return HttpAuth::AUTHORIZATION_RESULT_REJECT;
87 }
88
89 bool HttpAuthHandlerSpdyProxy::NeedsIdentity() {
90 return true;
91 }
92
93 bool HttpAuthHandlerSpdyProxy::AllowsDefaultCredentials() {
94 return false;
95 }
96
97 bool HttpAuthHandlerSpdyProxy::AllowsExplicitCredentials() {
98 return true;
99 }
100
101 bool HttpAuthHandlerSpdyProxy::Init(
102 HttpAuth::ChallengeTokenizer* challenge) {
103 auth_scheme_ = HttpAuth::AUTH_SCHEME_SPDYPROXY;
104 score_ = 5;
105 properties_ = ENCRYPTS_IDENTITY;
106 return ParseChallenge(challenge);
107 }
108
109 int HttpAuthHandlerSpdyProxy::GenerateAuthTokenImpl(
110 const AuthCredentials* credentials, const HttpRequestInfo* request,
111 const CompletionCallback&, std::string* auth_token) {
112 DCHECK(credentials);
113 if (credentials->password().length() == 0) {
114 DVLOG(1) << "Received a SpdyProxy auth token request without an "
115 << "available token.";
116 return -1;
117 }
118 *auth_token = "SpdyProxy ps=\"" + ps_token_ + "\", sid=\"" +
119 UTF16ToUTF8(credentials->password()) + "\"";
120 return net::OK;
121 }
122
123 bool HttpAuthHandlerSpdyProxy::ParseChallenge(
124 HttpAuth::ChallengeTokenizer* challenge) {
125
126 // Verify the challenge's auth-scheme.
127 if (!LowerCaseEqualsASCII(challenge->scheme(), "spdyproxy")) {
128 VLOG(1) << "Parsed challenge without SpdyProxy type";
129 return false;
130 }
131
132 HttpUtil::NameValuePairsIterator parameters = challenge->param_pairs();
133
134 // Loop through all the properties.
135 while (parameters.GetNext()) {
136 // FAIL -- couldn't parse a property.
137 if (!ParseChallengeProperty(parameters.name(),
138 parameters.value()))
139 return false;
140 }
141 // Check if tokenizer failed.
142 if (!parameters.valid())
143 return false;
144
145 // Check that the required properties were provided.
146 if (realm_.empty())
147 return false;
148
149 if (ps_token_.empty())
150 return false;
151
152 return true;
153 }
154
155 bool HttpAuthHandlerSpdyProxy::ParseChallengeProperty(
156 const std::string& name, const std::string& value) {
157 if (LowerCaseEqualsASCII(name, "realm")) {
158 std::string realm;
159 if (!base::ConvertToUtf8AndNormalize(value, base::kCodepageLatin1, &realm))
160 return false;
161 realm_ = realm;
162 } else if (LowerCaseEqualsASCII(name, "ps")) {
163 ps_token_ = value;
164 } else {
165 VLOG(1) << "Skipping unrecognized SpdyProxy auth property, " << name;
166 }
167 return true;
168 }
169
170
cbentzel 2012/09/18 15:30:52 Nit: extra new line
Michael Piatek 2012/09/18 20:32:05 Done.
171 } // namespace spdyproxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698