This source file includes following definitions.
- cryptographer_
- Init
- ApplyNigoriUpdate
- UpdateNigoriFromEncryptedTypes
- NeedKeystoreKey
- SetKeystoreKeys
- GetEncryptedTypes
- AddObserver
- RemoveObserver
- SetEncryptionPassphrase
- SetDecryptionPassphrase
- EnableEncryptEverything
- EncryptEverythingEnabled
- GetPassphraseType
#include "sync/test/fake_sync_encryption_handler.h"
#include "sync/protocol/nigori_specifics.pb.h"
#include "sync/syncable/nigori_util.h"
namespace syncer {
FakeSyncEncryptionHandler::FakeSyncEncryptionHandler()
: encrypted_types_(SensitiveTypes()),
encrypt_everything_(false),
passphrase_type_(IMPLICIT_PASSPHRASE),
cryptographer_(&encryptor_) {
}
FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {}
void FakeSyncEncryptionHandler::Init() {
KeyParams keystore_params = {"localhost", "dummy", "keystore_key"};
cryptographer_.AddKey(keystore_params);
}
void FakeSyncEncryptionHandler::ApplyNigoriUpdate(
const sync_pb::NigoriSpecifics& nigori,
syncable::BaseTransaction* const trans) {
if (nigori.encrypt_everything())
EnableEncryptEverything();
if (nigori.keybag_is_frozen())
passphrase_type_ = CUSTOM_PASSPHRASE;
if (cryptographer_.CanDecrypt(nigori.encryption_keybag()))
cryptographer_.InstallKeys(nigori.encryption_keybag());
else if (nigori.has_encryption_keybag())
cryptographer_.SetPendingKeys(nigori.encryption_keybag());
if (cryptographer_.has_pending_keys()) {
DVLOG(1) << "OnPassPhraseRequired Sent";
sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys();
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
OnPassphraseRequired(REASON_DECRYPTION,
pending_keys));
} else if (!cryptographer_.is_ready()) {
DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
<< "ready";
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
OnPassphraseRequired(REASON_ENCRYPTION,
sync_pb::EncryptedData()));
}
}
void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes(
sync_pb::NigoriSpecifics* nigori,
syncable::BaseTransaction* const trans) const {
syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_,
encrypt_everything_,
nigori);
}
bool FakeSyncEncryptionHandler::NeedKeystoreKey(
syncable::BaseTransaction* const trans) const {
return keystore_key_.empty();
}
bool FakeSyncEncryptionHandler::SetKeystoreKeys(
const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys,
syncable::BaseTransaction* const trans) {
if (keys.size() == 0)
return false;
std::string new_key = keys.Get(keys.size()-1);
if (new_key.empty())
return false;
keystore_key_ = new_key;
DVLOG(1) << "Keystore bootstrap token updated.";
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
OnBootstrapTokenUpdated(keystore_key_,
KEYSTORE_BOOTSTRAP_TOKEN));
return true;
}
ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes(
syncable::BaseTransaction* const trans) const {
return encrypted_types_;
}
void FakeSyncEncryptionHandler::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void FakeSyncEncryptionHandler::SetEncryptionPassphrase(
const std::string& passphrase,
bool is_explicit) {
if (is_explicit)
passphrase_type_ = CUSTOM_PASSPHRASE;
}
void FakeSyncEncryptionHandler::SetDecryptionPassphrase(
const std::string& passphrase) {
}
void FakeSyncEncryptionHandler::EnableEncryptEverything() {
if (encrypt_everything_)
return;
encrypt_everything_ = true;
encrypted_types_ = ModelTypeSet::All();
FOR_EACH_OBSERVER(
Observer, observers_,
OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
}
bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const {
return encrypt_everything_;
}
PassphraseType FakeSyncEncryptionHandler::GetPassphraseType() const {
return passphrase_type_;
}
}