| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // The server date is earlier than the stored date, and they are from | 106 // The server date is earlier than the stored date, and they are from |
| 107 // different UTC days, so |server_seed_date| is a valid new day. | 107 // different UTC days, so |server_seed_date| is a valid new day. |
| 108 return SEED_DATE_NEW_DAY; | 108 return SEED_DATE_NEW_DAY; |
| 109 } | 109 } |
| 110 return SEED_DATE_SAME_DAY; | 110 return SEED_DATE_SAME_DAY; |
| 111 } | 111 } |
| 112 | 112 |
| 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), is_invalid_signature_(false) { |
| 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_signature_.clear(); |
| 124 is_invalid_signature_ = false; |
| 123 const std::string base64_seed_data = | 125 const std::string base64_seed_data = |
| 124 local_state_->GetString(prefs::kVariationsSeed); | 126 local_state_->GetString(prefs::kVariationsSeed); |
| 125 if (base64_seed_data.empty()) { | 127 if (base64_seed_data.empty()) { |
| 126 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); | 128 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); |
| 127 return false; | 129 return false; |
| 128 } | 130 } |
| 129 | 131 |
| 130 // If the decode process fails, assume the pref value is corrupt and clear it. | 132 // If the decode process fails, assume the pref value is corrupt and clear it. |
| 131 std::string seed_data; | 133 std::string seed_data; |
| 132 if (!base::Base64Decode(base64_seed_data, &seed_data) || | 134 if (!base::Base64Decode(base64_seed_data, &seed_data) || |
| (...skipping 10 matching lines...) Expand all Loading... |
| 143 const VerifySignatureResult result = | 145 const VerifySignatureResult result = |
| 144 VerifySeedSignature(seed_data, base64_seed_signature); | 146 VerifySeedSignature(seed_data, base64_seed_signature); |
| 145 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { | 147 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { |
| 146 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, | 148 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, |
| 147 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); | 149 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); |
| 148 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { | 150 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { |
| 149 VLOG(1) << "Variations seed signature in local pref missing or invalid " | 151 VLOG(1) << "Variations seed signature in local pref missing or invalid " |
| 150 << "with result: " << result << ". Clearing the pref."; | 152 << "with result: " << result << ". Clearing the pref."; |
| 151 ClearPrefs(); | 153 ClearPrefs(); |
| 152 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_INVALID_SIGNATURE); | 154 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_INVALID_SIGNATURE); |
| 155 // Record the invalid signature. |
| 156 is_invalid_signature_ = true; |
| 157 invalid_signature_ = base64_seed_signature; |
| 153 return false; | 158 return false; |
| 154 } | 159 } |
| 155 } | 160 } |
| 156 | 161 |
| 157 variations_serial_number_ = seed->serial_number(); | 162 variations_serial_number_ = seed->serial_number(); |
| 158 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); | 163 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); |
| 159 return true; | 164 return true; |
| 160 } | 165 } |
| 161 | 166 |
| 162 bool VariationsSeedStore::StoreSeedData( | 167 bool VariationsSeedStore::StoreSeedData( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE; | 270 return VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE; |
| 266 } | 271 } |
| 267 | 272 |
| 268 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), | 273 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), |
| 269 seed_bytes.size()); | 274 seed_bytes.size()); |
| 270 if (verifier.VerifyFinal()) | 275 if (verifier.VerifyFinal()) |
| 271 return VARIATIONS_SEED_SIGNATURE_VALID; | 276 return VARIATIONS_SEED_SIGNATURE_VALID; |
| 272 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 277 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
| 273 } | 278 } |
| 274 | 279 |
| 280 bool VariationsSeedStore::GetInvalidSignature( |
| 281 std::string* invalid_signature) const { |
| 282 if (!is_invalid_signature_) |
| 283 return false; |
| 284 *invalid_signature = invalid_signature_; |
| 285 return true; |
| 286 } |
| 287 |
| 275 } // namespace chrome_variations | 288 } // namespace chrome_variations |
| OLD | NEW |