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

Side by Side Diff: sync/internal_api/sync_encryption_handler_impl.h

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SYNC_INTERNAL_API_SYNC_ENCRYPTION_HANDLER_IMPL_H
6 #define SYNC_INTERNAL_API_SYNC_ENCRYPTION_HANDLER_IMPL_H
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "sync/internal_api/public/sync_encryption_handler.h"
16
17 namespace syncer {
18
19 struct UserShare;
20 class WriteNode;
21 class WriteTransaction;
22
23 class SyncEncryptionHandlerImpl : public SyncEncryptionHandler {
24 public:
25 SyncEncryptionHandlerImpl(UserShare* user_share,
26 Cryptographer* cryptographer);
27 virtual ~SyncEncryptionHandlerImpl();
28
29 // SyncEncryptionHandler implementation.
30 virtual void AddObserver(Observer* observer) OVERRIDE;
31 virtual void RemoveObserver(Observer* observer) OVERRIDE;
32 virtual void ReloadNigori() OVERRIDE;
33 virtual void UpdateFromNigori(
34 const sync_pb::NigoriSpecifics& nigori) OVERRIDE;
35 virtual ModelTypeSet GetEncryptedTypes() const OVERRIDE;
36 virtual void UpdateNigoriFromEncryptedTypes(
37 sync_pb::NigoriSpecifics* nigori) const OVERRIDE;
38 virtual void SetEncryptionPassphrase(const std::string& passphrase,
39 bool is_explicit) OVERRIDE;
40 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE;
41 virtual void EnableEncryptEverything() OVERRIDE;
42 virtual bool EncryptEverythingEnabled() const OVERRIDE;
43 virtual bool IsUsingExplicitPassphrase() const OVERRIDE;
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(SyncEncryptionHandlerImpl);
47 FRIEND_TEST_ALL_PREFIXES(SyncEncryptionHandlerImplTest,
48 NigoriEncryptionTypes);
49 FRIEND_TEST_ALL_PREFIXES(SyncEncryptionHandlerImplTest,
50 EncryptEverythingExplicit);
51 FRIEND_TEST_ALL_PREFIXES(SyncEncryptionHandlerImplTest,
52 EncryptEverythingImplicit);
53 FRIEND_TEST_ALL_PREFIXES(SyncEncryptionHandlerImplTest,
54 UnknownSensitiveTypes);
55
56 // Iterate over all encrypted types ensuring each entry is properly encrypted.
57 void ReEncryptEverything(WriteTransaction* trans);
58
59 // Apply a nigori update. Updates internal and cryptographer state.
60 // Returns true on success, false if |nigori| was incompatible, and the
61 // nigori node must be corrected.
62 // Note: must be called from within a transaction.
63 bool ApplyNigoriUpdate(const sync_pb::NigoriSpecifics& nigori,
64 Cryptographer* cryptographer);
65
66 // Wrapper around WriteEncryptionStateToNigori that creates a new write
67 // transaction.
68 void RewriteNigori();
69
70 // Write the current encryption state into the nigori node. This includes
71 // the encrypted types/encrypt everything state, as well as the keybag/
72 // explicit passphrase state (if the cryptographer is ready).
73 void WriteEncryptionStateToNigori(WriteTransaction* trans);
74
75 // Updates local encrypted types from |nigori|.
76 // Returns true if the local set of encrypted types either matched or was
77 // a subset of that in |nigori|. Returns false if the local state already
78 // had stricter encryption than |nigori|, and the nigori node needs to be
79 // updated with the newer encryption state.
80 // Note: must be called from within a transaction.
81 bool UpdateEncryptedTypesFromNigori(const sync_pb::NigoriSpecifics& nigori);
82
83 // The final step of SetEncryptionPassphrase and SetDecryptionPassphrase that
84 // notifies observers of the result of the set passphrase operation, updates
85 // the nigori node, and does re-encryption.
86 // |success|: true if the operation was successful and false otherwise. If
87 // success == false, we send an OnPassphraseRequired notification.
88 // |bootstrap_token|: used to inform observers if the cryptographer's
89 // bootstrap token was updated.
90 // |is_explicit|: used to differentiate between a custom passphrase (true) and
91 // a GAIA passphrase that is implicitly used for encryption
92 // (false).
93 // |trans| and |nigori_node|: used to access data in the cryptographer.
94 void FinishSetPassphrase(bool success,
95 const std::string& bootstrap_token,
96 bool is_explicit,
97 WriteTransaction* trans,
98 WriteNode* nigori_node);
99
100 // Merges the given set of encrypted types with the existing set and emits a
101 // notification if necessary.
102 // Note: must be called from within a transaction.
103 void MergeEncryptedTypes(ModelTypeSet encrypted_types);
104
105 base::WeakPtrFactory<SyncEncryptionHandlerImpl> weak_ptr_factory_;
106
107 ObserverList<SyncEncryptionHandler::Observer> observers_;
108
109 // The current user share (for creating transactions).
110 UserShare* user_share_;
111
112 // TODO(zea): Remove this once NigoriChangeProcessor implements
113 // ChangeProcessor interface and we remove the UpdateFromNigori method.
114 Cryptographer* cryptographer_;
115
116 // The set of types that require encryption. This is accessed on all sync
117 // datatype threads when we write to a node, so we must hold a transaction
118 // whenever we touch/read it.
119 ModelTypeSet encrypted_types_;
120
121 // Sync encryption state. These are only modified and accessed from the sync
122 // thread.
123 bool encrypt_everything_;
124 bool explicit_passphrase_;
125
126 // The number of times we've automatically (i.e. not via SetPassphrase or
127 // conflict resolver) updated the nigori's encryption keys in this chrome
128 // instantiation.
129 int nigori_overwrite_count_;
130 };
131
132 } // namespace syncer
133
134 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_ENCRYPTION_HANDLER_IMPL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698