Commit 1339ec6a authored by fukino's avatar fukino Committed by Commit bot

cros: Remove user directory when encryption migration fails.

When the migration UI is notified by cryptohome that cryptohome gets unexpected
errors during migration and it gives up migration, we should remove the
user's cryptohome to make sure that the user will be able to log in to
the Desktop next time.

After the user's cryptohome is removed, we get password verification errors
on the existing user pod three times.
It seems an independent issue, so I filed crbug.com/715474 and will look into separately.

BUG=713556
TEST=manually tested by forcing cryptohome fail during migration and confirming the cryptohome is gone.

Review-Url: https://codereview.chromium.org/2838303003
Cr-Commit-Position: refs/heads/master@{#467608}
parent 5cdc120c
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/cryptohome/homedir_methods.h" #include "chromeos/cryptohome/homedir_methods.h"
#include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager/power_supply_properties.pb.h" #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
#include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_manager_client.h"
#include "components/login/localized_values_builder.h" #include "components/login/localized_values_builder.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "device/power_save_blocker/power_save_blocker.h" #include "device/power_save_blocker/power_save_blocker.h"
#include "ui/base/text/bytes_formatting.h" #include "ui/base/text/bytes_formatting.h"
...@@ -312,6 +314,26 @@ void EncryptionMigrationScreenHandler::StopBlockingPowerSave() { ...@@ -312,6 +314,26 @@ void EncryptionMigrationScreenHandler::StopBlockingPowerSave() {
} }
} }
void EncryptionMigrationScreenHandler::RemoveCryptohome() {
// Set invalid token status so that user is forced to go through Gaia on the
// next sign-in.
user_manager::UserManager::Get()->SaveUserOAuthStatus(
user_context_.GetAccountId(),
user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
cryptohome::Identification(user_context_.GetAccountId()),
base::Bind(&EncryptionMigrationScreenHandler::OnRemoveCryptohome,
weak_ptr_factory_.GetWeakPtr()));
}
void EncryptionMigrationScreenHandler::OnRemoveCryptohome(
bool success,
cryptohome::MountError return_code) {
LOG_IF(ERROR, !success) << "Removing cryptohome failed. return code: "
<< return_code;
UpdateUIState(UIState::MIGRATION_FAILED);
}
cryptohome::KeyDefinition EncryptionMigrationScreenHandler::GetAuthKey() { cryptohome::KeyDefinition EncryptionMigrationScreenHandler::GetAuthKey() {
// |auth_key| is created in the same manner as CryptohomeAuthenticator. // |auth_key| is created in the same manner as CryptohomeAuthenticator.
const Key* key = user_context_.GetKey(); const Key* key = user_context_.GetKey();
...@@ -344,12 +366,13 @@ void EncryptionMigrationScreenHandler::OnMigrationProgress( ...@@ -344,12 +366,13 @@ void EncryptionMigrationScreenHandler::OnMigrationProgress(
DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
break; break;
case cryptohome::DIRCRYPTO_MIGRATION_FAILED: case cryptohome::DIRCRYPTO_MIGRATION_FAILED:
UpdateUIState(UIState::MIGRATION_FAILED);
// Stop listening to the progress updates. // Stop listening to the progress updates.
DBusThreadManager::Get() DBusThreadManager::Get()
->GetCryptohomeClient() ->GetCryptohomeClient()
->SetDircryptoMigrationProgressHandler( ->SetDircryptoMigrationProgressHandler(
CryptohomeClient::DircryptoMigrationProgessHandler()); CryptohomeClient::DircryptoMigrationProgessHandler());
// Shows error screen after removing user directory is completed.
RemoveCryptohome();
break; break;
default: default:
break; break;
...@@ -357,12 +380,8 @@ void EncryptionMigrationScreenHandler::OnMigrationProgress( ...@@ -357,12 +380,8 @@ void EncryptionMigrationScreenHandler::OnMigrationProgress(
} }
void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) {
// This function is called when MigrateToDircrypto is correctly requested. LOG_IF(ERROR, !success) << "Requesting MigrateToDircrypto failed.";
// It does not mean that the migration is completed. We should know the UpdateUIState(UIState::MIGRATION_FAILED);
// completion by DircryptoMigrationProgressHandler. success == false means a
// failure in DBus communication.
// TODO(fukino): Handle this case. Should we retry or restart?
DCHECK(success);
} }
} // namespace chromeos } // namespace chromeos
...@@ -77,6 +77,9 @@ class EncryptionMigrationScreenHandler : public EncryptionMigrationScreenView, ...@@ -77,6 +77,9 @@ class EncryptionMigrationScreenHandler : public EncryptionMigrationScreenView,
const std::string& mount_hash); const std::string& mount_hash);
void StartBlockingPowerSave(); void StartBlockingPowerSave();
void StopBlockingPowerSave(); void StopBlockingPowerSave();
// Removes cryptohome and shows the error screen after the removal finishes.
void RemoveCryptohome();
void OnRemoveCryptohome(bool success, cryptohome::MountError return_code);
// Creates authorization key for MountEx method using |user_context_|. // Creates authorization key for MountEx method using |user_context_|.
cryptohome::KeyDefinition GetAuthKey(); cryptohome::KeyDefinition GetAuthKey();
......
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