Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_util.cc

Issue 1399843003: Move prefix_set and parts of s_b_util into a new component safe_browsing_db. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use group instead of a static_library for targets that have no sources. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/safe_browsing/chunk.pb.h" 10 #include "chrome/browser/safe_browsing/chunk.pb.h"
12 #include "components/google/core/browser/google_util.h" 11 #include "components/google/core/browser/google_util.h"
13 #include "crypto/sha2.h" 12 #include "crypto/sha2.h"
14 #include "net/base/escape.h" 13 #include "net/base/escape.h"
15 #include "url/gurl.h" 14 #include "url/gurl.h"
16 #include "url/url_util.h" 15 #include "url/url_util.h"
17 16
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
30 // SBCachedFullHashResult ------------------------------------------------------ 17 // SBCachedFullHashResult ------------------------------------------------------
31 18
32 SBCachedFullHashResult::SBCachedFullHashResult() {} 19 SBCachedFullHashResult::SBCachedFullHashResult() {}
33 20
34 SBCachedFullHashResult::SBCachedFullHashResult( 21 SBCachedFullHashResult::SBCachedFullHashResult(
35 const base::Time& in_expire_after) 22 const base::Time& in_expire_after)
36 : expire_after(in_expire_after) {} 23 : expire_after(in_expire_after) {}
37 24
38 SBCachedFullHashResult::~SBCachedFullHashResult() {} 25 SBCachedFullHashResult::~SBCachedFullHashResult() {}
39 26
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 std::vector<std::string> hosts, paths; 463 std::vector<std::string> hosts, paths;
477 GenerateHostsToCheck(url, &hosts); 464 GenerateHostsToCheck(url, &hosts);
478 GeneratePathsToCheck(url, &paths); 465 GeneratePathsToCheck(url, &paths);
479 for (size_t h = 0; h < hosts.size(); ++h) { 466 for (size_t h = 0; h < hosts.size(); ++h) {
480 for (size_t p = 0; p < paths.size(); ++p) { 467 for (size_t p = 0; p < paths.size(); ++p) {
481 urls->push_back(hosts[h] + paths[p]); 468 urls->push_back(hosts[h] + paths[p]);
482 } 469 }
483 } 470 }
484 } 471 }
485 472
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
508 SBFullHash StringToSBFullHash(const std::string& hash_in) { 473 SBFullHash StringToSBFullHash(const std::string& hash_in) {
509 DCHECK_EQ(crypto::kSHA256Length, hash_in.size()); 474 DCHECK_EQ(crypto::kSHA256Length, hash_in.size());
510 SBFullHash hash_out; 475 SBFullHash hash_out;
511 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); 476 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length);
512 return hash_out; 477 return hash_out;
513 } 478 }
514 479
515 std::string SBFullHashToString(const SBFullHash& hash) { 480 std::string SBFullHashToString(const SBFullHash& hash) {
516 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); 481 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash));
517 return std::string(hash.full_hash, sizeof(hash.full_hash)); 482 return std::string(hash.full_hash, sizeof(hash.full_hash));
518 } 483 }
519 484
520 } // namespace safe_browsing_util 485 } // namespace safe_browsing_util
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.h ('k') | chrome/browser/safe_browsing/safe_browsing_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698