xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/login/lock_screen_controller.h" |
| 6 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 7 | #include "ash/login/ui/lock_screen.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 8 | #include "chromeos/cryptohome/system_salt_getter.h" |
| 9 | #include "chromeos/login/auth/user_context.h" |
| 10 | |
| 11 | namespace ash { |
| 12 | |
| 13 | LockScreenController::LockScreenController() = default; |
| 14 | |
| 15 | LockScreenController::~LockScreenController() = default; |
| 16 | |
| 17 | void LockScreenController::BindRequest(mojom::LockScreenRequest request) { |
| 18 | bindings_.AddBinding(this, std::move(request)); |
| 19 | } |
| 20 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 21 | void LockScreenController::SetClient(mojom::LockScreenClientPtr client) { |
| 22 | lock_screen_client_ = std::move(client); |
| 23 | } |
| 24 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 25 | void LockScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) { |
| 26 | ::ash::ShowLockScreen(); |
| 27 | std::move(on_shown).Run(true); |
| 28 | } |
| 29 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 30 | void LockScreenController::ShowErrorMessage(int32_t login_attempts, |
| 31 | const std::string& error_text, |
| 32 | const std::string& help_link_text, |
| 33 | int32_t help_topic_id) { |
| 34 | NOTIMPLEMENTED(); |
| 35 | } |
| 36 | |
| 37 | void LockScreenController::ClearErrors() { |
| 38 | NOTIMPLEMENTED(); |
| 39 | } |
| 40 | |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 41 | void LockScreenController::ShowUserPodCustomIcon( |
| 42 | const AccountId& account_id, |
| 43 | mojom::UserPodCustomIconOptionsPtr icon) { |
| 44 | NOTIMPLEMENTED(); |
| 45 | } |
| 46 | |
| 47 | void LockScreenController::HideUserPodCustomIcon(const AccountId& account_id) { |
| 48 | NOTIMPLEMENTED(); |
| 49 | } |
| 50 | |
| 51 | void LockScreenController::SetAuthType(const AccountId& account_id, |
| 52 | mojom::AuthType auth_type, |
| 53 | const base::string16& initial_value) { |
| 54 | NOTIMPLEMENTED(); |
| 55 | } |
| 56 | |
| 57 | void LockScreenController::LoadUsers(std::unique_ptr<base::ListValue> users, |
| 58 | bool show_guest) { |
| 59 | NOTIMPLEMENTED(); |
| 60 | } |
| 61 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 62 | void LockScreenController::AuthenticateUser( |
| 63 | const AccountId& account_id, |
| 64 | const std::string& password, |
| 65 | bool authenticated_by_pin, |
| 66 | mojom::LockScreenClient::AuthenticateUserCallback callback) { |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 67 | if (!lock_screen_client_) |
| 68 | return; |
| 69 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 70 | // We cannot execute auth requests directly via GetSystemSalt because it |
| 71 | // expects a base::Callback instance, but |callback| is a base::OnceCallback. |
| 72 | // Instead, we store |callback| on this object and invoke it locally once we |
| 73 | // have the system salt. |
| 74 | DCHECK(!pending_user_auth_) << "More than one concurrent auth attempt"; |
| 75 | pending_user_auth_ = base::BindOnce( |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 76 | &LockScreenController::DoAuthenticateUser, base::Unretained(this), |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 77 | account_id, password, authenticated_by_pin, std::move(callback)); |
| 78 | chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind( |
| 79 | &LockScreenController::OnGetSystemSalt, base::Unretained(this))); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void LockScreenController::AttemptUnlock(const AccountId& account_id) { |
| 83 | if (!lock_screen_client_) |
| 84 | return; |
| 85 | lock_screen_client_->AttemptUnlock(account_id); |
| 86 | } |
| 87 | |
| 88 | void LockScreenController::HardlockPod(const AccountId& account_id) { |
| 89 | if (!lock_screen_client_) |
| 90 | return; |
| 91 | lock_screen_client_->HardlockPod(account_id); |
| 92 | } |
| 93 | |
| 94 | void LockScreenController::RecordClickOnLockIcon(const AccountId& account_id) { |
| 95 | if (!lock_screen_client_) |
| 96 | return; |
| 97 | lock_screen_client_->RecordClickOnLockIcon(account_id); |
| 98 | } |
| 99 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 100 | void LockScreenController::DoAuthenticateUser( |
| 101 | const AccountId& account_id, |
| 102 | const std::string& password, |
| 103 | bool authenticated_by_pin, |
| 104 | mojom::LockScreenClient::AuthenticateUserCallback callback, |
| 105 | const std::string& system_salt) { |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 106 | // Hash password before sending through mojo. |
| 107 | // TODO(xiaoyinh): Pin is hashed differently by using a different salt and |
| 108 | // a different hash algorithm. Update this part in PinStorage. |
| 109 | chromeos::Key key(password); |
| 110 | key.Transform(chromeos::Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame^] | 111 | lock_screen_client_->AuthenticateUser( |
| 112 | account_id, key.GetSecret(), authenticated_by_pin, std::move(callback)); |
| 113 | } |
| 114 | |
| 115 | void LockScreenController::OnGetSystemSalt(const std::string& system_salt) { |
| 116 | std::move(pending_user_auth_).Run(system_salt); |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | } // namespace ash |