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