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 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
10 #include "base/string_util.h" | 11 #include "chrome/browser/google/google_util.h" |
11 #include "crypto/hmac.h" | 12 #include "crypto/hmac.h" |
12 #include "crypto/sha2.h" | 13 #include "crypto/sha2.h" |
13 #include "chrome/browser/google/google_util.h" | |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "googleurl/src/url_util.h" | 15 #include "googleurl/src/url_util.h" |
16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
17 #include "unicode/locid.h" | 17 #include "unicode/locid.h" |
18 | 18 |
19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
20 #include "chrome/installer/util/browser_distribution.h" | 20 #include "chrome/installer/util/browser_distribution.h" |
21 #endif | 21 #endif |
22 | 22 |
23 static const int kSafeBrowsingMacDigestSize = 20; | 23 static const int kSafeBrowsingMacDigestSize = 20; |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 return !memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize); | 504 return !memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize); |
505 } | 505 } |
506 | 506 |
507 GURL GeneratePhishingReportUrl(const std::string& report_page, | 507 GURL GeneratePhishingReportUrl(const std::string& report_page, |
508 const std::string& url_to_report, | 508 const std::string& url_to_report, |
509 bool is_client_side_detection) { | 509 bool is_client_side_detection) { |
510 icu::Locale locale = icu::Locale::getDefault(); | 510 icu::Locale locale = icu::Locale::getDefault(); |
511 const char* lang = locale.getLanguage(); | 511 const char* lang = locale.getLanguage(); |
512 if (!lang) | 512 if (!lang) |
513 lang = "en"; // fallback | 513 lang = "en"; // fallback |
514 const std::string continue_esc = | 514 const std::string continue_esc = net::EscapeQueryParamValue( |
515 EscapeQueryParamValue(base::StringPrintf(kContinueUrlFormat, lang), true); | 515 base::StringPrintf(kContinueUrlFormat, lang), true); |
516 const std::string current_esc = EscapeQueryParamValue(url_to_report, true); | 516 const std::string current_esc = net::EscapeQueryParamValue(url_to_report, |
| 517 true); |
517 | 518 |
518 #if defined(OS_WIN) | 519 #if defined(OS_WIN) |
519 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 520 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
520 std::string client_name(dist->GetSafeBrowsingName()); | 521 std::string client_name(dist->GetSafeBrowsingName()); |
521 #else | 522 #else |
522 std::string client_name("googlechrome"); | 523 std::string client_name("googlechrome"); |
523 #endif | 524 #endif |
524 if (is_client_side_detection) | 525 if (is_client_side_detection) |
525 client_name.append("_csd"); | 526 client_name.append("_csd"); |
526 | 527 |
527 GURL report_url(report_page + base::StringPrintf(kReportParams, | 528 GURL report_url(report_page + base::StringPrintf(kReportParams, |
528 client_name.c_str(), | 529 client_name.c_str(), |
529 continue_esc.c_str(), | 530 continue_esc.c_str(), |
530 current_esc.c_str())); | 531 current_esc.c_str())); |
531 return google_util::AppendGoogleLocaleParam(report_url); | 532 return google_util::AppendGoogleLocaleParam(report_url); |
532 } | 533 } |
533 | 534 |
534 void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) { | 535 void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) { |
535 DCHECK_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), hash_in.size()); | 536 DCHECK_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), hash_in.size()); |
536 memcpy(hash_out->full_hash, hash_in.data(), crypto::SHA256_LENGTH); | 537 memcpy(hash_out->full_hash, hash_in.data(), crypto::SHA256_LENGTH); |
537 } | 538 } |
538 | 539 |
539 std::string SBFullHashToString(const SBFullHash& hash) { | 540 std::string SBFullHashToString(const SBFullHash& hash) { |
540 DCHECK_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), sizeof(hash.full_hash)); | 541 DCHECK_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), sizeof(hash.full_hash)); |
541 return std::string(hash.full_hash, sizeof(hash.full_hash)); | 542 return std::string(hash.full_hash, sizeof(hash.full_hash)); |
542 } | 543 } |
543 } // namespace safe_browsing_util | 544 } // namespace safe_browsing_util |
OLD | NEW |