OLD | NEW |
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 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_NEGOTIATE_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_NEGOTIATE_H_ |
6 #define NET_HTTP_HTTP_AUTH_HANDLER_NEGOTIATE_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_NEGOTIATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
14 #include "net/http/http_auth_handler.h" | 14 #include "net/http/http_auth_handler.h" |
15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
16 | 16 |
17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
18 #include "net/http/http_auth_sspi_win.h" | 18 #include "net/http/http_auth_sspi_win.h" |
19 #endif | 19 #elif defined(OS_POSIX) |
20 | |
21 #if defined(OS_POSIX) | |
22 #include "net/http/http_auth_gssapi_posix.h" | 20 #include "net/http/http_auth_gssapi_posix.h" |
23 #endif | 21 #endif |
24 | 22 |
25 namespace net { | 23 namespace net { |
26 | 24 |
27 class HostResolver; | 25 class HostResolver; |
28 class SingleRequestHostResolver; | 26 class SingleRequestHostResolver; |
29 class URLSecurityManager; | 27 class URLSecurityManager; |
30 | 28 |
31 // Handler for WWW-Authenticate: Negotiate protocol. | 29 // Handler for WWW-Authenticate: Negotiate protocol. |
32 // | 30 // |
33 // See http://tools.ietf.org/html/rfc4178 and http://tools.ietf.org/html/rfc4559 | 31 // See http://tools.ietf.org/html/rfc4178 and http://tools.ietf.org/html/rfc4559 |
34 // for more information about the protocol. | 32 // for more information about the protocol. |
35 | 33 |
36 class HttpAuthHandlerNegotiate : public HttpAuthHandler { | 34 class HttpAuthHandlerNegotiate : public HttpAuthHandler { |
37 public: | 35 public: |
| 36 #if defined(OS_WIN) |
| 37 typedef SSPILibrary AuthLibrary; |
| 38 typedef HttpAuthSSPI AuthSystem; |
| 39 #elif defined(OS_POSIX) |
| 40 typedef GSSAPILibrary AuthLibrary; |
| 41 typedef HttpAuthGSSAPI AuthSystem; |
| 42 #endif |
| 43 |
38 class Factory : public HttpAuthHandlerFactory { | 44 class Factory : public HttpAuthHandlerFactory { |
39 public: | 45 public: |
40 Factory(); | 46 Factory(); |
41 virtual ~Factory(); | 47 virtual ~Factory(); |
42 | 48 |
43 // |disable_cname_lookup()| and |set_disable_cname_lookup()| get/set whether | 49 // |disable_cname_lookup()| and |set_disable_cname_lookup()| get/set whether |
44 // the auth handlers generated by this factory should skip looking up the | 50 // the auth handlers generated by this factory should skip looking up the |
45 // canonical DNS name of the the host that they are authenticating to when | 51 // canonical DNS name of the the host that they are authenticating to when |
46 // generating the SPN. The default value is false. | 52 // generating the SPN. The default value is false. |
47 bool disable_cname_lookup() const { return disable_cname_lookup_; } | 53 bool disable_cname_lookup() const { return disable_cname_lookup_; } |
(...skipping 11 matching lines...) Expand all Loading... |
59 void set_host_resolver(HostResolver* host_resolver); | 65 void set_host_resolver(HostResolver* host_resolver); |
60 | 66 |
61 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, | 67 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, |
62 HttpAuth::Target target, | 68 HttpAuth::Target target, |
63 const GURL& origin, | 69 const GURL& origin, |
64 CreateReason reason, | 70 CreateReason reason, |
65 int digest_nonce_count, | 71 int digest_nonce_count, |
66 const BoundNetLog& net_log, | 72 const BoundNetLog& net_log, |
67 scoped_ptr<HttpAuthHandler>* handler); | 73 scoped_ptr<HttpAuthHandler>* handler); |
68 | 74 |
69 #if defined(OS_WIN) | 75 // Set the system library to use. Typically the only callers which need to |
70 // Set the SSPILibrary to use. Typically the only callers which need to | |
71 // use this are unit tests which pass in a mocked-out version of the | 76 // use this are unit tests which pass in a mocked-out version of the |
72 // SSPI library. | 77 // system library. |
73 // The caller is responsible for managing the lifetime of |*sspi_library|, | 78 // The caller is responsible for managing the lifetime of |*auth_library|, |
74 // and the lifetime must exceed that of this Factory object and all | 79 // and the lifetime must exceed that of this Factory object and all |
75 // HttpAuthHandler's that this Factory object creates. | 80 // HttpAuthHandler's that this Factory object creates. |
76 void set_sspi_library(SSPILibrary* sspi_library) { | 81 void set_library(AuthLibrary* auth_library) { |
77 sspi_library_ = sspi_library; | 82 auth_library_ = auth_library; |
78 } | 83 } |
79 #endif // defined(OS_WIN) | 84 |
80 private: | 85 private: |
81 bool disable_cname_lookup_; | 86 bool disable_cname_lookup_; |
82 bool use_port_; | 87 bool use_port_; |
83 scoped_refptr<HostResolver> resolver_; | 88 scoped_refptr<HostResolver> resolver_; |
84 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
85 ULONG max_token_length_; | 90 ULONG max_token_length_; |
86 bool first_creation_; | 91 bool first_creation_; |
87 bool is_unsupported_; | 92 bool is_unsupported_; |
88 SSPILibrary* sspi_library_; | |
89 #endif // defined(OS_WIN) | |
90 | |
91 #if defined(OS_POSIX) | |
92 GSSAPILibrary* gssapi_library_; | |
93 #endif | 93 #endif |
| 94 AuthLibrary* auth_library_; |
94 }; | 95 }; |
95 | 96 |
| 97 HttpAuthHandlerNegotiate(AuthLibrary* sspi_library, |
96 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
97 HttpAuthHandlerNegotiate(SSPILibrary* sspi_library, ULONG max_token_length, | 99 ULONG max_token_length, |
| 100 #endif |
98 URLSecurityManager* url_security_manager, | 101 URLSecurityManager* url_security_manager, |
99 HostResolver* host_resolver, | 102 HostResolver* host_resolver, |
100 bool disable_cname_lookup, bool use_port); | 103 bool disable_cname_lookup, |
101 #endif | 104 bool use_port); |
102 | |
103 #if defined(OS_POSIX) | |
104 HttpAuthHandlerNegotiate(GSSAPILibrary* gssapi_library, | |
105 URLSecurityManager* url_security_manager, | |
106 HostResolver* host_resolver, | |
107 bool disable_cname_lookup, bool use_port); | |
108 #endif | |
109 | 105 |
110 virtual ~HttpAuthHandlerNegotiate(); | 106 virtual ~HttpAuthHandlerNegotiate(); |
111 | 107 |
112 virtual bool NeedsIdentity(); | 108 virtual bool NeedsIdentity(); |
113 | 109 |
114 virtual bool IsFinalRound(); | 110 virtual bool IsFinalRound(); |
115 | 111 |
116 virtual bool AllowsDefaultCredentials(); | 112 virtual bool AllowsDefaultCredentials(); |
117 | 113 |
118 // These are public for unit tests | 114 // These are public for unit tests |
(...skipping 20 matching lines...) Expand all Loading... |
139 | 135 |
140 void OnIOComplete(int result); | 136 void OnIOComplete(int result); |
141 void DoCallback(int result); | 137 void DoCallback(int result); |
142 int DoLoop(int result); | 138 int DoLoop(int result); |
143 | 139 |
144 int DoResolveCanonicalName(); | 140 int DoResolveCanonicalName(); |
145 int DoResolveCanonicalNameComplete(int rv); | 141 int DoResolveCanonicalNameComplete(int rv); |
146 int DoGenerateAuthToken(); | 142 int DoGenerateAuthToken(); |
147 int DoGenerateAuthTokenComplete(int rv); | 143 int DoGenerateAuthTokenComplete(int rv); |
148 | 144 |
149 #if defined(OS_WIN) | 145 AuthSystem auth_system_; |
150 // Members which are constant for lifetime of the handler. | |
151 HttpAuthSSPI auth_system_; | |
152 #endif | |
153 | |
154 #if defined(OS_POSIX) | |
155 HttpAuthGSSAPI auth_system_; | |
156 #endif | |
157 | |
158 bool disable_cname_lookup_; | 146 bool disable_cname_lookup_; |
159 bool use_port_; | 147 bool use_port_; |
160 CompletionCallbackImpl<HttpAuthHandlerNegotiate> io_callback_; | 148 CompletionCallbackImpl<HttpAuthHandlerNegotiate> io_callback_; |
161 scoped_refptr<HostResolver> resolver_; | 149 scoped_refptr<HostResolver> resolver_; |
162 | 150 |
163 // Members which are needed for DNS lookup + SPN. | 151 // Members which are needed for DNS lookup + SPN. |
164 AddressList address_list_; | 152 AddressList address_list_; |
165 scoped_ptr<SingleRequestHostResolver> single_resolve_; | 153 scoped_ptr<SingleRequestHostResolver> single_resolve_; |
166 | 154 |
167 // Things which should be consistent after first call to GenerateAuthToken. | 155 // Things which should be consistent after first call to GenerateAuthToken. |
168 bool already_called_; | 156 bool already_called_; |
169 bool has_username_and_password_; | 157 bool has_username_and_password_; |
170 std::wstring username_; | 158 std::wstring username_; |
171 std::wstring password_; | 159 std::wstring password_; |
172 std::wstring spn_; | 160 std::wstring spn_; |
173 | 161 |
174 // Things which vary each round. | 162 // Things which vary each round. |
175 CompletionCallback* user_callback_; | 163 CompletionCallback* user_callback_; |
176 std::string* auth_token_; | 164 std::string* auth_token_; |
177 | 165 |
178 State next_state_; | 166 State next_state_; |
179 | 167 |
180 URLSecurityManager* url_security_manager_; | 168 URLSecurityManager* url_security_manager_; |
181 }; | 169 }; |
182 | 170 |
183 } // namespace net | 171 } // namespace net |
184 | 172 |
185 #endif // NET_HTTP_HTTP_AUTH_HANDLER_NEGOTIATE_H_ | 173 #endif // NET_HTTP_HTTP_AUTH_HANDLER_NEGOTIATE_H_ |
OLD | NEW |