OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <time.h> | 11 #include <time.h> |
12 | 12 |
13 #if defined(WEBRTC_WIN) | 13 #if defined(WEBRTC_WIN) |
14 #define WIN32_LEAN_AND_MEAN | 14 #define WIN32_LEAN_AND_MEAN |
15 #include <windows.h> | 15 #include <windows.h> |
16 #include <winsock2.h> | 16 #include <winsock2.h> |
17 #include <ws2tcpip.h> | 17 #include <ws2tcpip.h> |
18 #define SECURITY_WIN32 | 18 #define SECURITY_WIN32 |
19 #include <security.h> | 19 #include <security.h> |
20 #endif | 20 #endif |
21 | 21 |
22 #include <algorithm> | 22 #include <algorithm> |
23 | 23 |
24 #include "webrtc/base/arraysize.h" | 24 #include "webrtc/base/arraysize.h" |
25 #include "webrtc/base/base64.h" | 25 #include "webrtc/base/base64.h" |
| 26 #include "webrtc/base/checks.h" |
26 #include "webrtc/base/common.h" | 27 #include "webrtc/base/common.h" |
27 #include "webrtc/base/cryptstring.h" | 28 #include "webrtc/base/cryptstring.h" |
28 #include "webrtc/base/httpcommon-inl.h" | 29 #include "webrtc/base/httpcommon-inl.h" |
29 #include "webrtc/base/httpcommon.h" | 30 #include "webrtc/base/httpcommon.h" |
30 #include "webrtc/base/messagedigest.h" | 31 #include "webrtc/base/messagedigest.h" |
31 #include "webrtc/base/socketaddress.h" | 32 #include "webrtc/base/socketaddress.h" |
32 #include "webrtc/base/stringencode.h" | 33 #include "webrtc/base/stringencode.h" |
33 #include "webrtc/base/stringutils.h" | 34 #include "webrtc/base/stringutils.h" |
34 | 35 |
35 namespace rtc { | 36 namespace rtc { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT", | 335 "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT", |
335 "A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", | 336 "A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", |
336 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" | 337 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" |
337 }; | 338 }; |
338 const int kTimeZoneOffsets[] = { | 339 const int kTimeZoneOffsets[] = { |
339 0, 0, -5, -4, -6, -5, -7, -6, -8, -7, | 340 0, 0, -5, -4, -6, -5, -7, -6, -8, -7, |
340 -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, | 341 -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, |
341 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 | 342 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 |
342 }; | 343 }; |
343 | 344 |
344 ASSERT(NULL != seconds); | 345 RTC_DCHECK(NULL != seconds); |
345 struct tm tval; | 346 struct tm tval; |
346 memset(&tval, 0, sizeof(tval)); | 347 memset(&tval, 0, sizeof(tval)); |
347 char month[4], zone[6]; | 348 char month[4], zone[6]; |
348 memset(month, 0, sizeof(month)); | 349 memset(month, 0, sizeof(month)); |
349 memset(zone, 0, sizeof(zone)); | 350 memset(zone, 0, sizeof(zone)); |
350 | 351 |
351 if (7 != sscanf(date.c_str(), "%*3s, %d %3s %d %d:%d:%d %5c", | 352 if (7 != sscanf(date.c_str(), "%*3s, %d %3s %d %d:%d:%d %5c", |
352 &tval.tm_mday, month, &tval.tm_year, | 353 &tval.tm_mday, month, &tval.tm_year, |
353 &tval.tm_hour, &tval.tm_min, &tval.tm_sec, zone)) { | 354 &tval.tm_hour, &tval.tm_min, &tval.tm_sec, zone)) { |
354 return false; | 355 return false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 475 } |
475 | 476 |
476 void HttpData::setContent(const std::string& content_type, | 477 void HttpData::setContent(const std::string& content_type, |
477 StreamInterface* document) { | 478 StreamInterface* document) { |
478 setHeader(HH_CONTENT_TYPE, content_type); | 479 setHeader(HH_CONTENT_TYPE, content_type); |
479 setDocumentAndLength(document); | 480 setDocumentAndLength(document); |
480 } | 481 } |
481 | 482 |
482 void HttpData::setDocumentAndLength(StreamInterface* document) { | 483 void HttpData::setDocumentAndLength(StreamInterface* document) { |
483 // TODO: Consider calling Rewind() here? | 484 // TODO: Consider calling Rewind() here? |
484 ASSERT(!hasHeader(HH_CONTENT_LENGTH, NULL)); | 485 RTC_DCHECK(!hasHeader(HH_CONTENT_LENGTH, NULL)); |
485 ASSERT(!hasHeader(HH_TRANSFER_ENCODING, NULL)); | 486 RTC_DCHECK(!hasHeader(HH_TRANSFER_ENCODING, NULL)); |
486 ASSERT(document != NULL); | 487 RTC_DCHECK(document != NULL); |
487 this->document.reset(document); | 488 this->document.reset(document); |
488 size_t content_length = 0; | 489 size_t content_length = 0; |
489 if (this->document->GetAvailable(&content_length)) { | 490 if (this->document->GetAvailable(&content_length)) { |
490 char buffer[32]; | 491 char buffer[32]; |
491 sprintfn(buffer, sizeof(buffer), "%d", content_length); | 492 sprintfn(buffer, sizeof(buffer), "%d", content_length); |
492 setHeader(HH_CONTENT_LENGTH, buffer); | 493 setHeader(HH_CONTENT_LENGTH, buffer); |
493 } else { | 494 } else { |
494 setHeader(HH_TRANSFER_ENCODING, "chunked"); | 495 setHeader(HH_TRANSFER_ENCODING, "chunked"); |
495 } | 496 } |
496 } | 497 } |
(...skipping 11 matching lines...) Expand all Loading... |
508 | 509 |
509 void | 510 void |
510 HttpRequestData::copy(const HttpRequestData& src) { | 511 HttpRequestData::copy(const HttpRequestData& src) { |
511 verb = src.verb; | 512 verb = src.verb; |
512 path = src.path; | 513 path = src.path; |
513 HttpData::copy(src); | 514 HttpData::copy(src); |
514 } | 515 } |
515 | 516 |
516 size_t | 517 size_t |
517 HttpRequestData::formatLeader(char* buffer, size_t size) const { | 518 HttpRequestData::formatLeader(char* buffer, size_t size) const { |
518 ASSERT(path.find(' ') == std::string::npos); | 519 RTC_DCHECK(path.find(' ') == std::string::npos); |
519 return sprintfn(buffer, size, "%s %.*s HTTP/%s", ToString(verb), path.size(), | 520 return sprintfn(buffer, size, "%s %.*s HTTP/%s", ToString(verb), path.size(), |
520 path.data(), ToString(version)); | 521 path.data(), ToString(version)); |
521 } | 522 } |
522 | 523 |
523 HttpError | 524 HttpError |
524 HttpRequestData::parseLeader(const char* line, size_t len) { | 525 HttpRequestData::parseLeader(const char* line, size_t len) { |
525 unsigned int vmajor, vminor; | 526 unsigned int vmajor, vminor; |
526 int vend, dstart, dend; | 527 int vend, dstart, dend; |
527 // sscanf isn't safe with strings that aren't null-terminated, and there is | 528 // sscanf isn't safe with strings that aren't null-terminated, and there is |
528 // no guarantee that |line| is. Create a local copy that is null-terminated. | 529 // no guarantee that |line| is. Create a local copy that is null-terminated. |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 } else { | 832 } else { |
832 middle = nonce; | 833 middle = nonce; |
833 } | 834 } |
834 std::string HA1 = MD5(sensitive); | 835 std::string HA1 = MD5(sensitive); |
835 memset(sensitive, 0, len); | 836 memset(sensitive, 0, len); |
836 delete [] sensitive; | 837 delete [] sensitive; |
837 std::string HA2 = MD5(A2); | 838 std::string HA2 = MD5(A2); |
838 std::string dig_response = MD5(HA1 + ":" + middle + ":" + HA2); | 839 std::string dig_response = MD5(HA1 + ":" + middle + ":" + HA2); |
839 | 840 |
840 #if TEST_DIGEST | 841 #if TEST_DIGEST |
841 ASSERT(strcmp(dig_response.c_str(), DIGEST_RESPONSE) == 0); | 842 RTC_DCHECK(strcmp(dig_response.c_str(), DIGEST_RESPONSE) == 0); |
842 #endif | 843 #endif |
843 | 844 |
844 std::stringstream ss; | 845 std::stringstream ss; |
845 ss << auth_method; | 846 ss << auth_method; |
846 ss << " username=" << quote(username); | 847 ss << " username=" << quote(username); |
847 ss << ", realm=" << quote(realm); | 848 ss << ", realm=" << quote(realm); |
848 ss << ", nonce=" << quote(nonce); | 849 ss << ", nonce=" << quote(nonce); |
849 ss << ", uri=" << quote(uri); | 850 ss << ", uri=" << quote(uri); |
850 if (has_qop) { | 851 if (has_qop) { |
851 ss << ", qop=" << qop; | 852 ss << ", qop=" << qop; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 CtxtHandle ctx; | 1014 CtxtHandle ctx; |
1014 ret = InitializeSecurityContextA(&cred, 0, spn, flags, 0, SECURITY_NATIVE_
DREP, 0, 0, &ctx, &out_buf_desc, &ret_flags, &lifetime); | 1015 ret = InitializeSecurityContextA(&cred, 0, spn, flags, 0, SECURITY_NATIVE_
DREP, 0, 0, &ctx, &out_buf_desc, &ret_flags, &lifetime); |
1015 //LOG(INFO) << "$$$ InitializeSecurityContext @ " << TimeSince(now); | 1016 //LOG(INFO) << "$$$ InitializeSecurityContext @ " << TimeSince(now); |
1016 if (FAILED(ret)) { | 1017 if (FAILED(ret)) { |
1017 LOG(LS_ERROR) << "InitializeSecurityContext returned: " | 1018 LOG(LS_ERROR) << "InitializeSecurityContext returned: " |
1018 << ErrorName(ret, SECURITY_ERRORS); | 1019 << ErrorName(ret, SECURITY_ERRORS); |
1019 FreeCredentialsHandle(&cred); | 1020 FreeCredentialsHandle(&cred); |
1020 return HAR_IGNORE; | 1021 return HAR_IGNORE; |
1021 } | 1022 } |
1022 | 1023 |
1023 ASSERT(!context); | 1024 RTC_DCHECK(!context); |
1024 context = neg = new NegotiateAuthContext(auth_method, cred, ctx); | 1025 context = neg = new NegotiateAuthContext(auth_method, cred, ctx); |
1025 neg->specified_credentials = specify_credentials; | 1026 neg->specified_credentials = specify_credentials; |
1026 neg->steps = steps; | 1027 neg->steps = steps; |
1027 } | 1028 } |
1028 | 1029 |
1029 if ((ret == SEC_I_COMPLETE_NEEDED) || (ret == SEC_I_COMPLETE_AND_CONTINUE))
{ | 1030 if ((ret == SEC_I_COMPLETE_NEEDED) || (ret == SEC_I_COMPLETE_AND_CONTINUE))
{ |
1030 ret = CompleteAuthToken(&neg->ctx, &out_buf_desc); | 1031 ret = CompleteAuthToken(&neg->ctx, &out_buf_desc); |
1031 //LOG(INFO) << "$$$ CompleteAuthToken @ " << TimeSince(now); | 1032 //LOG(INFO) << "$$$ CompleteAuthToken @ " << TimeSince(now); |
1032 LOG(LS_VERBOSE) << "CompleteAuthToken returned: " | 1033 LOG(LS_VERBOSE) << "CompleteAuthToken returned: " |
1033 << ErrorName(ret, SECURITY_ERRORS); | 1034 << ErrorName(ret, SECURITY_ERRORS); |
(...skipping 12 matching lines...) Expand all Loading... |
1046 } | 1047 } |
1047 #endif | 1048 #endif |
1048 #endif // WEBRTC_WIN | 1049 #endif // WEBRTC_WIN |
1049 | 1050 |
1050 return HAR_IGNORE; | 1051 return HAR_IGNORE; |
1051 } | 1052 } |
1052 | 1053 |
1053 ////////////////////////////////////////////////////////////////////// | 1054 ////////////////////////////////////////////////////////////////////// |
1054 | 1055 |
1055 } // namespace rtc | 1056 } // namespace rtc |
OLD | NEW |