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 #include "chrome/browser/metrics/variations/variations_seed_store.h" | 5 #include "chrome/browser/metrics/variations/variations_seed_store.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } // namespace | 113 } // namespace |
114 | 114 |
115 VariationsSeedStore::VariationsSeedStore(PrefService* local_state) | 115 VariationsSeedStore::VariationsSeedStore(PrefService* local_state) |
116 : local_state_(local_state) { | 116 : local_state_(local_state) { |
117 } | 117 } |
118 | 118 |
119 VariationsSeedStore::~VariationsSeedStore() { | 119 VariationsSeedStore::~VariationsSeedStore() { |
120 } | 120 } |
121 | 121 |
122 bool VariationsSeedStore::LoadSeed(variations::VariationsSeed* seed) { | 122 bool VariationsSeedStore::LoadSeed(variations::VariationsSeed* seed) { |
| 123 invalid_base64_signature_.clear(); |
123 const std::string base64_seed_data = | 124 const std::string base64_seed_data = |
124 local_state_->GetString(prefs::kVariationsSeed); | 125 local_state_->GetString(prefs::kVariationsSeed); |
125 if (base64_seed_data.empty()) { | 126 if (base64_seed_data.empty()) { |
126 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); | 127 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); |
127 return false; | 128 return false; |
128 } | 129 } |
129 | 130 |
130 // If the decode process fails, assume the pref value is corrupt and clear it. | 131 // If the decode process fails, assume the pref value is corrupt and clear it. |
131 std::string seed_data; | 132 std::string seed_data; |
132 if (!base::Base64Decode(base64_seed_data, &seed_data) || | 133 if (!base::Base64Decode(base64_seed_data, &seed_data) || |
(...skipping 10 matching lines...) Expand all Loading... |
143 const VerifySignatureResult result = | 144 const VerifySignatureResult result = |
144 VerifySeedSignature(seed_data, base64_seed_signature); | 145 VerifySeedSignature(seed_data, base64_seed_signature); |
145 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { | 146 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { |
146 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, | 147 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, |
147 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); | 148 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); |
148 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { | 149 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { |
149 VLOG(1) << "Variations seed signature in local pref missing or invalid " | 150 VLOG(1) << "Variations seed signature in local pref missing or invalid " |
150 << "with result: " << result << ". Clearing the pref."; | 151 << "with result: " << result << ". Clearing the pref."; |
151 ClearPrefs(); | 152 ClearPrefs(); |
152 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_INVALID_SIGNATURE); | 153 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_INVALID_SIGNATURE); |
| 154 // Record the invalid signature. |
| 155 invalid_base64_signature_ = base64_seed_signature; |
153 return false; | 156 return false; |
154 } | 157 } |
155 } | 158 } |
156 | 159 |
157 variations_serial_number_ = seed->serial_number(); | 160 variations_serial_number_ = seed->serial_number(); |
158 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); | 161 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); |
159 return true; | 162 return true; |
160 } | 163 } |
161 | 164 |
162 bool VariationsSeedStore::StoreSeedData( | 165 bool VariationsSeedStore::StoreSeedData( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE; | 268 return VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE; |
266 } | 269 } |
267 | 270 |
268 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), | 271 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), |
269 seed_bytes.size()); | 272 seed_bytes.size()); |
270 if (verifier.VerifyFinal()) | 273 if (verifier.VerifyFinal()) |
271 return VARIATIONS_SEED_SIGNATURE_VALID; | 274 return VARIATIONS_SEED_SIGNATURE_VALID; |
272 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 275 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
273 } | 276 } |
274 | 277 |
| 278 std::string VariationsSeedStore::GetInvalidSignature() const { |
| 279 return invalid_base64_signature_; |
| 280 } |
| 281 |
275 } // namespace chrome_variations | 282 } // namespace chrome_variations |
OLD | NEW |