OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/safe_browsing/chunk.pb.h" | 11 #include "chrome/browser/safe_browsing/chunk.pb.h" |
11 #include "components/google/core/browser/google_util.h" | 12 #include "components/google/core/browser/google_util.h" |
12 #include "crypto/sha2.h" | 13 #include "crypto/sha2.h" |
13 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 #include "url/url_util.h" | 16 #include "url/url_util.h" |
16 | 17 |
| 18 #if defined(OS_WIN) |
| 19 #include "chrome/installer/util/browser_distribution.h" |
| 20 #endif |
| 21 |
| 22 static const char kReportParams[] = "?tpl=%s&url=%s"; |
| 23 |
| 24 SBFullHash SBFullHashForString(const base::StringPiece& str) { |
| 25 SBFullHash h; |
| 26 crypto::SHA256HashString(str, &h.full_hash, sizeof(h.full_hash)); |
| 27 return h; |
| 28 } |
| 29 |
17 // SBCachedFullHashResult ------------------------------------------------------ | 30 // SBCachedFullHashResult ------------------------------------------------------ |
18 | 31 |
19 SBCachedFullHashResult::SBCachedFullHashResult() {} | 32 SBCachedFullHashResult::SBCachedFullHashResult() {} |
20 | 33 |
21 SBCachedFullHashResult::SBCachedFullHashResult( | 34 SBCachedFullHashResult::SBCachedFullHashResult( |
22 const base::Time& in_expire_after) | 35 const base::Time& in_expire_after) |
23 : expire_after(in_expire_after) {} | 36 : expire_after(in_expire_after) {} |
24 | 37 |
25 SBCachedFullHashResult::~SBCachedFullHashResult() {} | 38 SBCachedFullHashResult::~SBCachedFullHashResult() {} |
26 | 39 |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 std::vector<std::string> hosts, paths; | 476 std::vector<std::string> hosts, paths; |
464 GenerateHostsToCheck(url, &hosts); | 477 GenerateHostsToCheck(url, &hosts); |
465 GeneratePathsToCheck(url, &paths); | 478 GeneratePathsToCheck(url, &paths); |
466 for (size_t h = 0; h < hosts.size(); ++h) { | 479 for (size_t h = 0; h < hosts.size(); ++h) { |
467 for (size_t p = 0; p < paths.size(); ++p) { | 480 for (size_t p = 0; p < paths.size(); ++p) { |
468 urls->push_back(hosts[h] + paths[p]); | 481 urls->push_back(hosts[h] + paths[p]); |
469 } | 482 } |
470 } | 483 } |
471 } | 484 } |
472 | 485 |
| 486 GURL GeneratePhishingReportUrl(const std::string& report_page, |
| 487 const std::string& url_to_report, |
| 488 bool is_client_side_detection) { |
| 489 const std::string current_esc = net::EscapeQueryParamValue(url_to_report, |
| 490 true); |
| 491 |
| 492 #if defined(OS_WIN) |
| 493 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 494 std::string client_name(dist->GetSafeBrowsingName()); |
| 495 #else |
| 496 std::string client_name("googlechrome"); |
| 497 #endif |
| 498 if (is_client_side_detection) |
| 499 client_name.append("_csd"); |
| 500 |
| 501 GURL report_url(report_page + base::StringPrintf(kReportParams, |
| 502 client_name.c_str(), |
| 503 current_esc.c_str())); |
| 504 return google_util::AppendGoogleLocaleParam( |
| 505 report_url, g_browser_process->GetApplicationLocale()); |
| 506 } |
| 507 |
473 SBFullHash StringToSBFullHash(const std::string& hash_in) { | 508 SBFullHash StringToSBFullHash(const std::string& hash_in) { |
474 DCHECK_EQ(crypto::kSHA256Length, hash_in.size()); | 509 DCHECK_EQ(crypto::kSHA256Length, hash_in.size()); |
475 SBFullHash hash_out; | 510 SBFullHash hash_out; |
476 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); | 511 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); |
477 return hash_out; | 512 return hash_out; |
478 } | 513 } |
479 | 514 |
480 std::string SBFullHashToString(const SBFullHash& hash) { | 515 std::string SBFullHashToString(const SBFullHash& hash) { |
481 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); | 516 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); |
482 return std::string(hash.full_hash, sizeof(hash.full_hash)); | 517 return std::string(hash.full_hash, sizeof(hash.full_hash)); |
483 } | 518 } |
484 | 519 |
485 } // namespace safe_browsing_util | 520 } // namespace safe_browsing_util |
OLD | NEW |