OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/hmac.h" | 8 #include "base/hmac.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/sha2.h" | 10 #include "base/sha2.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "chrome/browser/google_util.h" | 12 #include "chrome/browser/google_util.h" |
12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
13 #include "net/base/base64.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 static const int kSafeBrowsingMacDigestSize = 20; | 17 static const int kSafeBrowsingMacDigestSize = 20; |
18 | 18 |
19 // Continue to this URL after submitting the phishing report form. | 19 // Continue to this URL after submitting the phishing report form. |
20 // TODO(paulg): Change to a Chrome specific URL. | 20 // TODO(paulg): Change to a Chrome specific URL. |
21 static const char kContinueUrlFormat[] = | 21 static const char kContinueUrlFormat[] = |
22 "http://www.google.com/tools/firefox/toolbar/FT2/intl/%s/submit_success.html"; | 22 "http://www.google.com/tools/firefox/toolbar/FT2/intl/%s/submit_success.html"; |
23 | 23 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 break; | 156 break; |
157 } | 157 } |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 bool VerifyMAC(const std::string& key, const std::string& mac, | 161 bool VerifyMAC(const std::string& key, const std::string& mac, |
162 const char* data, int data_length) { | 162 const char* data, int data_length) { |
163 std::string key_copy = key; | 163 std::string key_copy = key; |
164 DecodeWebSafe(&key_copy); | 164 DecodeWebSafe(&key_copy); |
165 std::string decoded_key; | 165 std::string decoded_key; |
166 net::Base64Decode(key_copy, &decoded_key); | 166 base::Base64Decode(key_copy, &decoded_key); |
167 | 167 |
168 std::string mac_copy = mac; | 168 std::string mac_copy = mac; |
169 DecodeWebSafe(&mac_copy); | 169 DecodeWebSafe(&mac_copy); |
170 std::string decoded_mac; | 170 std::string decoded_mac; |
171 net::Base64Decode(mac_copy, &decoded_mac); | 171 base::Base64Decode(mac_copy, &decoded_mac); |
172 | 172 |
173 base::HMAC hmac(base::HMAC::SHA1); | 173 base::HMAC hmac(base::HMAC::SHA1); |
174 if (!hmac.Init(decoded_key)) | 174 if (!hmac.Init(decoded_key)) |
175 return false; | 175 return false; |
176 const std::string data_str(data, data_length); | 176 const std::string data_str(data, data_length); |
177 unsigned char digest[kSafeBrowsingMacDigestSize]; | 177 unsigned char digest[kSafeBrowsingMacDigestSize]; |
178 if (!hmac.Sign(data_str, digest, kSafeBrowsingMacDigestSize)) | 178 if (!hmac.Sign(data_str, digest, kSafeBrowsingMacDigestSize)) |
179 return false; | 179 return false; |
180 | 180 |
181 return memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize) == 0; | 181 return memcmp(digest, decoded_mac.data(), kSafeBrowsingMacDigestSize) == 0; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 630 |
631 // Validate that the next entry is wholly contained inside of |data_|. | 631 // Validate that the next entry is wholly contained inside of |data_|. |
632 const char* end = data_.get() + size_; | 632 const char* end = data_.get() + size_; |
633 if (next + SBEntry::kMinSize <= end && next + next_entry->Size() <= end) { | 633 if (next + SBEntry::kMinSize <= end && next + next_entry->Size() <= end) { |
634 *entry = next_entry; | 634 *entry = next_entry; |
635 return true; | 635 return true; |
636 } | 636 } |
637 | 637 |
638 return false; | 638 return false; |
639 } | 639 } |
OLD | NEW |