OLD | NEW |
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 // This file contains common routines used by NTLM and Negotiate authentication | 5 // This file contains common routines used by NTLM and Negotiate authentication |
6 // using the SSPI API on Windows. | 6 // using the SSPI API on Windows. |
7 | 7 |
8 #ifndef NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ | 8 #ifndef NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ |
9 #define NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ | 9 #define NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 // security.h needs to be included for CredHandle. Unfortunately CredHandle | 12 // security.h needs to be included for CredHandle. Unfortunately CredHandle |
13 // is a typedef and can't be forward declared. | 13 // is a typedef and can't be forward declared. |
14 #define SECURITY_WIN32 1 | 14 #define SECURITY_WIN32 1 |
15 #include <windows.h> | 15 #include <windows.h> |
16 #include <security.h> | 16 #include <security.h> |
17 | 17 |
18 #include <string> | 18 #include <string> |
19 | 19 |
20 #include "base/string16.h" | 20 #include "base/string16.h" |
21 #include "net/base/net_api.h" | 21 #include "net/base/net_export.h" |
22 #include "net/http/http_auth.h" | 22 #include "net/http/http_auth.h" |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 // SSPILibrary is introduced so unit tests can mock the calls to Windows' SSPI | 26 // SSPILibrary is introduced so unit tests can mock the calls to Windows' SSPI |
27 // implementation. The default implementation simply passes the arguments on to | 27 // implementation. The default implementation simply passes the arguments on to |
28 // the SSPI implementation provided by Secur32.dll. | 28 // the SSPI implementation provided by Secur32.dll. |
29 // NOTE(cbentzel): I considered replacing the Secur32.dll with a mock DLL, but | 29 // NOTE(cbentzel): I considered replacing the Secur32.dll with a mock DLL, but |
30 // decided that it wasn't worth the effort as this is unlikely to be performance | 30 // decided that it wasn't worth the effort as this is unlikely to be performance |
31 // sensitive code. | 31 // sensitive code. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 virtual SECURITY_STATUS DeleteSecurityContext(PCtxtHandle phContext) { | 116 virtual SECURITY_STATUS DeleteSecurityContext(PCtxtHandle phContext) { |
117 return ::DeleteSecurityContext(phContext); | 117 return ::DeleteSecurityContext(phContext); |
118 } | 118 } |
119 | 119 |
120 virtual SECURITY_STATUS FreeContextBuffer(PVOID pvContextBuffer) { | 120 virtual SECURITY_STATUS FreeContextBuffer(PVOID pvContextBuffer) { |
121 return ::FreeContextBuffer(pvContextBuffer); | 121 return ::FreeContextBuffer(pvContextBuffer); |
122 } | 122 } |
123 }; | 123 }; |
124 | 124 |
125 class NET_TEST HttpAuthSSPI { | 125 class NET_EXPORT_PRIVATE HttpAuthSSPI { |
126 public: | 126 public: |
127 HttpAuthSSPI(SSPILibrary* sspi_library, | 127 HttpAuthSSPI(SSPILibrary* sspi_library, |
128 const std::string& scheme, | 128 const std::string& scheme, |
129 SEC_WCHAR* security_package, | 129 SEC_WCHAR* security_package, |
130 ULONG max_token_length); | 130 ULONG max_token_length); |
131 ~HttpAuthSSPI(); | 131 ~HttpAuthSSPI(); |
132 | 132 |
133 bool NeedsIdentity() const; | 133 bool NeedsIdentity() const; |
134 | 134 |
135 HttpAuth::AuthorizationResult ParseChallenge( | 135 HttpAuth::AuthorizationResult ParseChallenge( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 CtxtHandle ctxt_; | 174 CtxtHandle ctxt_; |
175 bool can_delegate_; | 175 bool can_delegate_; |
176 }; | 176 }; |
177 | 177 |
178 // Splits |combined| into domain and username. | 178 // Splits |combined| into domain and username. |
179 // If |combined| is of form "FOO\bar", |domain| will contain "FOO" and |user| | 179 // If |combined| is of form "FOO\bar", |domain| will contain "FOO" and |user| |
180 // will contain "bar". | 180 // will contain "bar". |
181 // If |combined| is of form "bar", |domain| will be empty and |user| will | 181 // If |combined| is of form "bar", |domain| will be empty and |user| will |
182 // contain "bar". | 182 // contain "bar". |
183 // |domain| and |user| must be non-NULL. | 183 // |domain| and |user| must be non-NULL. |
184 NET_TEST void SplitDomainAndUser(const string16& combined, | 184 NET_EXPORT_PRIVATE void SplitDomainAndUser(const string16& combined, |
185 string16* domain, | 185 string16* domain, |
186 string16* user); | 186 string16* user); |
187 | 187 |
188 // Determines the maximum token length in bytes for a particular SSPI package. | 188 // Determines the maximum token length in bytes for a particular SSPI package. |
189 // | 189 // |
190 // |library| and |max_token_length| must be non-NULL pointers to valid objects. | 190 // |library| and |max_token_length| must be non-NULL pointers to valid objects. |
191 // | 191 // |
192 // If the return value is OK, |*max_token_length| contains the maximum token | 192 // If the return value is OK, |*max_token_length| contains the maximum token |
193 // length in bytes. | 193 // length in bytes. |
194 // | 194 // |
195 // If the return value is ERR_UNSUPPORTED_AUTH_SCHEME, |package| is not an | 195 // If the return value is ERR_UNSUPPORTED_AUTH_SCHEME, |package| is not an |
196 // known SSPI authentication scheme on this system. |*max_token_length| is not | 196 // known SSPI authentication scheme on this system. |*max_token_length| is not |
197 // changed. | 197 // changed. |
198 // | 198 // |
199 // If the return value is ERR_UNEXPECTED, there was an unanticipated problem | 199 // If the return value is ERR_UNEXPECTED, there was an unanticipated problem |
200 // in the underlying SSPI call. The details are logged, and |*max_token_length| | 200 // in the underlying SSPI call. The details are logged, and |*max_token_length| |
201 // is not changed. | 201 // is not changed. |
202 NET_TEST int DetermineMaxTokenLength(SSPILibrary* library, | 202 NET_EXPORT_PRIVATE int DetermineMaxTokenLength(SSPILibrary* library, |
203 const std::wstring& package, | 203 const std::wstring& package, |
204 ULONG* max_token_length); | 204 ULONG* max_token_length); |
205 | 205 |
206 } // namespace net | 206 } // namespace net |
207 | 207 |
208 #endif // NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ | 208 #endif // NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ |
OLD | NEW |