| 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*)>& |
| 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 #if defined(OS_ANDROID) |
| 116 // Imports the variations seed data from Java side during the first |
| 117 // Chrome for Android run. |
| 118 void ImportFirstRunJavaSeed(); |
| 119 #endif // OS_ANDROID |
| 120 |
| 106 // Reads the variations seed data from prefs; returns true on success. | 121 // Reads the variations seed data from prefs; returns true on success. |
| 107 bool ReadSeedData(std::string* seed_data); | 122 bool ReadSeedData(std::string* seed_data); |
| 108 | 123 |
| 109 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta | 124 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta |
| 110 // compressed. | 125 // compressed. |
| 111 bool StoreSeedDataNoDelta( | 126 bool StoreSeedDataNoDelta( |
| 112 const std::string& seed_data, | 127 const std::string& seed_data, |
| 113 const std::string& base64_seed_signature, | 128 const std::string& base64_seed_signature, |
| 114 const std::string& country_code, | 129 const std::string& country_code, |
| 115 const base::Time& date_fetched, | 130 const base::Time& date_fetched, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 127 // Cached serial number from the most recently fetched variations seed. | 142 // Cached serial number from the most recently fetched variations seed. |
| 128 std::string variations_serial_number_; | 143 std::string variations_serial_number_; |
| 129 | 144 |
| 130 // Whether the most recently fetched variations seed has the country code | 145 // Whether the most recently fetched variations seed has the country code |
| 131 // field set. | 146 // field set. |
| 132 bool seed_has_country_code_; | 147 bool seed_has_country_code_; |
| 133 | 148 |
| 134 // Keeps track of an invalid signature. | 149 // Keeps track of an invalid signature. |
| 135 std::string invalid_base64_signature_; | 150 std::string invalid_base64_signature_; |
| 136 | 151 |
| 152 #if defined(OS_ANDROID) |
| 153 base::Callback<void(std::string*, std::string*, std::string*)> |
| 154 get_variations_first_run_seed_; |
| 155 #endif // OS_ANDROID |
| 156 |
| 137 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); | 157 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); |
| 138 }; | 158 }; |
| 139 | 159 |
| 140 } // namespace variations | 160 } // namespace variations |
| 141 | 161 |
| 142 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 162 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
| OLD | NEW |