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

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: 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 // Stores the current set of encryption keys (if the cryptographer is ready)
71 // and encrypted types into the nigori node.
72 void WriteEncryptionStateToNigori(WriteTransaction* trans);
73
74 // Updates local encryption state from |nigori|.
75 // Returns true if the local set of encrypted types either matched or was
76 // a subset of that in |nigori|. Returns false if the local state already
77 // had stricter encryption than |nigori|, and the nigori node needs to be
78 // updated with the newer encryption state.
79 // Note: must be called from within a transaction.
80 bool UpdateEncryptedTypesFromNigori(const sync_pb::NigoriSpecifics& nigori);
81
82 // The final step of SetEncryptionPassphrase and SetDecryptionPassphrase that
83 // notifies observers of the result of the set passphrase operation, updates
84 // the nigori node, and does re-encryption.
85 // |success|: true if the operation was successful and false otherwise. If
86 // success == false, we send an OnPassphraseRequired notification.
87 // |bootstrap_token|: used to inform observers if the cryptographer's
88 // bootstrap token was updated.
89 // |is_explicit|: used to differentiate between a custom passphrase (true) and
90 // a GAIA passphrase that is implicitly used for encryption
91 // (false).
92 // |trans| and |nigori_node|: used to access data in the cryptographer.
93 void FinishSetPassphrase(bool success,
94 const std::string& bootstrap_token,
95 bool is_explicit,
96 WriteTransaction* trans,
97 WriteNode* nigori_node);
98
99 // Merges the given set of encrypted types with the existing set and emits a
100 // notification if necessary.
101 // Note: must be called from within a transaction.
102 void MergeEncryptedTypes(ModelTypeSet encrypted_types);
103
104 // Unsafe implementations of public methods (do not open transactions).
105 ModelTypeSet EnableEncryptEverythingUnsafe();
106
107 base::WeakPtrFactory<SyncEncryptionHandlerImpl> weak_ptr_factory_;
108
109 ObserverList<SyncEncryptionHandler::Observer> observers_;
110
111 // The current user share (for creating transactions).
112 UserShare* user_share_;
113
114 // TODO(zea): Remove this once NigoriChangeProcessor implements
115 // ChangeProcessor interface and we remove the UpdateFromNigori method.
116 Cryptographer* cryptographer_;
117
118 // The set of types that require encryption. This is accessed on all sync
119 // datatype threads when we write to a node, so we must hold a transaction
120 // whenever we touch/read it.
121 ModelTypeSet encrypted_types_;
122
123 // Sync encryption state. These are only modified and accessed from the sync
124 // thread.
125 bool encrypt_everything_;
126 bool explicit_passphrase_;
127
128 // The number of times we've automatically (i.e. not via SetPassphrase or
129 // conflict resolver) updated the nigori's encryption keys in this chrome
130 // instantiation.
131 int nigori_overwrite_count_;
132 };
133
134 } // namespace syncer
135
136 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_ENCRYPTION_HANDLER_IMPL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698