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 // 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 "net/http/http_auth.h" | 21 #include "net/http/http_auth.h" |
21 | 22 |
22 namespace net { | 23 namespace net { |
23 | 24 |
24 struct HttpRequestInfo; | 25 struct HttpRequestInfo; |
25 class ProxyInfo; | 26 class ProxyInfo; |
26 | 27 |
27 // SSPILibrary is introduced so unit tests can mock the calls to Windows' SSPI | 28 // SSPILibrary is introduced so unit tests can mock the calls to Windows' SSPI |
28 // implementation. The default implementation simply passes the arguments on to | 29 // implementation. The default implementation simply passes the arguments on to |
29 // the SSPI implementation provided by Secur32.dll. | 30 // the SSPI implementation provided by Secur32.dll. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 bool ParseChallenge(HttpAuth::ChallengeTokenizer* tok); | 87 bool ParseChallenge(HttpAuth::ChallengeTokenizer* tok); |
87 | 88 |
88 // Generates an authentication token for the service specified by the | 89 // Generates an authentication token for the service specified by the |
89 // Service Principal Name |spn| and stores the value in |*auth_token|. | 90 // Service Principal Name |spn| and stores the value in |*auth_token|. |
90 // If the return value is not |OK|, then the value of |*auth_token| is | 91 // If the return value is not |OK|, then the value of |*auth_token| is |
91 // unspecified. ERR_IO_PENDING is not a valid return code. | 92 // unspecified. ERR_IO_PENDING is not a valid return code. |
92 // If this is the first round of a multiple round scheme, credentials are | 93 // If this is the first round of a multiple round scheme, credentials are |
93 // obtained using |*username| and |*password|. If |username| and |password| | 94 // obtained using |*username| and |*password|. If |username| and |password| |
94 // are both NULL, the credentials for the currently logged in user are used | 95 // are both NULL, the credentials for the currently logged in user are used |
95 // instead. | 96 // instead. |
96 int GenerateAuthToken(const std::wstring* username, | 97 int GenerateAuthToken(const string16* username, |
97 const std::wstring* password, | 98 const string16* password, |
98 const std::wstring& spn, | 99 const std::wstring& spn, |
99 std::string* auth_token); | 100 std::string* auth_token); |
100 | 101 |
101 private: | 102 private: |
102 int OnFirstRound(const std::wstring* username, | 103 int OnFirstRound(const string16* username, |
103 const std::wstring* password); | 104 const string16* password); |
104 | 105 |
105 int GetNextSecurityToken( | 106 int GetNextSecurityToken( |
106 const std::wstring& spn, | 107 const std::wstring& spn, |
107 const void* in_token, | 108 const void* in_token, |
108 int in_token_len, | 109 int in_token_len, |
109 void** out_token, | 110 void** out_token, |
110 int* out_token_len); | 111 int* out_token_len); |
111 | 112 |
112 void ResetSecurityContext(); | 113 void ResetSecurityContext(); |
113 | 114 |
114 SSPILibrary* library_; | 115 SSPILibrary* library_; |
115 std::string scheme_; | 116 std::string scheme_; |
116 SEC_WCHAR* security_package_; | 117 SEC_WCHAR* security_package_; |
117 std::string decoded_server_auth_token_; | 118 std::string decoded_server_auth_token_; |
118 ULONG max_token_length_; | 119 ULONG max_token_length_; |
119 CredHandle cred_; | 120 CredHandle cred_; |
120 CtxtHandle ctxt_; | 121 CtxtHandle ctxt_; |
121 }; | 122 }; |
122 | 123 |
123 // Splits |combined| into domain and username. | 124 // Splits |combined| into domain and username. |
124 // If |combined| is of form "FOO\bar", |domain| will contain "FOO" and |user| | 125 // If |combined| is of form "FOO\bar", |domain| will contain "FOO" and |user| |
125 // will contain "bar". | 126 // will contain "bar". |
126 // If |combined| is of form "bar", |domain| will be empty and |user| will | 127 // If |combined| is of form "bar", |domain| will be empty and |user| will |
127 // contain "bar". | 128 // contain "bar". |
128 // |domain| and |user| must be non-NULL. | 129 // |domain| and |user| must be non-NULL. |
129 void SplitDomainAndUser(const std::wstring& combined, | 130 void SplitDomainAndUser(const string16& combined, |
130 std::wstring* domain, | 131 string16* domain, |
131 std::wstring* user); | 132 string16* user); |
132 | 133 |
133 // Determines the maximum token length in bytes for a particular SSPI package. | 134 // Determines the maximum token length in bytes for a particular SSPI package. |
134 // | 135 // |
135 // |library| and |max_token_length| must be non-NULL pointers to valid objects. | 136 // |library| and |max_token_length| must be non-NULL pointers to valid objects. |
136 // | 137 // |
137 // If the return value is OK, |*max_token_length| contains the maximum token | 138 // If the return value is OK, |*max_token_length| contains the maximum token |
138 // length in bytes. | 139 // length in bytes. |
139 // | 140 // |
140 // If the return value is ERR_UNSUPPORTED_AUTH_SCHEME, |package| is not an | 141 // If the return value is ERR_UNSUPPORTED_AUTH_SCHEME, |package| is not an |
141 // known SSPI authentication scheme on this system. |*max_token_length| is not | 142 // known SSPI authentication scheme on this system. |*max_token_length| is not |
142 // changed. | 143 // changed. |
143 // | 144 // |
144 // If the return value is ERR_UNEXPECTED, there was an unanticipated problem | 145 // If the return value is ERR_UNEXPECTED, there was an unanticipated problem |
145 // in the underlying SSPI call. The details are logged, and |*max_token_length| | 146 // in the underlying SSPI call. The details are logged, and |*max_token_length| |
146 // is not changed. | 147 // is not changed. |
147 int DetermineMaxTokenLength(SSPILibrary* library, | 148 int DetermineMaxTokenLength(SSPILibrary* library, |
148 const std::wstring& package, | 149 const std::wstring& package, |
149 ULONG* max_token_length); | 150 ULONG* max_token_length); |
150 | 151 |
151 } // namespace net | 152 } // namespace net |
152 | 153 |
153 #endif // NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ | 154 #endif // NET_HTTP_HTTP_AUTH_SSPI_WIN_H_ |
OLD | NEW |