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 // See "SSPI Sample Application" at | 5 // See "SSPI Sample Application" at |
6 // http://msdn.microsoft.com/en-us/library/aa918273.aspx | 6 // http://msdn.microsoft.com/en-us/library/aa918273.aspx |
7 | 7 |
8 #include "net/http/http_auth_sspi_win.h" | 8 #include "net/http/http_auth_sspi_win.h" |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 247 } |
248 | 248 |
249 std::string decoded_auth_token; | 249 std::string decoded_auth_token; |
250 bool base64_rv = base::Base64Decode(encoded_auth_token, &decoded_auth_token); | 250 bool base64_rv = base::Base64Decode(encoded_auth_token, &decoded_auth_token); |
251 if (!base64_rv) | 251 if (!base64_rv) |
252 return HttpAuth::AUTHORIZATION_RESULT_INVALID; | 252 return HttpAuth::AUTHORIZATION_RESULT_INVALID; |
253 decoded_server_auth_token_ = decoded_auth_token; | 253 decoded_server_auth_token_ = decoded_auth_token; |
254 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; | 254 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; |
255 } | 255 } |
256 | 256 |
257 int HttpAuthSSPI::GenerateAuthToken(const string16* username, | 257 int HttpAuthSSPI::GenerateAuthToken(const AuthCredentials* credentials, |
258 const string16* password, | |
259 const std::wstring& spn, | 258 const std::wstring& spn, |
260 std::string* auth_token) { | 259 std::string* auth_token) { |
261 DCHECK((username == NULL) == (password == NULL)); | |
262 | |
263 // Initial challenge. | 260 // Initial challenge. |
264 if (!SecIsValidHandle(&cred_)) { | 261 if (!SecIsValidHandle(&cred_)) { |
265 int rv = OnFirstRound(username, password); | 262 int rv = OnFirstRound(credentials); |
266 if (rv != OK) | 263 if (rv != OK) |
267 return rv; | 264 return rv; |
268 } | 265 } |
269 | 266 |
270 DCHECK(SecIsValidHandle(&cred_)); | 267 DCHECK(SecIsValidHandle(&cred_)); |
271 void* out_buf; | 268 void* out_buf; |
272 int out_buf_len; | 269 int out_buf_len; |
273 int rv = GetNextSecurityToken( | 270 int rv = GetNextSecurityToken( |
274 spn, | 271 spn, |
275 static_cast<void *>(const_cast<char *>( | 272 static_cast<void *>(const_cast<char *>( |
(...skipping 11 matching lines...) Expand all Loading... |
287 // OK, we are done with |out_buf| | 284 // OK, we are done with |out_buf| |
288 free(out_buf); | 285 free(out_buf); |
289 if (!base64_rv) { | 286 if (!base64_rv) { |
290 LOG(ERROR) << "Base64 encoding of auth token failed."; | 287 LOG(ERROR) << "Base64 encoding of auth token failed."; |
291 return ERR_ENCODING_CONVERSION_FAILED; | 288 return ERR_ENCODING_CONVERSION_FAILED; |
292 } | 289 } |
293 *auth_token = scheme_ + " " + encode_output; | 290 *auth_token = scheme_ + " " + encode_output; |
294 return OK; | 291 return OK; |
295 } | 292 } |
296 | 293 |
297 int HttpAuthSSPI::OnFirstRound(const string16* username, | 294 int HttpAuthSSPI::OnFirstRound(const AuthCredentials* credentials) { |
298 const string16* password) { | |
299 DCHECK((username == NULL) == (password == NULL)); | |
300 DCHECK(!SecIsValidHandle(&cred_)); | 295 DCHECK(!SecIsValidHandle(&cred_)); |
301 int rv = OK; | 296 int rv = OK; |
302 if (username) { | 297 if (credentials) { |
303 string16 domain; | 298 string16 domain; |
304 string16 user; | 299 string16 user; |
305 SplitDomainAndUser(*username, &domain, &user); | 300 SplitDomainAndUser(credentials->username(), &domain, &user); |
306 rv = AcquireExplicitCredentials(library_, security_package_, domain, | 301 rv = AcquireExplicitCredentials(library_, security_package_, domain, |
307 user, *password, &cred_); | 302 user, credentials->password(), &cred_); |
308 if (rv != OK) | 303 if (rv != OK) |
309 return rv; | 304 return rv; |
310 } else { | 305 } else { |
311 rv = AcquireDefaultCredentials(library_, security_package_, &cred_); | 306 rv = AcquireDefaultCredentials(library_, security_package_, &cred_); |
312 if (rv != OK) | 307 if (rv != OK) |
313 return rv; | 308 return rv; |
314 } | 309 } |
315 | 310 |
316 return rv; | 311 return rv; |
317 } | 312 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 int token_length = pkg_info->cbMaxToken; | 420 int token_length = pkg_info->cbMaxToken; |
426 status = library->FreeContextBuffer(pkg_info); | 421 status = library->FreeContextBuffer(pkg_info); |
427 rv = MapFreeContextBufferStatusToError(status); | 422 rv = MapFreeContextBufferStatusToError(status); |
428 if (rv != OK) | 423 if (rv != OK) |
429 return rv; | 424 return rv; |
430 *max_token_length = token_length; | 425 *max_token_length = token_length; |
431 return OK; | 426 return OK; |
432 } | 427 } |
433 | 428 |
434 } // namespace net | 429 } // namespace net |
OLD | NEW |