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

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

Issue 10069031: Replace SafeBrowsing MAC with downloads over SSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base64.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/string_util.h" 8 #include "base/string_util.h"
10 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
11 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
12 #include "crypto/hmac.h"
13 #include "crypto/sha2.h" 11 #include "crypto/sha2.h"
14 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
15 #include "googleurl/src/url_util.h" 13 #include "googleurl/src/url_util.h"
16 #include "net/base/escape.h" 14 #include "net/base/escape.h"
17 #include "unicode/locid.h" 15 #include "unicode/locid.h"
18 16
19 #if defined(OS_WIN) 17 #if defined(OS_WIN)
20 #include "chrome/installer/util/browser_distribution.h" 18 #include "chrome/installer/util/browser_distribution.h"
21 #endif 19 #endif
22 20
23 static const int kSafeBrowsingMacDigestSize = 20;
24
25 // Continue to this URL after submitting the phishing report form. 21 // Continue to this URL after submitting the phishing report form.
26 // TODO(paulg): Change to a Chrome specific URL. 22 // TODO(paulg): Change to a Chrome specific URL.
27 static const char kContinueUrlFormat[] = 23 static const char kContinueUrlFormat[] =
28 "http://www.google.com/tools/firefox/toolbar/FT2/intl/%s/submit_success.html"; 24 "http://www.google.com/tools/firefox/toolbar/FT2/intl/%s/submit_success.html";
29 25
30 static const char kReportParams[] = "?tpl=%s&continue=%s&url=%s"; 26 static const char kReportParams[] = "?tpl=%s&continue=%s&url=%s";
31 27
32 // SBChunk --------------------------------------------------------------------- 28 // SBChunk ---------------------------------------------------------------------
33 29
34 SBChunk::SBChunk() 30 SBChunk::SBChunk()
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 468 }
473 469
474 bool IsBadbinurlList(const std::string& list_name) { 470 bool IsBadbinurlList(const std::string& list_name) {
475 return list_name.compare(kBinUrlList) == 0; 471 return list_name.compare(kBinUrlList) == 0;
476 } 472 }
477 473
478 bool IsBadbinhashList(const std::string& list_name) { 474 bool IsBadbinhashList(const std::string& list_name) {
479 return list_name.compare(kBinHashList) == 0; 475 return list_name.compare(kBinHashList) == 0;
480 } 476 }
481 477
482 static void DecodeWebSafe(std::string* decoded) {
483 DCHECK(decoded);
484 for (std::string::iterator i(decoded->begin()); i != decoded->end(); ++i) {
485 if (*i == '_')
486 *i = '/';
487 else if (*i == '-')
488 *i = '+';
489 }
490 }
491
492 bool VerifyMAC(const std::string& key, const std::string& mac,
493 const char* data, int data_length) {
494 std::string key_copy = key;
495 DecodeWebSafe(&key_copy);
496 std::string decoded_key;
497 base::Base64Decode(key_copy, &decoded_key);
498
499 std::string mac_copy = mac;
500 DecodeWebSafe(&mac_copy);
501 std::string decoded_mac;
502 base::Base64Decode(mac_copy, &decoded_mac);
503
504 crypto::HMAC hmac(crypto::HMAC::SHA1);
505 if (!hmac.Init(decoded_key))
506 return false;
507 const std::string data_str(data, data_length);
508 unsigned char digest[kSafeBrowsingMacDigestSize];
509 if (!hmac.Sign(data_str, digest, kSafeBrowsingMacDigestSize))
510 return false;
511
512 return !memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize);
513 }
514
515 GURL GeneratePhishingReportUrl(const std::string& report_page, 478 GURL GeneratePhishingReportUrl(const std::string& report_page,
516 const std::string& url_to_report, 479 const std::string& url_to_report,
517 bool is_client_side_detection) { 480 bool is_client_side_detection) {
518 icu::Locale locale = icu::Locale::getDefault(); 481 icu::Locale locale = icu::Locale::getDefault();
519 const char* lang = locale.getLanguage(); 482 const char* lang = locale.getLanguage();
520 if (!lang) 483 if (!lang)
521 lang = "en"; // fallback 484 lang = "en"; // fallback
522 const std::string continue_esc = net::EscapeQueryParamValue( 485 const std::string continue_esc = net::EscapeQueryParamValue(
523 base::StringPrintf(kContinueUrlFormat, lang), true); 486 base::StringPrintf(kContinueUrlFormat, lang), true);
524 const std::string current_esc = net::EscapeQueryParamValue(url_to_report, 487 const std::string current_esc = net::EscapeQueryParamValue(url_to_report,
(...skipping 18 matching lines...) Expand all
543 void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) { 506 void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) {
544 DCHECK_EQ(crypto::kSHA256Length, hash_in.size()); 507 DCHECK_EQ(crypto::kSHA256Length, hash_in.size());
545 memcpy(hash_out->full_hash, hash_in.data(), crypto::kSHA256Length); 508 memcpy(hash_out->full_hash, hash_in.data(), crypto::kSHA256Length);
546 } 509 }
547 510
548 std::string SBFullHashToString(const SBFullHash& hash) { 511 std::string SBFullHashToString(const SBFullHash& hash) {
549 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); 512 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash));
550 return std::string(hash.full_hash, sizeof(hash.full_hash)); 513 return std::string(hash.full_hash, sizeof(hash.full_hash));
551 } 514 }
552 } // namespace safe_browsing_util 515 } // namespace safe_browsing_util
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698