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 | |
| 7 | #include "chromeos/cryptohome/system_salt_getter.h" |
| 8 | #include "chromeos/login/auth/user_context.h" |
| 9 | |
| 10 | namespace ash { |
| 11 | |
| 12 | LockScreenController::LockScreenController() = default; |
| 13 | |
| 14 | LockScreenController::~LockScreenController() = default; |
| 15 | |
| 16 | void LockScreenController::BindRequest(mojom::LockScreenRequest request) { |
| 17 | bindings_.AddBinding(this, std::move(request)); |
| 18 | } |
| 19 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 20 | void LockScreenController::SetClient(mojom::LockScreenClientPtr client) { |
| 21 | lock_screen_client_ = std::move(client); |
| 22 | } |
| 23 | |
| 24 | void LockScreenController::ShowErrorMessage(int32_t login_attempts, |
| 25 | const std::string& error_text, |
| 26 | const std::string& help_link_text, |
| 27 | int32_t help_topic_id) { |
| 28 | NOTIMPLEMENTED(); |
| 29 | } |
| 30 | |
| 31 | void LockScreenController::ClearErrors() { |
| 32 | NOTIMPLEMENTED(); |
| 33 | } |
| 34 | |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame^] | 35 | void LockScreenController::ShowUserPodCustomIcon( |
| 36 | const AccountId& account_id, |
| 37 | mojom::UserPodCustomIconOptionsPtr icon) { |
| 38 | NOTIMPLEMENTED(); |
| 39 | } |
| 40 | |
| 41 | void LockScreenController::HideUserPodCustomIcon(const AccountId& account_id) { |
| 42 | NOTIMPLEMENTED(); |
| 43 | } |
| 44 | |
| 45 | void LockScreenController::SetAuthType(const AccountId& account_id, |
| 46 | mojom::AuthType auth_type, |
| 47 | const base::string16& initial_value) { |
| 48 | NOTIMPLEMENTED(); |
| 49 | } |
| 50 | |
| 51 | void LockScreenController::LoadUsers(std::unique_ptr<base::ListValue> users, |
| 52 | bool show_guest) { |
| 53 | NOTIMPLEMENTED(); |
| 54 | } |
| 55 | |
| 56 | void LockScreenController::AuthenticateUser(const AccountId& account_id, |
| 57 | const std::string& password, |
| 58 | bool authenticated_by_pin) { |
| 59 | if (!lock_screen_client_) |
| 60 | return; |
| 61 | |
| 62 | chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind( |
| 63 | &LockScreenController::DoAuthenticateUser, base::Unretained(this), |
| 64 | account_id, password, authenticated_by_pin)); |
| 65 | } |
| 66 | |
| 67 | void LockScreenController::AttemptUnlock(const AccountId& account_id) { |
| 68 | if (!lock_screen_client_) |
| 69 | return; |
| 70 | lock_screen_client_->AttemptUnlock(account_id); |
| 71 | } |
| 72 | |
| 73 | void LockScreenController::HardlockPod(const AccountId& account_id) { |
| 74 | if (!lock_screen_client_) |
| 75 | return; |
| 76 | lock_screen_client_->HardlockPod(account_id); |
| 77 | } |
| 78 | |
| 79 | void LockScreenController::RecordClickOnLockIcon(const AccountId& account_id) { |
| 80 | if (!lock_screen_client_) |
| 81 | return; |
| 82 | lock_screen_client_->RecordClickOnLockIcon(account_id); |
| 83 | } |
| 84 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 85 | void LockScreenController::DoAuthenticateUser(const AccountId& account_id, |
| 86 | const std::string& password, |
| 87 | bool authenticated_by_pin, |
| 88 | const std::string& system_salt) { |
| 89 | // Hash password before sending through mojo. |
| 90 | // TODO(xiaoyinh): Pin is hashed differently by using a different salt and |
| 91 | // a different hash algorithm. Update this part in PinStorage. |
| 92 | chromeos::Key key(password); |
| 93 | key.Transform(chromeos::Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); |
| 94 | lock_screen_client_->AuthenticateUser(account_id, key.GetSecret(), |
| 95 | authenticated_by_pin); |
| 96 | } |
| 97 | |
| 98 | } // namespace ash |