| 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/hmac.h" | 7 #include "base/hmac.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/sha2.h" | 9 #include "base/sha2.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 net::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 net::Base64Decode(mac_copy, &decoded_mac); |
| 172 | 172 |
| 173 base::HMAC hmac(base::HMAC::SHA1, | 173 base::HMAC hmac(base::HMAC::SHA1); |
| 174 reinterpret_cast<const unsigned char*>(decoded_key.data()), | 174 if (!hmac.Init(decoded_key)) |
| 175 static_cast<int>(decoded_key.length())); | 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; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void FreeChunks(std::deque<SBChunk>* chunks) { | 184 void FreeChunks(std::deque<SBChunk>* chunks) { |
| 185 while (!chunks->empty()) { | 185 while (!chunks->empty()) { |
| (...skipping 444 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 |