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

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: 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 std::vector<std::string> hosts, paths; 471 std::vector<std::string> hosts, paths;
485 GenerateHostsToCheck(url, &hosts); 472 GenerateHostsToCheck(url, &hosts);
486 GeneratePathsToCheck(url, &paths); 473 GeneratePathsToCheck(url, &paths);
487 for (size_t h = 0; h < hosts.size(); ++h) { 474 for (size_t h = 0; h < hosts.size(); ++h) {
488 for (size_t p = 0; p < paths.size(); ++p) { 475 for (size_t p = 0; p < paths.size(); ++p) {
489 urls->push_back(hosts[h] + paths[p]); 476 urls->push_back(hosts[h] + paths[p]);
490 } 477 }
491 } 478 }
492 } 479 }
493 480
494 GURL GeneratePhishingReportUrl(const std::string& report_page,
Nathan Parker 2015/10/14 17:37:10 meta note: This is being removed because it is dea
vakh (old account. dont use) 2015/10/15 21:07:08 Acknowledged.
495 const std::string& url_to_report,
496 bool is_client_side_detection) {
497 const std::string current_esc = net::EscapeQueryParamValue(url_to_report,
498 true);
499
500 #if defined(OS_WIN)
501 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
502 std::string client_name(dist->GetSafeBrowsingName());
503 #else
504 std::string client_name("googlechrome");
505 #endif
506 if (is_client_side_detection)
507 client_name.append("_csd");
508
509 GURL report_url(report_page + base::StringPrintf(kReportParams,
510 client_name.c_str(),
511 current_esc.c_str()));
512 return google_util::AppendGoogleLocaleParam(
513 report_url, g_browser_process->GetApplicationLocale());
514 }
515
516 SBFullHash StringToSBFullHash(const std::string& hash_in) { 481 SBFullHash StringToSBFullHash(const std::string& hash_in) {
517 DCHECK_EQ(crypto::kSHA256Length, hash_in.size()); 482 DCHECK_EQ(crypto::kSHA256Length, hash_in.size());
518 SBFullHash hash_out; 483 SBFullHash hash_out;
519 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); 484 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length);
520 return hash_out; 485 return hash_out;
521 } 486 }
522 487
523 std::string SBFullHashToString(const SBFullHash& hash) { 488 std::string SBFullHashToString(const SBFullHash& hash) {
524 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); 489 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash));
525 return std::string(hash.full_hash, sizeof(hash.full_hash)); 490 return std::string(hash.full_hash, sizeof(hash.full_hash));
526 } 491 }
527 492
528 } // namespace safe_browsing_util 493 } // namespace safe_browsing_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698