OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 | 130 |
131 // Keystore Bootstrap Token helper methods. | 131 // Keystore Bootstrap Token helper methods. |
132 // The bootstrap is a base64 encoded, encrypted, ListValue of keystore key | 132 // The bootstrap is a base64 encoded, encrypted, ListValue of keystore key |
133 // strings, with the current keystore key as the last value in the list. | 133 // strings, with the current keystore key as the last value in the list. |
134 std::string PackKeystoreBootstrapToken( | 134 std::string PackKeystoreBootstrapToken( |
135 const std::vector<std::string>& old_keystore_keys, | 135 const std::vector<std::string>& old_keystore_keys, |
136 const std::string& current_keystore_key, | 136 const std::string& current_keystore_key, |
137 Encryptor* encryptor) { | 137 Encryptor* encryptor) { |
138 if (current_keystore_key.empty()) | 138 if (current_keystore_key.empty()) |
139 return ""; | 139 return std::string(); |
140 | 140 |
141 base::ListValue keystore_key_values; | 141 base::ListValue keystore_key_values; |
142 for (size_t i = 0; i < old_keystore_keys.size(); ++i) | 142 for (size_t i = 0; i < old_keystore_keys.size(); ++i) |
143 keystore_key_values.AppendString(old_keystore_keys[i]); | 143 keystore_key_values.AppendString(old_keystore_keys[i]); |
144 keystore_key_values.AppendString(current_keystore_key); | 144 keystore_key_values.AppendString(current_keystore_key); |
145 | 145 |
146 // Update the bootstrap token. | 146 // Update the bootstrap token. |
147 // The bootstrap is a base64 encoded, encrypted, ListValue of keystore key | 147 // The bootstrap is a base64 encoded, encrypted, ListValue of keystore key |
148 // strings, with the current keystore key as the last value in the list. | 148 // strings, with the current keystore key as the last value in the list. |
149 std::string serialized_keystores; | 149 std::string serialized_keystores; |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 const std::string& passphrase, | 1105 const std::string& passphrase, |
1106 WriteTransaction* trans, | 1106 WriteTransaction* trans, |
1107 WriteNode* nigori_node) { | 1107 WriteNode* nigori_node) { |
1108 DCHECK(thread_checker_.CalledOnValidThread()); | 1108 DCHECK(thread_checker_.CalledOnValidThread()); |
1109 DCHECK(IsNigoriMigratedToKeystore(nigori_node->GetNigoriSpecifics())); | 1109 DCHECK(IsNigoriMigratedToKeystore(nigori_node->GetNigoriSpecifics())); |
1110 KeyParams key_params = {"localhost", "dummy", passphrase}; | 1110 KeyParams key_params = {"localhost", "dummy", passphrase}; |
1111 | 1111 |
1112 if (passphrase_type_ != KEYSTORE_PASSPHRASE) { | 1112 if (passphrase_type_ != KEYSTORE_PASSPHRASE) { |
1113 DVLOG(1) << "Failing to set a custom passphrase because one has already " | 1113 DVLOG(1) << "Failing to set a custom passphrase because one has already " |
1114 << "been set."; | 1114 << "been set."; |
1115 FinishSetPassphrase(false, "", trans, nigori_node); | 1115 FinishSetPassphrase(false, std::string(), trans, nigori_node); |
1116 return; | 1116 return; |
1117 } | 1117 } |
1118 | 1118 |
1119 Cryptographer* cryptographer = | 1119 Cryptographer* cryptographer = |
1120 &UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer; | 1120 &UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer; |
1121 if (cryptographer->has_pending_keys()) { | 1121 if (cryptographer->has_pending_keys()) { |
1122 // This theoretically shouldn't happen, because the only way to have pending | 1122 // This theoretically shouldn't happen, because the only way to have pending |
1123 // keys after migrating to keystore support is if a custom passphrase was | 1123 // keys after migrating to keystore support is if a custom passphrase was |
1124 // set, which should update passpshrase_state_ and should be caught by the | 1124 // set, which should update passpshrase_state_ and should be caught by the |
1125 // if statement above. For the sake of safety though, we check for it in | 1125 // if statement above. For the sake of safety though, we check for it in |
1126 // case a client is misbehaving. | 1126 // case a client is misbehaving. |
1127 LOG(ERROR) << "Failing to set custom passphrase because of pending keys."; | 1127 LOG(ERROR) << "Failing to set custom passphrase because of pending keys."; |
1128 FinishSetPassphrase(false, "", trans, nigori_node); | 1128 FinishSetPassphrase(false, std::string(), trans, nigori_node); |
1129 return; | 1129 return; |
1130 } | 1130 } |
1131 | 1131 |
1132 std::string bootstrap_token; | 1132 std::string bootstrap_token; |
1133 if (cryptographer->AddKey(key_params)) { | 1133 if (cryptographer->AddKey(key_params)) { |
1134 DVLOG(1) << "Setting custom passphrase."; | 1134 DVLOG(1) << "Setting custom passphrase."; |
1135 cryptographer->GetBootstrapToken(&bootstrap_token); | 1135 cryptographer->GetBootstrapToken(&bootstrap_token); |
1136 passphrase_type_ = CUSTOM_PASSPHRASE; | 1136 passphrase_type_ = CUSTOM_PASSPHRASE; |
1137 custom_passphrase_time_ = base::Time::Now(); | 1137 custom_passphrase_time_ = base::Time::Now(); |
1138 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, | 1138 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 | 1645 |
1646 base::Time SyncEncryptionHandlerImpl::GetExplicitPassphraseTime() const { | 1646 base::Time SyncEncryptionHandlerImpl::GetExplicitPassphraseTime() const { |
1647 if (passphrase_type_ == FROZEN_IMPLICIT_PASSPHRASE) | 1647 if (passphrase_type_ == FROZEN_IMPLICIT_PASSPHRASE) |
1648 return migration_time(); | 1648 return migration_time(); |
1649 else if (passphrase_type_ == CUSTOM_PASSPHRASE) | 1649 else if (passphrase_type_ == CUSTOM_PASSPHRASE) |
1650 return custom_passphrase_time(); | 1650 return custom_passphrase_time(); |
1651 return base::Time(); | 1651 return base::Time(); |
1652 } | 1652 } |
1653 | 1653 |
1654 } // namespace browser_sync | 1654 } // namespace browser_sync |
OLD | NEW |