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

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

Issue 1408433006: Support tls-server-end-point channel bindings for HTTP authentication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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.h" 5 #include "net/http/http_auth.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string_tokenizer.h" 9 #include "base/strings/string_tokenizer.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/http/http_auth_challenge_tokenizer.h" 12 #include "net/http/http_auth_challenge_tokenizer.h"
13 #include "net/http/http_auth_handler.h" 13 #include "net/http/http_auth_handler.h"
14 #include "net/http/http_auth_handler_factory.h" 14 #include "net/http/http_auth_handler_factory.h"
15 #include "net/http/http_auth_scheme.h" 15 #include "net/http/http_auth_scheme.h"
16 #include "net/http/http_request_headers.h" 16 #include "net/http/http_request_headers.h"
17 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
18 #include "net/http/http_response_info.h"
18 #include "net/http/http_util.h" 19 #include "net/http/http_util.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 HttpAuth::Identity::Identity() : source(IDENT_SRC_NONE), invalid(true) {} 23 HttpAuth::Identity::Identity() : source(IDENT_SRC_NONE), invalid(true) {}
23 24
24 // static 25 // static
25 void HttpAuth::ChooseBestChallenge( 26 void HttpAuth::ChooseBestChallenge(
26 HttpAuthHandlerFactory* http_auth_handler_factory, 27 HttpAuthHandlerFactory* http_auth_handler_factory,
27 const HttpResponseHeaders* headers, 28 const HttpResponseInfo& response_info,
28 Target target, 29 Target target,
29 const GURL& origin, 30 const GURL& origin,
30 const std::set<Scheme>& disabled_schemes, 31 const std::set<Scheme>& disabled_schemes,
31 const BoundNetLog& net_log, 32 const BoundNetLog& net_log,
32 scoped_ptr<HttpAuthHandler>* handler) { 33 scoped_ptr<HttpAuthHandler>* handler) {
33 DCHECK(http_auth_handler_factory); 34 DCHECK(http_auth_handler_factory);
35 DCHECK(response_info.headers.get());
34 DCHECK(handler->get() == NULL); 36 DCHECK(handler->get() == NULL);
35 37
36 // Choose the challenge whose authentication handler gives the maximum score. 38 // Choose the challenge whose authentication handler gives the maximum score.
37 scoped_ptr<HttpAuthHandler> best; 39 scoped_ptr<HttpAuthHandler> best;
38 const std::string header_name = GetChallengeHeaderName(target); 40 const std::string header_name = GetChallengeHeaderName(target);
39 std::string cur_challenge; 41 std::string cur_challenge;
40 size_t iter = 0; 42 size_t iter = 0;
41 while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) { 43 while (response_info.headers->EnumerateHeader(&iter, header_name,
44 &cur_challenge)) {
42 scoped_ptr<HttpAuthHandler> cur; 45 scoped_ptr<HttpAuthHandler> cur;
43 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( 46 int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
44 cur_challenge, target, origin, net_log, &cur); 47 cur_challenge, target, response_info, origin, net_log, &cur);
45 if (rv != OK) { 48 if (rv != OK) {
46 VLOG(1) << "Unable to create AuthHandler. Status: " 49 VLOG(1) << "Unable to create AuthHandler. Status: "
47 << ErrorToString(rv) << " Challenge: " << cur_challenge; 50 << ErrorToString(rv) << " Challenge: " << cur_challenge;
48 continue; 51 continue;
49 } 52 }
50 if (cur.get() && (!best.get() || best->score() < cur->score()) && 53 if (cur.get() && (!best.get() || best->score() < cur->score()) &&
51 (disabled_schemes.find(cur->auth_scheme()) == disabled_schemes.end())) 54 (disabled_schemes.find(cur->auth_scheme()) == disabled_schemes.end()))
52 best.swap(cur); 55 best.swap(cur);
53 } 56 }
54 handler->swap(best); 57 handler->swap(best);
55 } 58 }
56 59
57 // static 60 // static
58 HttpAuth::AuthorizationResult HttpAuth::HandleChallengeResponse( 61 HttpAuth::AuthorizationResult HttpAuth::HandleChallengeResponse(
59 HttpAuthHandler* handler, 62 HttpAuthHandler* handler,
60 const HttpResponseHeaders* headers, 63 const HttpResponseInfo& response_info,
61 Target target, 64 Target target,
62 const std::set<Scheme>& disabled_schemes, 65 const std::set<Scheme>& disabled_schemes,
63 std::string* challenge_used) { 66 std::string* challenge_used) {
64 DCHECK(handler); 67 DCHECK(handler);
65 DCHECK(headers); 68 DCHECK(response_info.headers.get());
66 DCHECK(challenge_used); 69 DCHECK(challenge_used);
67 challenge_used->clear(); 70 challenge_used->clear();
68 HttpAuth::Scheme current_scheme = handler->auth_scheme(); 71 HttpAuth::Scheme current_scheme = handler->auth_scheme();
69 if (disabled_schemes.find(current_scheme) != disabled_schemes.end()) 72 if (disabled_schemes.find(current_scheme) != disabled_schemes.end())
70 return HttpAuth::AUTHORIZATION_RESULT_REJECT; 73 return HttpAuth::AUTHORIZATION_RESULT_REJECT;
71 std::string current_scheme_name = SchemeToString(current_scheme); 74 std::string current_scheme_name = SchemeToString(current_scheme);
72 const std::string header_name = GetChallengeHeaderName(target); 75 const std::string header_name = GetChallengeHeaderName(target);
73 size_t iter = 0; 76 size_t iter = 0;
74 std::string challenge; 77 std::string challenge;
75 HttpAuth::AuthorizationResult authorization_result = 78 HttpAuth::AuthorizationResult authorization_result =
76 HttpAuth::AUTHORIZATION_RESULT_INVALID; 79 HttpAuth::AUTHORIZATION_RESULT_INVALID;
77 while (headers->EnumerateHeader(&iter, header_name, &challenge)) { 80 while (
81 response_info.headers->EnumerateHeader(&iter, header_name, &challenge)) {
78 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); 82 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end());
79 if (!base::LowerCaseEqualsASCII(props.scheme(), 83 if (!base::LowerCaseEqualsASCII(props.scheme(),
80 current_scheme_name.c_str())) 84 current_scheme_name.c_str()))
81 continue; 85 continue;
82 authorization_result = handler->HandleAnotherChallenge(&props); 86 authorization_result = handler->HandleAnotherChallenge(&props);
83 if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) { 87 if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) {
84 *challenge_used = challenge; 88 *challenge_used = challenge;
85 return authorization_result; 89 return authorization_result;
86 } 90 }
87 } 91 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 static_assert(arraysize(kSchemeNames) == AUTH_SCHEME_MAX, 140 static_assert(arraysize(kSchemeNames) == AUTH_SCHEME_MAX,
137 "http auth scheme names incorrect size"); 141 "http auth scheme names incorrect size");
138 if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) { 142 if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) {
139 NOTREACHED(); 143 NOTREACHED();
140 return "invalid_scheme"; 144 return "invalid_scheme";
141 } 145 }
142 return kSchemeNames[scheme]; 146 return kSchemeNames[scheme];
143 } 147 }
144 148
145 } // namespace net 149 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698