• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_STORE_TRANSACTION_H_
6 #define CHROME_BROWSER_PREFS_PREF_HASH_STORE_TRANSACTION_H_
7 
8 #include <string>
9 #include <vector>
10 
11 namespace base {
12 class DictionaryValue;
13 class Value;
14 }  // namespace base
15 
16 // Used to perform a series of checks/transformations on a PrefHashStore.
17 class PrefHashStoreTransaction {
18  public:
19   enum ValueState {
20     // The preference value corresponds to its stored hash.
21     UNCHANGED,
22     // The preference has been cleared since the last hash.
23     CLEARED,
24     // The preference value corresponds to its stored hash, which was calculated
25     // using a deprecated hash algorithm which isn't as safe as the current one.
26     WEAK_LEGACY,
27     // The preference value corresponds to its stored hash, but the hash was
28     // calculated using a deprecated hash algorithm which is just as safe as
29     // the current one.
30     SECURE_LEGACY,
31     // The preference value has been changed since the last hash.
32     CHANGED,
33     // No stored hash exists for the preference value.
34     UNTRUSTED_UNKNOWN_VALUE,
35     // No stored hash exists for the preference value, but the current set of
36     // hashes stored is trusted and thus this value can safely be seeded. This
37     // happens when all hashes are already properly seeded and a newly
38     // tracked value needs to be seeded). NULL values are inherently trusted as
39     // well.
40     TRUSTED_UNKNOWN_VALUE,
41   };
42 
43   // Finalizes any remaining work after the transaction has been performed.
~PrefHashStoreTransaction()44   virtual ~PrefHashStoreTransaction() {}
45 
46   // Checks |initial_value| against the existing stored value hash.
47   virtual ValueState CheckValue(
48       const std::string& path, const base::Value* initial_value) const = 0;
49 
50   // Stores a hash of the current |value| of the preference at |path|.
51   virtual void StoreHash(const std::string& path,
52                          const base::Value* value) = 0;
53 
54   // Checks |initial_value| against the existing stored hashes for the split
55   // preference at |path|. |initial_split_value| being an empty dictionary or
56   // NULL is equivalent. |invalid_keys| must initially be empty. |invalid_keys|
57   // will not be modified unless the return value is CHANGED, in which case it
58   // will be filled with the keys that are considered invalid (unknown or
59   // changed).
60   virtual ValueState CheckSplitValue(
61       const std::string& path,
62       const base::DictionaryValue* initial_split_value,
63       std::vector<std::string>* invalid_keys) const = 0;
64 
65   // Stores hashes for the |value| of the split preference at |path|.
66   // |split_value| being an empty dictionary or NULL is equivalent.
67   virtual void StoreSplitHash(
68       const std::string& path,
69       const base::DictionaryValue* split_value) = 0;
70 
71   // Indicates whether the store contains a hash for the preference at |path|.
72   virtual bool HasHash(const std::string& path) const = 0;
73 
74   // Sets the hash for the preference at |path|.
75   // If |path| is a split preference |hash| must be a DictionaryValue whose
76   // keys are keys in the split preference and whose values are MACs of the
77   // corresponding values in the split preference.
78   // If |path| is an atomic preference |hash| must be a StringValue
79   // containing a MAC of the preference value.
80   // |hash| should originate from a PrefHashStore sharing the same MAC
81   // parameters as this transaction's store.
82   // The (in)validity of the super MAC will be maintained by this call.
83   virtual void ImportHash(const std::string& path, const base::Value* hash) = 0;
84 
85   // Removes the hash stored at |path|. The (in)validity of the super MAC will
86   // be maintained by this call.
87   virtual void ClearHash(const std::string& path) = 0;
88 
89   // Indicates whether the super MAC was successfully verified at the beginning
90   // of this transaction.
91   virtual bool IsSuperMACValid() const = 0;
92 
93   // Forces a valid super MAC to be stored when this transaction terminates.
94   // Returns true if this results in a change to the store contents.
95   virtual bool StampSuperMac() = 0;
96 };
97 
98 #endif  // CHROME_BROWSER_PREFS_PREF_HASH_STORE_TRANSACTION_H_
99