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

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

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 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
OLDNEW
1 // Copyright (c) 2010 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/hmac.h"
9 #include "base/sha2.h"
10 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "crypto/hmac.h"
10 #include "crypto/sha2.h"
11 #include "chrome/browser/google/google_util.h" 11 #include "chrome/browser/google/google_util.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "googleurl/src/url_util.h" 13 #include "googleurl/src/url_util.h"
14 #include "net/base/escape.h" 14 #include "net/base/escape.h"
15 #include "unicode/locid.h" 15 #include "unicode/locid.h"
16 16
17 #if defined(OS_WIN) 17 #if defined(OS_WIN)
18 #include "chrome/installer/util/browser_distribution.h" 18 #include "chrome/installer/util/browser_distribution.h"
19 #endif 19 #endif
20 20
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 if (full_hashes.empty()) 429 if (full_hashes.empty())
430 return -1; 430 return -1;
431 431
432 std::vector<std::string> hosts, paths; 432 std::vector<std::string> hosts, paths;
433 GenerateHostsToCheck(url, &hosts); 433 GenerateHostsToCheck(url, &hosts);
434 GeneratePathsToCheck(url, &paths); 434 GeneratePathsToCheck(url, &paths);
435 435
436 for (size_t h = 0; h < hosts.size(); ++h) { 436 for (size_t h = 0; h < hosts.size(); ++h) {
437 for (size_t p = 0; p < paths.size(); ++p) { 437 for (size_t p = 0; p < paths.size(); ++p) {
438 SBFullHash key; 438 SBFullHash key;
439 base::SHA256HashString(hosts[h] + paths[p], 439 crypto::SHA256HashString(hosts[h] + paths[p],
440 key.full_hash, 440 key.full_hash,
441 sizeof(SBFullHash)); 441 sizeof(SBFullHash));
442 int index = GetHashIndex(key, full_hashes); 442 int index = GetHashIndex(key, full_hashes);
443 if (index != -1) return index; 443 if (index != -1) return index;
444 } 444 }
445 } 445 }
446 446
447 return -1; 447 return -1;
448 } 448 }
449 449
450 bool IsPhishingList(const std::string& list_name) { 450 bool IsPhishingList(const std::string& list_name) {
451 return list_name.compare(kPhishingList) == 0; 451 return list_name.compare(kPhishingList) == 0;
(...skipping 26 matching lines...) Expand all
478 std::string key_copy = key; 478 std::string key_copy = key;
479 DecodeWebSafe(&key_copy); 479 DecodeWebSafe(&key_copy);
480 std::string decoded_key; 480 std::string decoded_key;
481 base::Base64Decode(key_copy, &decoded_key); 481 base::Base64Decode(key_copy, &decoded_key);
482 482
483 std::string mac_copy = mac; 483 std::string mac_copy = mac;
484 DecodeWebSafe(&mac_copy); 484 DecodeWebSafe(&mac_copy);
485 std::string decoded_mac; 485 std::string decoded_mac;
486 base::Base64Decode(mac_copy, &decoded_mac); 486 base::Base64Decode(mac_copy, &decoded_mac);
487 487
488 base::HMAC hmac(base::HMAC::SHA1); 488 crypto::HMAC hmac(crypto::HMAC::SHA1);
489 if (!hmac.Init(decoded_key)) 489 if (!hmac.Init(decoded_key))
490 return false; 490 return false;
491 const std::string data_str(data, data_length); 491 const std::string data_str(data, data_length);
492 unsigned char digest[kSafeBrowsingMacDigestSize]; 492 unsigned char digest[kSafeBrowsingMacDigestSize];
493 if (!hmac.Sign(data_str, digest, kSafeBrowsingMacDigestSize)) 493 if (!hmac.Sign(data_str, digest, kSafeBrowsingMacDigestSize))
494 return false; 494 return false;
495 495
496 return !memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize); 496 return !memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize);
497 } 497 }
498 498
(...skipping 14 matching lines...) Expand all
513 std::string client_name("googlechrome"); 513 std::string client_name("googlechrome");
514 #endif 514 #endif
515 515
516 GURL report_url(report_page + 516 GURL report_url(report_page +
517 StringPrintf(kReportParams, client_name.c_str(), continue_esc.c_str(), 517 StringPrintf(kReportParams, client_name.c_str(), continue_esc.c_str(),
518 current_esc.c_str())); 518 current_esc.c_str()));
519 return google_util::AppendGoogleLocaleParam(report_url); 519 return google_util::AppendGoogleLocaleParam(report_url);
520 } 520 }
521 521
522 void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) { 522 void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) {
523 DCHECK_EQ(static_cast<size_t>(base::SHA256_LENGTH), hash_in.size()); 523 DCHECK_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), hash_in.size());
524 memcpy(hash_out->full_hash, hash_in.data(), base::SHA256_LENGTH); 524 memcpy(hash_out->full_hash, hash_in.data(), crypto::SHA256_LENGTH);
525 } 525 }
526 526
527 std::string SBFullHashToString(const SBFullHash& hash) { 527 std::string SBFullHashToString(const SBFullHash& hash) {
528 DCHECK_EQ(static_cast<size_t>(base::SHA256_LENGTH), sizeof(hash.full_hash)); 528 DCHECK_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), sizeof(hash.full_hash));
529 return std::string(hash.full_hash, sizeof(hash.full_hash)); 529 return std::string(hash.full_hash, sizeof(hash.full_hash));
530 } 530 }
531 } // namespace safe_browsing_util 531 } // namespace safe_browsing_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698