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/sync_encryption_handler_impl.h" | 5 #include "sync/internal_api/sync_encryption_handler_impl.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 case IMPLICIT_PASSPHRASE: | 90 case IMPLICIT_PASSPHRASE: |
91 return sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE; | 91 return sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE; |
92 case KEYSTORE_PASSPHRASE: | 92 case KEYSTORE_PASSPHRASE: |
93 return sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE; | 93 return sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE; |
94 case CUSTOM_PASSPHRASE: | 94 case CUSTOM_PASSPHRASE: |
95 return sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE; | 95 return sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE; |
96 case FROZEN_IMPLICIT_PASSPHRASE: | 96 case FROZEN_IMPLICIT_PASSPHRASE: |
97 return sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE; | 97 return sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE; |
98 default: | 98 default: |
99 NOTREACHED(); | 99 NOTREACHED(); |
100 return sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE;; | 100 return sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE; |
101 }; | 101 }; |
102 } | 102 } |
103 | 103 |
104 bool IsExplicitPassphrase(PassphraseType type) { | 104 bool IsExplicitPassphrase(PassphraseType type) { |
105 return type == CUSTOM_PASSPHRASE || type == FROZEN_IMPLICIT_PASSPHRASE; | 105 return type == CUSTOM_PASSPHRASE || type == FROZEN_IMPLICIT_PASSPHRASE; |
106 } | 106 } |
107 | 107 |
108 } // namespace | 108 } // namespace |
109 | 109 |
110 SyncEncryptionHandlerImpl::Vault::Vault( | 110 SyncEncryptionHandlerImpl::Vault::Vault( |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 } | 887 } |
888 } | 888 } |
889 | 889 |
890 bool SyncEncryptionHandlerImpl::UpdateEncryptedTypesFromNigori( | 890 bool SyncEncryptionHandlerImpl::UpdateEncryptedTypesFromNigori( |
891 const sync_pb::NigoriSpecifics& nigori, | 891 const sync_pb::NigoriSpecifics& nigori, |
892 syncable::BaseTransaction* const trans) { | 892 syncable::BaseTransaction* const trans) { |
893 DCHECK(thread_checker_.CalledOnValidThread()); | 893 DCHECK(thread_checker_.CalledOnValidThread()); |
894 ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; | 894 ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; |
895 if (nigori.encrypt_everything()) { | 895 if (nigori.encrypt_everything()) { |
896 EnableEncryptEverythingImpl(trans); | 896 EnableEncryptEverythingImpl(trans); |
897 DCHECK(encrypted_types->Equals(UserTypes())); | 897 DCHECK(encrypted_types->Equals(EncryptableUserTypes())); |
898 return true; | 898 return true; |
899 } else if (encrypt_everything_) { | 899 } else if (encrypt_everything_) { |
900 DCHECK(encrypted_types->Equals(UserTypes())); | 900 DCHECK(encrypted_types->Equals(EncryptableUserTypes())); |
901 return false; | 901 return false; |
902 } | 902 } |
903 | 903 |
904 ModelTypeSet nigori_encrypted_types; | 904 ModelTypeSet nigori_encrypted_types; |
905 nigori_encrypted_types = syncable::GetEncryptedTypesFromNigori(nigori); | 905 nigori_encrypted_types = syncable::GetEncryptedTypesFromNigori(nigori); |
906 nigori_encrypted_types.PutAll(SensitiveTypes()); | 906 nigori_encrypted_types.PutAll(SensitiveTypes()); |
907 | 907 |
908 // If anything more than the sensitive types were encrypted, and | 908 // If anything more than the sensitive types were encrypted, and |
909 // encrypt_everything is not explicitly set to false, we assume it means | 909 // encrypt_everything is not explicitly set to false, we assume it means |
910 // a client intended to enable encrypt everything. | 910 // a client intended to enable encrypt everything. |
911 if (!nigori.has_encrypt_everything() && | 911 if (!nigori.has_encrypt_everything() && |
912 !Difference(nigori_encrypted_types, SensitiveTypes()).Empty()) { | 912 !Difference(nigori_encrypted_types, SensitiveTypes()).Empty()) { |
913 if (!encrypt_everything_) { | 913 if (!encrypt_everything_) { |
914 encrypt_everything_ = true; | 914 encrypt_everything_ = true; |
915 *encrypted_types = UserTypes(); | 915 *encrypted_types = EncryptableUserTypes(); |
916 FOR_EACH_OBSERVER( | 916 FOR_EACH_OBSERVER( |
917 Observer, observers_, | 917 Observer, observers_, |
918 OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); | 918 OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); |
919 } | 919 } |
920 DCHECK(encrypted_types->Equals(UserTypes())); | 920 DCHECK(encrypted_types->Equals(EncryptableUserTypes())); |
921 return false; | 921 return false; |
922 } | 922 } |
923 | 923 |
924 MergeEncryptedTypes(nigori_encrypted_types, trans); | 924 MergeEncryptedTypes(nigori_encrypted_types, trans); |
925 return encrypted_types->Equals(nigori_encrypted_types); | 925 return encrypted_types->Equals(nigori_encrypted_types); |
926 } | 926 } |
927 | 927 |
928 void SyncEncryptionHandlerImpl::SetCustomPassphrase( | 928 void SyncEncryptionHandlerImpl::SetCustomPassphrase( |
929 const std::string& passphrase, | 929 const std::string& passphrase, |
930 WriteTransaction* trans, | 930 WriteTransaction* trans, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 // redundant. Figure out a way to not do this unnecessarily. | 1087 // redundant. Figure out a way to not do this unnecessarily. |
1088 ReEncryptEverything(trans); | 1088 ReEncryptEverything(trans); |
1089 } | 1089 } |
1090 | 1090 |
1091 void SyncEncryptionHandlerImpl::MergeEncryptedTypes( | 1091 void SyncEncryptionHandlerImpl::MergeEncryptedTypes( |
1092 ModelTypeSet new_encrypted_types, | 1092 ModelTypeSet new_encrypted_types, |
1093 syncable::BaseTransaction* const trans) { | 1093 syncable::BaseTransaction* const trans) { |
1094 DCHECK(thread_checker_.CalledOnValidThread()); | 1094 DCHECK(thread_checker_.CalledOnValidThread()); |
1095 | 1095 |
1096 // Only UserTypes may be encrypted. | 1096 // Only UserTypes may be encrypted. |
1097 DCHECK(UserTypes().HasAll(new_encrypted_types)); | 1097 DCHECK(EncryptableUserTypes().HasAll(new_encrypted_types)); |
1098 | 1098 |
1099 ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; | 1099 ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; |
1100 if (!encrypted_types->HasAll(new_encrypted_types)) { | 1100 if (!encrypted_types->HasAll(new_encrypted_types)) { |
1101 *encrypted_types = new_encrypted_types; | 1101 *encrypted_types = new_encrypted_types; |
1102 FOR_EACH_OBSERVER( | 1102 FOR_EACH_OBSERVER( |
1103 Observer, observers_, | 1103 Observer, observers_, |
1104 OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); | 1104 OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); |
1105 } | 1105 } |
1106 } | 1106 } |
1107 | 1107 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 cryptographer->InstallKeys(keybag); | 1282 cryptographer->InstallKeys(keybag); |
1283 if (update_default) | 1283 if (update_default) |
1284 cryptographer->SetDefaultKey(keybag.key_name()); | 1284 cryptographer->SetDefaultKey(keybag.key_name()); |
1285 return true; | 1285 return true; |
1286 } | 1286 } |
1287 | 1287 |
1288 void SyncEncryptionHandlerImpl::EnableEncryptEverythingImpl( | 1288 void SyncEncryptionHandlerImpl::EnableEncryptEverythingImpl( |
1289 syncable::BaseTransaction* const trans) { | 1289 syncable::BaseTransaction* const trans) { |
1290 ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; | 1290 ModelTypeSet* encrypted_types = &UnlockVaultMutable(trans)->encrypted_types; |
1291 if (encrypt_everything_) { | 1291 if (encrypt_everything_) { |
1292 DCHECK(encrypted_types->Equals(UserTypes())); | 1292 DCHECK(encrypted_types->Equals(EncryptableUserTypes())); |
1293 return; | 1293 return; |
1294 } | 1294 } |
1295 encrypt_everything_ = true; | 1295 encrypt_everything_ = true; |
1296 *encrypted_types = UserTypes(); | 1296 *encrypted_types = EncryptableUserTypes(); |
1297 FOR_EACH_OBSERVER( | 1297 FOR_EACH_OBSERVER( |
1298 Observer, observers_, | 1298 Observer, observers_, |
1299 OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); | 1299 OnEncryptedTypesChanged(*encrypted_types, encrypt_everything_)); |
1300 } | 1300 } |
1301 | 1301 |
1302 bool SyncEncryptionHandlerImpl::DecryptPendingKeysWithKeystoreKey( | 1302 bool SyncEncryptionHandlerImpl::DecryptPendingKeysWithKeystoreKey( |
1303 const std::string& keystore_key, | 1303 const std::string& keystore_key, |
1304 const sync_pb::EncryptedData& keystore_decryptor_token, | 1304 const sync_pb::EncryptedData& keystore_decryptor_token, |
1305 Cryptographer* cryptographer) { | 1305 Cryptographer* cryptographer) { |
1306 DCHECK(cryptographer->has_pending_keys()); | 1306 DCHECK(cryptographer->has_pending_keys()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 | 1348 |
1349 base::Time SyncEncryptionHandlerImpl::GetExplicitPassphraseTime() const { | 1349 base::Time SyncEncryptionHandlerImpl::GetExplicitPassphraseTime() const { |
1350 if (passphrase_type_ == FROZEN_IMPLICIT_PASSPHRASE) | 1350 if (passphrase_type_ == FROZEN_IMPLICIT_PASSPHRASE) |
1351 return migration_time(); | 1351 return migration_time(); |
1352 else if (passphrase_type_ == CUSTOM_PASSPHRASE) | 1352 else if (passphrase_type_ == CUSTOM_PASSPHRASE) |
1353 return custom_passphrase_time(); | 1353 return custom_passphrase_time(); |
1354 return base::Time(); | 1354 return base::Time(); |
1355 } | 1355 } |
1356 | 1356 |
1357 } // namespace browser_sync | 1357 } // namespace browser_sync |
OLD | NEW |