Commit 1b434839 authored by Maajid's avatar Maajid Committed by Commit Bot

Remove RenameCryptohome from HomedirMethods.

Bug: 741274
Change-Id: Ib6a62720c7f3e89a7d480a63c4bc4a470d75aed9
Reviewed-on: https://chromium-review.googlesource.com/861368
Commit-Queue: Maajid <maajid@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530423}
parent a5ae4fab
...@@ -90,7 +90,7 @@ bool PreSigninPolicyFetcher::ForceTimeoutForTesting() { ...@@ -90,7 +90,7 @@ bool PreSigninPolicyFetcher::ForceTimeoutForTesting() {
void PreSigninPolicyFetcher::OnMountTemporaryUserHome( void PreSigninPolicyFetcher::OnMountTemporaryUserHome(
base::Optional<cryptohome::BaseReply> reply) { base::Optional<cryptohome::BaseReply> reply) {
if (BaseReplyToMountError(reply) != cryptohome::MOUNT_ERROR_NONE) { if (MountExReplyToMountError(reply) != cryptohome::MOUNT_ERROR_NONE) {
LOG(ERROR) << "Temporary user home mount failed."; LOG(ERROR) << "Temporary user home mount failed.";
NotifyCallback(PolicyFetchResult::ERROR, nullptr); NotifyCallback(PolicyFetchResult::ERROR, nullptr);
return; return;
......
...@@ -581,11 +581,13 @@ void EncryptionMigrationScreenHandler::StartMigration() { ...@@ -581,11 +581,13 @@ void EncryptionMigrationScreenHandler::StartMigration() {
void EncryptionMigrationScreenHandler::OnMountExistingVault( void EncryptionMigrationScreenHandler::OnMountExistingVault(
base::Optional<cryptohome::BaseReply> reply) { base::Optional<cryptohome::BaseReply> reply) {
if (cryptohome::BaseReplyToMountError(reply) != cryptohome::MountError return_code =
cryptohome::MOUNT_ERROR_NONE) { cryptohome::MountExReplyToMountError(reply);
if (return_code != cryptohome::MOUNT_ERROR_NONE) {
RecordMigrationResultMountFailure(IsResumingIncompleteMigration(), RecordMigrationResultMountFailure(IsResumingIncompleteMigration(),
IsArcKiosk()); IsArcKiosk());
UpdateUIState(UIState::MIGRATION_FAILED); UpdateUIState(UIState::MIGRATION_FAILED);
LOG(ERROR) << "Mount existing vault failed. Error: " << return_code;
return; return;
} }
......
...@@ -17,23 +17,37 @@ ...@@ -17,23 +17,37 @@
namespace cryptohome { namespace cryptohome {
MountError BaseReplyToMountError(const base::Optional<BaseReply>& reply) { namespace {
bool IsEmpty(const base::Optional<BaseReply>& reply) {
if (!reply.has_value()) { if (!reply.has_value()) {
LOGIN_LOG(ERROR) << "MountEx failed with no reply."; LOGIN_LOG(ERROR) << "Cryptohome call failed with empty reply.";
return MOUNT_ERROR_FATAL; return true;
} }
return false;
}
} // namespace
MountError MountExReplyToMountError(const base::Optional<BaseReply>& reply) {
if (IsEmpty(reply))
return MOUNT_ERROR_FATAL;
if (!reply->HasExtension(MountReply::reply)) { if (!reply->HasExtension(MountReply::reply)) {
LOGIN_LOG(ERROR) << "MountEx failed with no MountReply extension in reply."; LOGIN_LOG(ERROR) << "MountEx failed with no MountReply extension in reply.";
return MOUNT_ERROR_FATAL; return MOUNT_ERROR_FATAL;
} }
if (reply->has_error() && reply->error() != CRYPTOHOME_ERROR_NOT_SET) {
LOGIN_LOG(ERROR) << "MountEx failed (CryptohomeErrorCode): "
<< reply->error();
}
return CryptohomeErrorToMountError(reply->error()); return CryptohomeErrorToMountError(reply->error());
} }
const std::string& BaseReplyToMountHash(const BaseReply& reply) { MountError BaseReplyToMountError(const base::Optional<BaseReply>& reply) {
if (IsEmpty(reply))
return MOUNT_ERROR_FATAL;
return CryptohomeErrorToMountError(reply->error());
}
const std::string& MountExReplyToMountHash(const BaseReply& reply) {
return reply.GetExtension(MountReply::reply).sanitized_username(); return reply.GetExtension(MountReply::reply).sanitized_username();
} }
......
...@@ -21,11 +21,17 @@ namespace cryptohome { ...@@ -21,11 +21,17 @@ namespace cryptohome {
CHROMEOS_EXPORT MountError CHROMEOS_EXPORT MountError
BaseReplyToMountError(const base::Optional<BaseReply>& reply); BaseReplyToMountError(const base::Optional<BaseReply>& reply);
// Returns a MountError code from the MountEx |reply| returning
// MOUNT_ERROR_NONE if the reply is well-formed and there is no error.
CHROMEOS_EXPORT MountError
MountExReplyToMountError(const base::Optional<BaseReply>& reply);
// Extracts the mount hash from |reply|. // Extracts the mount hash from |reply|.
// This method assumes |reply| is well-formed. To check if a reply // This method assumes |reply| is well-formed. To check if a reply
// is well-formed, callers can check if BaseReplyToMountError returns // is well-formed, callers can check if BaseReplyToMountError returns
// MOUNT_ERROR_NONE. // MOUNT_ERROR_NONE.
CHROMEOS_EXPORT const std::string& BaseReplyToMountHash(const BaseReply& reply); CHROMEOS_EXPORT const std::string& MountExReplyToMountHash(
const BaseReply& reply);
// Creates an AuthorizationRequest from the given secret and label. // Creates an AuthorizationRequest from the given secret and label.
CHROMEOS_EXPORT AuthorizationRequest CHROMEOS_EXPORT AuthorizationRequest
......
...@@ -82,15 +82,6 @@ class HomedirMethodsImpl : public HomedirMethods { ...@@ -82,15 +82,6 @@ class HomedirMethodsImpl : public HomedirMethods {
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), callback));
} }
void RenameCryptohome(const Identification& id_from,
const Identification& id_to,
const Callback& callback) override {
DBusThreadManager::Get()->GetCryptohomeClient()->RenameCryptohome(
id_from, id_to,
base::BindOnce(&HomedirMethodsImpl::OnBaseReplyCallback,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void GetAccountDiskUsage( void GetAccountDiskUsage(
const Identification& id, const Identification& id,
const GetAccountDiskUsageCallback& callback) override { const GetAccountDiskUsageCallback& callback) override {
......
...@@ -77,12 +77,6 @@ class CHROMEOS_EXPORT HomedirMethods { ...@@ -77,12 +77,6 @@ class CHROMEOS_EXPORT HomedirMethods {
const RemoveKeyRequest& request, const RemoveKeyRequest& request,
const Callback& callback) = 0; const Callback& callback) = 0;
// Asks cryptohomed to change cryptohome identification |id_from| to |id_to|,
// which results in cryptohome directory renaming.
virtual void RenameCryptohome(const Identification& id_from,
const Identification& id_to,
const Callback& callback) = 0;
// Asks cryptohomed to compute the size of cryptohome for user identified by // Asks cryptohomed to compute the size of cryptohome for user identified by
// |id|. // |id|.
virtual void GetAccountDiskUsage( virtual void GetAccountDiskUsage(
......
...@@ -47,10 +47,6 @@ class CHROMEOS_EXPORT MockHomedirMethods : public HomedirMethods { ...@@ -47,10 +47,6 @@ class CHROMEOS_EXPORT MockHomedirMethods : public HomedirMethods {
const AuthorizationRequest& auth, const AuthorizationRequest& auth,
const UpdateKeyRequest& request, const UpdateKeyRequest& request,
const Callback& callback)); const Callback& callback));
MOCK_METHOD3(RenameCryptohome,
void(const Identification& id_from,
const Identification& id_to,
const Callback& callback));
MOCK_METHOD2(GetAccountDiskUsage, MOCK_METHOD2(GetAccountDiskUsage,
void(const Identification& id, void(const Identification& id,
const GetAccountDiskUsageCallback& callback)); const GetAccountDiskUsageCallback& callback));
......
...@@ -141,11 +141,13 @@ void OnMount(const base::WeakPtr<AuthAttemptState>& attempt, ...@@ -141,11 +141,13 @@ void OnMount(const base::WeakPtr<AuthAttemptState>& attempt,
chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker(
public_mount ? "CryptohomeMountPublic-End" : "CryptohomeMount-End", public_mount ? "CryptohomeMountPublic-End" : "CryptohomeMount-End",
false); false);
attempt->RecordCryptohomeStatus(BaseReplyToMountError(reply)); attempt->RecordCryptohomeStatus(MountExReplyToMountError(reply));
if (attempt->cryptohome_code() == cryptohome::MOUNT_ERROR_NONE) if (attempt->cryptohome_code() == cryptohome::MOUNT_ERROR_NONE) {
attempt->RecordUsernameHash(BaseReplyToMountHash(reply.value())); attempt->RecordUsernameHash(MountExReplyToMountHash(reply.value()));
else } else {
LOGIN_LOG(ERROR) << "MountEx failed. Error: " << attempt->cryptohome_code();
attempt->RecordUsernameHashFailed(); attempt->RecordUsernameHashFailed();
}
resolver->Resolve(); resolver->Resolve();
} }
...@@ -187,7 +189,7 @@ void DoMount(const base::WeakPtr<AuthAttemptState>& attempt, ...@@ -187,7 +189,7 @@ void DoMount(const base::WeakPtr<AuthAttemptState>& attempt,
auth_key->set_secret(key->GetSecret()); auth_key->set_secret(key->GetSecret());
DBusThreadManager::Get()->GetCryptohomeClient()->MountEx( DBusThreadManager::Get()->GetCryptohomeClient()->MountEx(
cryptohome::Identification(attempt->user_context.GetAccountId()), auth, cryptohome::Identification(attempt->user_context.GetAccountId()), auth,
mount, base::Bind(&OnMount, attempt, resolver)); mount, base::BindOnce(&OnMount, attempt, resolver));
} }
// Handle cryptohome migration status. // Handle cryptohome migration status.
...@@ -195,12 +197,12 @@ void OnCryptohomeRenamed(const base::WeakPtr<AuthAttemptState>& attempt, ...@@ -195,12 +197,12 @@ void OnCryptohomeRenamed(const base::WeakPtr<AuthAttemptState>& attempt,
scoped_refptr<CryptohomeAuthenticator> resolver, scoped_refptr<CryptohomeAuthenticator> resolver,
bool ephemeral, bool ephemeral,
bool create_if_nonexistent, bool create_if_nonexistent,
bool success, base::Optional<cryptohome::BaseReply> reply) {
cryptohome::MountError return_code) { cryptohome::MountError return_code = cryptohome::BaseReplyToMountError(reply);
chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker(
"CryptohomeRename-End", false); "CryptohomeRename-End", false);
const AccountId account_id = attempt->user_context.GetAccountId(); const AccountId account_id = attempt->user_context.GetAccountId();
if (success) { if (return_code == cryptohome::MOUNT_ERROR_NONE) {
cryptohome::SetGaiaIdMigrationStatusDone(account_id); cryptohome::SetGaiaIdMigrationStatusDone(account_id);
UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::SUCCESS); UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::SUCCESS);
} else { } else {
...@@ -255,11 +257,11 @@ void EnsureCryptohomeMigratedToGaiaId( ...@@ -255,11 +257,11 @@ void EnsureCryptohomeMigratedToGaiaId(
const std::string cryptohome_id_to = const std::string cryptohome_id_to =
attempt->user_context.GetAccountId().GetAccountIdKey(); attempt->user_context.GetAccountId().GetAccountIdKey();
cryptohome::HomedirMethods::GetInstance()->RenameCryptohome( DBusThreadManager::Get()->GetCryptohomeClient()->RenameCryptohome(
cryptohome::Identification::FromString(cryptohome_id_from), cryptohome::Identification::FromString(cryptohome_id_from),
cryptohome::Identification::FromString(cryptohome_id_to), cryptohome::Identification::FromString(cryptohome_id_to),
base::Bind(&OnCryptohomeRenamed, attempt, resolver, ephemeral, base::BindOnce(&OnCryptohomeRenamed, attempt, resolver, ephemeral,
create_if_nonexistent)); create_if_nonexistent));
return; return;
} }
if (!already_migrated && has_account_key) { if (!already_migrated && has_account_key) {
...@@ -434,7 +436,7 @@ void MountPublic(const base::WeakPtr<AuthAttemptState>& attempt, ...@@ -434,7 +436,7 @@ void MountPublic(const base::WeakPtr<AuthAttemptState>& attempt,
DBusThreadManager::Get()->GetCryptohomeClient()->MountEx( DBusThreadManager::Get()->GetCryptohomeClient()->MountEx(
cryptohome::Identification(attempt->user_context.GetAccountId()), cryptohome::Identification(attempt->user_context.GetAccountId()),
cryptohome::AuthorizationRequest(), mount, cryptohome::AuthorizationRequest(), mount,
base::Bind(&OnMount, attempt, resolver)); base::BindOnce(&OnMount, attempt, resolver));
} }
// Calls cryptohome's key migration method. // Calls cryptohome's key migration method.
......
...@@ -266,11 +266,12 @@ void ExtendedAuthenticatorImpl::OnMountComplete( ...@@ -266,11 +266,12 @@ void ExtendedAuthenticatorImpl::OnMountComplete(
const UserContext& user_context, const UserContext& user_context,
const ResultCallback& success_callback, const ResultCallback& success_callback,
base::Optional<cryptohome::BaseReply> reply) { base::Optional<cryptohome::BaseReply> reply) {
cryptohome::MountError return_code = cryptohome::BaseReplyToMountError(reply); cryptohome::MountError return_code =
cryptohome::MountExReplyToMountError(reply);
RecordEndMarker(time_marker); RecordEndMarker(time_marker);
if (return_code == cryptohome::MOUNT_ERROR_NONE) { if (return_code == cryptohome::MOUNT_ERROR_NONE) {
const std::string& mount_hash = const std::string& mount_hash =
cryptohome::BaseReplyToMountHash(reply.value()); cryptohome::MountExReplyToMountHash(reply.value());
if (!success_callback.is_null()) if (!success_callback.is_null())
success_callback.Run(mount_hash); success_callback.Run(mount_hash);
if (old_consumer_) { if (old_consumer_) {
...@@ -280,6 +281,7 @@ void ExtendedAuthenticatorImpl::OnMountComplete( ...@@ -280,6 +281,7 @@ void ExtendedAuthenticatorImpl::OnMountComplete(
} }
return; return;
} }
LOG(ERROR) << "MountEx failed. Error: " << return_code;
AuthState state = FAILED_MOUNT; AuthState state = FAILED_MOUNT;
if (return_code == cryptohome::MOUNT_ERROR_TPM_COMM_ERROR || if (return_code == cryptohome::MOUNT_ERROR_TPM_COMM_ERROR ||
return_code == cryptohome::MOUNT_ERROR_TPM_DEFEND_LOCK || return_code == cryptohome::MOUNT_ERROR_TPM_DEFEND_LOCK ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment