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

Side by Side Diff: components/safe_browsing_db/v4_store.h

Issue 2384893002: PVer4: Test checksum on startup outside the hotpath of DB load (Closed)
Patch Set: Created 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 TestHashPrefixExistsInMapWithSingleSize); 239 TestHashPrefixExistsInMapWithSingleSize);
240 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, 240 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
241 TestHashPrefixExistsInMapWithDifferentSizes); 241 TestHashPrefixExistsInMapWithDifferentSizes);
242 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, 242 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
243 TestHashPrefixDoesNotExistInMapWithDifferentSizes); 243 TestHashPrefixDoesNotExistInMapWithDifferentSizes);
244 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, 244 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
245 TestAdditionsWithRiceEncodingFailsWithInvalidInput); 245 TestAdditionsWithRiceEncodingFailsWithInvalidInput);
246 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds); 246 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds);
247 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds); 247 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds);
248 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesFailsChecksum); 248 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesFailsChecksum);
249 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestChecksumErrorOnStartup);
249 friend class V4StoreTest; 250 friend class V4StoreTest;
250 251
251 // If |prefix_size| is within expected range, and |raw_hashes_length| is a 252 // If |prefix_size| is within expected range, and |raw_hashes_length| is a
252 // multiple of prefix_size, then it sets the string of length 253 // multiple of prefix_size, then it sets the string of length
253 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key 254 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key
254 // |prefix_size| in |additions_map| 255 // |prefix_size| in |additions_map|
255 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, 256 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size,
256 const char* raw_hashes_begin, 257 const char* raw_hashes_begin,
257 const size_t raw_hashes_length, 258 const size_t raw_hashes_length,
258 HashPrefixMap* additions_map); 259 HashPrefixMap* additions_map);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 293
293 // Updates the |additions_map| with the additions received in the partial 294 // Updates the |additions_map| with the additions received in the partial
294 // update from the server. 295 // update from the server.
295 static ApplyUpdateResult UpdateHashPrefixMapFromAdditions( 296 static ApplyUpdateResult UpdateHashPrefixMapFromAdditions(
296 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, 297 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions,
297 HashPrefixMap* additions_map); 298 HashPrefixMap* additions_map);
298 299
299 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the 300 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the
300 // update (additions_map) to populate the prefix map for the current store. 301 // update (additions_map) to populate the prefix map for the current store.
301 // The indices in the |raw_removals| list, which may be NULL, are not merged. 302 // The indices in the |raw_removals| list, which may be NULL, are not merged.
302 // The SHA256 checksum of the final list of hash prefixes, in lexographically 303 // The SHA256 checksum of the final list of hash prefixes, in
303 // sorted order, must match |expected_checksum| (if it's not empty). 304 // lexicographically sorted order, must match |expected_checksum| (if it's not
305 // empty).
304 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, 306 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map,
305 const HashPrefixMap& additions_map, 307 const HashPrefixMap& additions_map,
306 const ::google::protobuf::RepeatedField< 308 const ::google::protobuf::RepeatedField<
307 ::google::protobuf::int32>* raw_removals, 309 ::google::protobuf::int32>* raw_removals,
308 const std::string& expected_checksum); 310 const std::string& expected_checksum);
309 311
310 // Processes the FULL_UPDATE |response| from the server, and writes the 312 // Processes the FULL_UPDATE |response| from the server, and writes the
311 // merged V4Store to disk. If processing the |response| succeeds, it returns 313 // merged V4Store to disk. If processing the |response| succeeds, it returns
312 // APPLY_UPDATE_SUCCESS. 314 // APPLY_UPDATE_SUCCESS.
313 // This method is only called when we receive a FULL_UPDATE from the server. 315 // This method is only called when we receive a FULL_UPDATE from the server.
(...skipping 20 matching lines...) Expand all
334 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing 336 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing
335 // succeeds, it returns APPLY_UPDATE_SUCCESS. 337 // succeeds, it returns APPLY_UPDATE_SUCCESS.
336 ApplyUpdateResult ProcessUpdate( 338 ApplyUpdateResult ProcessUpdate(
337 const HashPrefixMap& hash_prefix_map_old, 339 const HashPrefixMap& hash_prefix_map_old,
338 const std::unique_ptr<ListUpdateResponse>& response); 340 const std::unique_ptr<ListUpdateResponse>& response);
339 341
340 // Reads the state of the store from the file on disk and returns the reason 342 // Reads the state of the store from the file on disk and returns the reason
341 // for the failure or reports success. 343 // for the failure or reports success.
342 StoreReadResult ReadFromDisk(); 344 StoreReadResult ReadFromDisk();
343 345
346 // Scheduled when reading the store file from disk on startup. When run, it
347 // ensures that the checksum of the hash prefixes in lexicographical sorted
348 // order matches the expected value. If not, it clears out the contents of
349 // the store.
350 void VerifyChecksum(const std::string& expected_checksum);
351
344 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. 352 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto.
345 StoreWriteResult WriteToDisk( 353 StoreWriteResult WriteToDisk(
346 std::unique_ptr<ListUpdateResponse> response) const; 354 std::unique_ptr<ListUpdateResponse> response) const;
347 355
348 // The state of the store as returned by the PVer4 server in the last applied 356 // The state of the store as returned by the PVer4 server in the last applied
349 // update response. 357 // update response.
350 std::string state_; 358 std::string state_;
351 const base::FilePath store_path_; 359 const base::FilePath store_path_;
352 HashPrefixMap hash_prefix_map_; 360 HashPrefixMap hash_prefix_map_;
353 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 361 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
354 }; 362 };
355 363
356 std::ostream& operator<<(std::ostream& os, const V4Store& store); 364 std::ostream& operator<<(std::ostream& os, const V4Store& store);
357 365
358 } // namespace safe_browsing 366 } // namespace safe_browsing
359 367
360 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ 368 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_store.cc » ('j') | components/safe_browsing_db/v4_store.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698