OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 5 #ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
6 #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 6 #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 | 14 |
14 class PrefService; | 15 class PrefService; |
15 class PrefRegistrySimple; | 16 class PrefRegistrySimple; |
16 | 17 |
17 namespace variations { | 18 namespace variations { |
18 class VariationsSeed; | 19 class VariationsSeed; |
19 } | 20 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 return seed_has_country_code_; | 69 return seed_has_country_code_; |
69 } | 70 } |
70 | 71 |
71 // Returns the invalid signature in base64 format, or an empty string if the | 72 // Returns the invalid signature in base64 format, or an empty string if the |
72 // signature was valid, missing, or if signature verification is disabled. | 73 // signature was valid, missing, or if signature verification is disabled. |
73 std::string GetInvalidSignature() const; | 74 std::string GetInvalidSignature() const; |
74 | 75 |
75 // Registers Local State prefs used by this class. | 76 // Registers Local State prefs used by this class. |
76 static void RegisterPrefs(PrefRegistrySimple* registry); | 77 static void RegisterPrefs(PrefRegistrySimple* registry); |
77 | 78 |
79 #if defined(OS_ANDROID) | |
80 void SetVariationsFirstRunSeedCallback( | |
81 const base::Callback<void(std::string*, std::string*, std::string*)>& | |
Bernhard Bauer
2015/10/30 09:56:08
Hm... instead of a single callback that returns th
Steven Holte
2015/11/02 19:05:40
They are not really independent, since they all co
Bernhard Bauer
2015/11/02 19:10:07
What I meant was that it looks like doing this wit
Alexei Svitkine (slow)
2015/11/02 20:39:21
They are meant to be used together. I think a stru
| |
82 callback) { | |
83 get_variations_first_run_seed_ = callback; | |
84 } | |
85 #endif // OS_ANDROID | |
86 | |
78 protected: | 87 protected: |
79 // Note: UMA histogram enum - don't re-order or remove entries. | 88 // Note: UMA histogram enum - don't re-order or remove entries. |
80 enum VerifySignatureResult { | 89 enum VerifySignatureResult { |
81 VARIATIONS_SEED_SIGNATURE_MISSING, | 90 VARIATIONS_SEED_SIGNATURE_MISSING, |
82 VARIATIONS_SEED_SIGNATURE_DECODE_FAILED, | 91 VARIATIONS_SEED_SIGNATURE_DECODE_FAILED, |
83 VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE, | 92 VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE, |
84 VARIATIONS_SEED_SIGNATURE_INVALID_SEED, | 93 VARIATIONS_SEED_SIGNATURE_INVALID_SEED, |
85 VARIATIONS_SEED_SIGNATURE_VALID, | 94 VARIATIONS_SEED_SIGNATURE_VALID, |
86 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE, | 95 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE, |
87 }; | 96 }; |
88 | 97 |
89 // Verifies a variations seed (the serialized proto bytes) with the specified | 98 // Verifies a variations seed (the serialized proto bytes) with the specified |
90 // base-64 encoded signature that was received from the server and returns the | 99 // base-64 encoded signature that was received from the server and returns the |
91 // result. The signature is assumed to be an "ECDSA with SHA-256" signature | 100 // result. The signature is assumed to be an "ECDSA with SHA-256" signature |
92 // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of | 101 // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of |
93 // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature | 102 // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature |
94 // verification is not enabled. | 103 // verification is not enabled. |
95 virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature( | 104 virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature( |
96 const std::string& seed_bytes, | 105 const std::string& seed_bytes, |
97 const std::string& base64_seed_signature); | 106 const std::string& base64_seed_signature); |
98 | 107 |
99 private: | 108 private: |
100 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature); | 109 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature); |
101 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, ApplyDeltaPatch); | 110 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, ApplyDeltaPatch); |
102 | 111 |
103 // Clears all prefs related to variations seed storage. | 112 // Clears all prefs related to variations seed storage. |
104 void ClearPrefs(); | 113 void ClearPrefs(); |
105 | 114 |
115 // Imports the variations seed data from Java side during the first | |
116 // Chrome for Android run. | |
117 void ImportFirstRunJavaSeed(); | |
118 | |
106 // Reads the variations seed data from prefs; returns true on success. | 119 // Reads the variations seed data from prefs; returns true on success. |
107 bool ReadSeedData(std::string* seed_data); | 120 bool ReadSeedData(std::string* seed_data); |
108 | 121 |
109 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta | 122 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta |
110 // compressed. | 123 // compressed. |
111 bool StoreSeedDataNoDelta( | 124 bool StoreSeedDataNoDelta( |
112 const std::string& seed_data, | 125 const std::string& seed_data, |
113 const std::string& base64_seed_signature, | 126 const std::string& base64_seed_signature, |
114 const std::string& country_code, | 127 const std::string& country_code, |
115 const base::Time& date_fetched, | 128 const base::Time& date_fetched, |
(...skipping 11 matching lines...) Expand all Loading... | |
127 // Cached serial number from the most recently fetched variations seed. | 140 // Cached serial number from the most recently fetched variations seed. |
128 std::string variations_serial_number_; | 141 std::string variations_serial_number_; |
129 | 142 |
130 // Whether the most recently fetched variations seed has the country code | 143 // Whether the most recently fetched variations seed has the country code |
131 // field set. | 144 // field set. |
132 bool seed_has_country_code_; | 145 bool seed_has_country_code_; |
133 | 146 |
134 // Keeps track of an invalid signature. | 147 // Keeps track of an invalid signature. |
135 std::string invalid_base64_signature_; | 148 std::string invalid_base64_signature_; |
136 | 149 |
150 base::Callback<void(std::string*, std::string*, std::string*)> | |
151 get_variations_first_run_seed_; | |
152 | |
137 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); | 153 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); |
138 }; | 154 }; |
139 | 155 |
140 } // namespace variations | 156 } // namespace variations |
141 | 157 |
142 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 158 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
OLD | NEW |