OLD | NEW |
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/internal_api/public/base_node.h" | 5 #include "sync/internal_api/public/base_node.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "sync/internal_api/public/base_transaction.h" | 11 #include "sync/internal_api/public/base_transaction.h" |
12 #include "sync/internal_api/syncapi_internal.h" | 12 #include "sync/internal_api/syncapi_internal.h" |
13 #include "sync/protocol/app_specifics.pb.h" | 13 #include "sync/protocol/app_specifics.pb.h" |
14 #include "sync/protocol/autofill_specifics.pb.h" | 14 #include "sync/protocol/autofill_specifics.pb.h" |
15 #include "sync/protocol/bookmark_specifics.pb.h" | 15 #include "sync/protocol/bookmark_specifics.pb.h" |
16 #include "sync/protocol/extension_specifics.pb.h" | 16 #include "sync/protocol/extension_specifics.pb.h" |
17 #include "sync/protocol/nigori_specifics.pb.h" | 17 #include "sync/protocol/nigori_specifics.pb.h" |
18 #include "sync/protocol/password_specifics.pb.h" | 18 #include "sync/protocol/password_specifics.pb.h" |
19 #include "sync/protocol/session_specifics.pb.h" | 19 #include "sync/protocol/session_specifics.pb.h" |
20 #include "sync/protocol/theme_specifics.pb.h" | 20 #include "sync/protocol/theme_specifics.pb.h" |
21 #include "sync/protocol/typed_url_specifics.pb.h" | 21 #include "sync/protocol/typed_url_specifics.pb.h" |
22 #include "sync/syncable/directory.h" | 22 #include "sync/syncable/directory.h" |
23 #include "sync/syncable/entry.h" | 23 #include "sync/syncable/entry.h" |
| 24 #include "sync/syncable/syncable_base_transaction.h" |
24 #include "sync/syncable/syncable_id.h" | 25 #include "sync/syncable/syncable_id.h" |
25 #include "sync/util/time.h" | 26 #include "sync/util/time.h" |
26 | 27 |
27 using sync_pb::AutofillProfileSpecifics; | 28 using sync_pb::AutofillProfileSpecifics; |
28 | 29 |
29 namespace syncer { | 30 namespace syncer { |
30 | 31 |
31 using syncable::SPECIFICS; | 32 using syncable::SPECIFICS; |
32 | 33 |
33 // Helper function to look up the int64 metahandle of an object given the ID | 34 // Helper function to look up the int64 metahandle of an object given the ID |
(...skipping 15 matching lines...) Expand all Loading... |
49 bool BaseNode::DecryptIfNecessary() { | 50 bool BaseNode::DecryptIfNecessary() { |
50 if (!GetEntry()->GetUniqueServerTag().empty()) | 51 if (!GetEntry()->GetUniqueServerTag().empty()) |
51 return true; // Ignore unique folders. | 52 return true; // Ignore unique folders. |
52 const sync_pb::EntitySpecifics& specifics = | 53 const sync_pb::EntitySpecifics& specifics = |
53 GetEntry()->GetSpecifics(); | 54 GetEntry()->GetSpecifics(); |
54 if (specifics.has_password()) { | 55 if (specifics.has_password()) { |
55 // Passwords have their own legacy encryption structure. | 56 // Passwords have their own legacy encryption structure. |
56 scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics( | 57 scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics( |
57 specifics, GetTransaction()->GetCryptographer())); | 58 specifics, GetTransaction()->GetCryptographer())); |
58 if (!data) { | 59 if (!data) { |
59 LOG(ERROR) << "Failed to decrypt password specifics."; | 60 GetTransaction()->GetWrappedTrans()->OnUnrecoverableError( |
| 61 FROM_HERE, std::string("Failed to decrypt encrypted node of type ") + |
| 62 ModelTypeToString(GetModelType())); |
60 return false; | 63 return false; |
61 } | 64 } |
62 password_data_.swap(data); | 65 password_data_.swap(data); |
63 return true; | 66 return true; |
64 } | 67 } |
65 | 68 |
66 // We assume any node with the encrypted field set has encrypted data and if | 69 // We assume any node with the encrypted field set has encrypted data and if |
67 // not we have no work to do, with the exception of bookmarks. For bookmarks | 70 // not we have no work to do, with the exception of bookmarks. For bookmarks |
68 // we must make sure the bookmarks data has the title field supplied. If not, | 71 // we must make sure the bookmarks data has the title field supplied. If not, |
69 // we fill the unencrypted_data_ with a copy of the bookmark specifics that | 72 // we fill the unencrypted_data_ with a copy of the bookmark specifics that |
(...skipping 12 matching lines...) Expand all Loading... |
82 unencrypted_data_.mutable_bookmark()->set_title( | 85 unencrypted_data_.mutable_bookmark()->set_title( |
83 server_legal_title); | 86 server_legal_title); |
84 } | 87 } |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 const sync_pb::EncryptedData& encrypted = specifics.encrypted(); | 91 const sync_pb::EncryptedData& encrypted = specifics.encrypted(); |
89 std::string plaintext_data = GetTransaction()->GetCryptographer()-> | 92 std::string plaintext_data = GetTransaction()->GetCryptographer()-> |
90 DecryptToString(encrypted); | 93 DecryptToString(encrypted); |
91 if (plaintext_data.length() == 0) { | 94 if (plaintext_data.length() == 0) { |
92 LOG(ERROR) << "Failed to decrypt encrypted node of type " | 95 GetTransaction()->GetWrappedTrans()->OnUnrecoverableError( |
93 << ModelTypeToString(GetModelType()) << "."; | 96 FROM_HERE, std::string("Failed to decrypt encrypted node of type ") + |
94 // Debugging for crbug.com/123223. We failed to decrypt the data, which | 97 ModelTypeToString(GetModelType())); |
95 // means we applied an update without having the key or lost the key at a | |
96 // later point. | |
97 CHECK(false); | |
98 return false; | 98 return false; |
99 } else if (!unencrypted_data_.ParseFromString(plaintext_data)) { | 99 } else if (!unencrypted_data_.ParseFromString(plaintext_data)) { |
100 // Debugging for crbug.com/123223. We should never succeed in decrypting | 100 GetTransaction()->GetWrappedTrans()->OnUnrecoverableError( |
101 // but fail to parse into a protobuf. | 101 FROM_HERE, std::string("Failed to parse encrypted node of type ") + |
102 CHECK(false); | 102 ModelTypeToString(GetModelType())); |
103 return false; | 103 return false; |
104 } | 104 } |
105 DVLOG(2) << "Decrypted specifics of type " | 105 DVLOG(2) << "Decrypted specifics of type " |
106 << ModelTypeToString(GetModelType()) | 106 << ModelTypeToString(GetModelType()) |
107 << " with content: " << plaintext_data; | 107 << " with content: " << plaintext_data; |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 const sync_pb::EntitySpecifics& BaseNode::GetUnencryptedSpecifics( | 111 const sync_pb::EntitySpecifics& BaseNode::GetUnencryptedSpecifics( |
112 const syncable::Entry* entry) const { | 112 const syncable::Entry* entry) const { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 const sync_pb::EntitySpecifics& specifics) { | 306 const sync_pb::EntitySpecifics& specifics) { |
307 ModelType type = GetModelTypeFromSpecifics(specifics); | 307 ModelType type = GetModelTypeFromSpecifics(specifics); |
308 DCHECK_NE(UNSPECIFIED, type); | 308 DCHECK_NE(UNSPECIFIED, type); |
309 if (GetModelType() != UNSPECIFIED) { | 309 if (GetModelType() != UNSPECIFIED) { |
310 DCHECK_EQ(GetModelType(), type); | 310 DCHECK_EQ(GetModelType(), type); |
311 } | 311 } |
312 unencrypted_data_.CopyFrom(specifics); | 312 unencrypted_data_.CopyFrom(specifics); |
313 } | 313 } |
314 | 314 |
315 } // namespace syncer | 315 } // namespace syncer |
OLD | NEW |