Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: chrome/browser/metrics/variations/variations_seed_store_unittest.cc

Issue 646733002: Added incident report for variations seed signature mismatch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responded to comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "base/sha1.h" 9 #include "base/sha1.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed)); 119 EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed));
120 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeed)); 120 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeed));
121 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedDate)); 121 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedDate));
122 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedSignature)); 122 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedSignature));
123 123
124 // Check that having no seed in prefs results in a return value of false. 124 // Check that having no seed in prefs results in a return value of false.
125 prefs.ClearPref(prefs::kVariationsSeed); 125 prefs.ClearPref(prefs::kVariationsSeed);
126 EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed)); 126 EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed));
127 } 127 }
128 128
129 TEST(VariationsSeedStoreTest, GetInvalidSignature) {
130 const variations::VariationsSeed seed = CreateTestSeed();
131 std::string seed_hash;
132 const std::string base64_seed = SerializeSeedBase64(seed, &seed_hash);
133
134 TestingPrefServiceSimple prefs;
135 VariationsSeedStore::RegisterPrefs(prefs.registry());
136 prefs.SetString(prefs::kVariationsSeed, base64_seed);
137
138 variations::VariationsSeed loaded_seed;
139
140 // The below seed and signature pair were generated using the server's
141 // private key.
142 const std::string base64_seed_data =
143 "CigxZDI5NDY0ZmIzZDc4ZmYxNTU2ZTViNTUxYzY0NDdjYmM3NGU1ZmQwEr0BCh9VTUEtVW5p"
144 "Zm9ybWl0eS1UcmlhbC0xMC1QZXJjZW50GICckqUFOAFCB2RlZmF1bHRKCwoHZGVmYXVsdBAB"
145 "SgwKCGdyb3VwXzAxEAFKDAoIZ3JvdXBfMDIQAUoMCghncm91cF8wMxABSgwKCGdyb3VwXzA0"
146 "EAFKDAoIZ3JvdXBfMDUQAUoMCghncm91cF8wNhABSgwKCGdyb3VwXzA3EAFKDAoIZ3JvdXBf"
147 "MDgQAUoMCghncm91cF8wORAB";
148 const std::string base64_seed_signature =
149 "MEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy"
150 "96JkMYgzTkHPwbv7K/CmgA==";
151 const std::string base64_seed_signature_invalid =
152 "AEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy"
153 "96JkMYgzTkHPwbv7K/CmgA==";
154
155 // Set seed and valid signature in prefs.
156 prefs.SetString(prefs::kVariationsSeed, base64_seed_data);
157 prefs.SetString(prefs::kVariationsSeedSignature, base64_seed_signature);
158
159 VariationsSeedStore seed_store(&prefs);
160 seed_store.LoadSeed(&loaded_seed);
161 std::string invalid_signature;
162 // Valid signature.
163 EXPECT_FALSE(seed_store.GetInvalidSignature(&invalid_signature));
164
165 prefs.SetString(prefs::kVariationsSeedSignature,
166 base64_seed_signature_invalid);
167 seed_store.LoadSeed(&loaded_seed);
168 // Invalid signature, so we should get the signature itself.
169 EXPECT_TRUE(seed_store.GetInvalidSignature(&invalid_signature));
170 EXPECT_EQ(invalid_signature, base64_seed_signature_invalid);
171
172 prefs.SetString(prefs::kVariationsSeedSignature, std::string());
173 seed_store.LoadSeed(&loaded_seed);
174 // Empty signature, not considered invalid.
175 EXPECT_FALSE(seed_store.GetInvalidSignature(&invalid_signature));
176 }
177
129 TEST(VariationsSeedStoreTest, StoreSeedData) { 178 TEST(VariationsSeedStoreTest, StoreSeedData) {
130 const variations::VariationsSeed seed = CreateTestSeed(); 179 const variations::VariationsSeed seed = CreateTestSeed();
131 const std::string serialized_seed = SerializeSeed(seed); 180 const std::string serialized_seed = SerializeSeed(seed);
132 181
133 TestingPrefServiceSimple prefs; 182 TestingPrefServiceSimple prefs;
134 VariationsSeedStore::RegisterPrefs(prefs.registry()); 183 VariationsSeedStore::RegisterPrefs(prefs.registry());
135 184
136 TestVariationsSeedStore seed_store(&prefs); 185 TestVariationsSeedStore seed_store(&prefs);
137 186
138 EXPECT_TRUE(seed_store.StoreSeedForTesting(serialized_seed)); 187 EXPECT_TRUE(seed_store.StoreSeedForTesting(serialized_seed));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 seed_store.VerifySeedSignature(seed_data, base64_seed_data)); 264 seed_store.VerifySeedSignature(seed_data, base64_seed_data));
216 #endif 265 #endif
217 266
218 // Using a different seed should not match the signature. 267 // Using a different seed should not match the signature.
219 seed_data[0] = 'x'; 268 seed_data[0] = 'x';
220 EXPECT_EQ(VariationsSeedStore::VARIATIONS_SEED_SIGNATURE_INVALID_SEED, 269 EXPECT_EQ(VariationsSeedStore::VARIATIONS_SEED_SIGNATURE_INVALID_SEED,
221 seed_store.VerifySeedSignature(seed_data, base64_seed_signature)); 270 seed_store.VerifySeedSignature(seed_data, base64_seed_signature));
222 } 271 }
223 272
224 } // namespace chrome_variations 273 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698