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

Side by Side Diff: sync/util/cryptographer_unittest.cc

Issue 452283003: sync: Finish non-blocking type encryption support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cryptographer testing Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « sync/util/cryptographer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/util/cryptographer.h" 5 #include "sync/util/cryptographer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 Cryptographer other_cryptographer(&encryptor_); 194 Cryptographer other_cryptographer(&encryptor_);
195 other_cryptographer.Bootstrap(token); 195 other_cryptographer.Bootstrap(token);
196 EXPECT_TRUE(other_cryptographer.is_ready()); 196 EXPECT_TRUE(other_cryptographer.is_ready());
197 197
198 const char secret[] = "secret"; 198 const char secret[] = "secret";
199 sync_pb::EncryptedData encrypted; 199 sync_pb::EncryptedData encrypted;
200 EXPECT_TRUE(other_cryptographer.EncryptString(secret, &encrypted)); 200 EXPECT_TRUE(other_cryptographer.EncryptString(secret, &encrypted));
201 EXPECT_TRUE(cryptographer_.CanDecryptUsingDefaultKey(encrypted)); 201 EXPECT_TRUE(cryptographer_.CanDecryptUsingDefaultKey(encrypted));
202 } 202 }
203 203
204 // Verifies that copied cryptographers are just as good as the original.
205 //
206 // Encrypt an item using the original cryptographer and two different sets of
207 // keys. Verify that it can decrypt them.
208 //
209 // Then copy the original cryptographer and ensure it can also decrypt these
210 // items and encrypt them with the most recent key.
211 TEST_F(CryptographerTest, CopyConstructor) {
212 sync_pb::PasswordSpecificsData original;
213 original.set_origin("http://example.com");
214 original.set_username_value("luser");
215 original.set_password_value("p4ssw0rd");
216
217 // Start by testing the original cryptogprapher.
218 KeyParams params1 = {"localhost", "dummy", "dummy"};
219 EXPECT_TRUE(cryptographer_.AddKey(params1));
220 EXPECT_TRUE(cryptographer_.is_ready());
221
222 sync_pb::EncryptedData encrypted_k1;
223 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k1));
224
225 KeyParams params2 = {"localhost", "fatuous", "fatuous"};
226 EXPECT_TRUE(cryptographer_.AddKey(params2));
227 EXPECT_TRUE(cryptographer_.is_ready());
228
229 sync_pb::EncryptedData encrypted_k2;
230 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k2));
231
232 sync_pb::PasswordSpecificsData decrypted_k1;
233 sync_pb::PasswordSpecificsData decrypted_k2;
234 EXPECT_TRUE(cryptographer_.Decrypt(encrypted_k1, &decrypted_k1));
235 EXPECT_TRUE(cryptographer_.Decrypt(encrypted_k2, &decrypted_k2));
236
237 EXPECT_EQ(original.SerializeAsString(), decrypted_k1.SerializeAsString());
238 EXPECT_EQ(original.SerializeAsString(), decrypted_k2.SerializeAsString());
239
240 // Clone the cryptographer and test that it behaves the same.
241 Cryptographer cryptographer_clone(cryptographer_);
242
243 // The clone should be able to decrypt with old and new keys.
244 sync_pb::PasswordSpecificsData decrypted_k1_clone;
245 sync_pb::PasswordSpecificsData decrypted_k2_clone;
246 EXPECT_TRUE(cryptographer_clone.Decrypt(encrypted_k1, &decrypted_k1_clone));
247 EXPECT_TRUE(cryptographer_clone.Decrypt(encrypted_k2, &decrypted_k2_clone));
248
249 EXPECT_EQ(original.SerializeAsString(),
250 decrypted_k1_clone.SerializeAsString());
251 EXPECT_EQ(original.SerializeAsString(),
252 decrypted_k2_clone.SerializeAsString());
253
254 // The old cryptographer should be able to decrypt things encrypted by the
255 // new.
256 sync_pb::EncryptedData encrypted_c;
257 EXPECT_TRUE(cryptographer_clone.Encrypt(original, &encrypted_c));
258
259 sync_pb::PasswordSpecificsData decrypted_c;
260 EXPECT_TRUE(cryptographer_.Decrypt(encrypted_c, &decrypted_c));
261 EXPECT_EQ(original.SerializeAsString(), decrypted_c.SerializeAsString());
262
263 // The cloned cryptographer should be using the latest key.
264 EXPECT_EQ(encrypted_c.key_name(), encrypted_k2.key_name());
265 }
266
204 } // namespace syncer 267 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/util/cryptographer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698