OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/login/lock_screen_controller.h" | 5 #include "ash/login/lock_screen_controller.h" |
6 | 6 |
| 7 #include "ash/login/ui/lock_screen.h" |
7 #include "chromeos/cryptohome/system_salt_getter.h" | 8 #include "chromeos/cryptohome/system_salt_getter.h" |
8 #include "chromeos/login/auth/user_context.h" | 9 #include "chromeos/login/auth/user_context.h" |
9 | 10 |
10 namespace ash { | 11 namespace ash { |
11 | 12 |
12 LockScreenController::LockScreenController() = default; | 13 LockScreenController::LockScreenController() = default; |
13 | 14 |
14 LockScreenController::~LockScreenController() = default; | 15 LockScreenController::~LockScreenController() = default; |
15 | 16 |
16 void LockScreenController::BindRequest(mojom::LockScreenRequest request) { | 17 void LockScreenController::BindRequest(mojom::LockScreenRequest request) { |
17 bindings_.AddBinding(this, std::move(request)); | 18 bindings_.AddBinding(this, std::move(request)); |
18 } | 19 } |
19 | 20 |
20 void LockScreenController::SetClient(mojom::LockScreenClientPtr client) { | 21 void LockScreenController::SetClient(mojom::LockScreenClientPtr client) { |
21 lock_screen_client_ = std::move(client); | 22 lock_screen_client_ = std::move(client); |
22 } | 23 } |
23 | 24 |
| 25 void LockScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) { |
| 26 ::ash::ShowLockScreen(); |
| 27 std::move(on_shown).Run(true); |
| 28 } |
| 29 |
24 void LockScreenController::ShowErrorMessage(int32_t login_attempts, | 30 void LockScreenController::ShowErrorMessage(int32_t login_attempts, |
25 const std::string& error_text, | 31 const std::string& error_text, |
26 const std::string& help_link_text, | 32 const std::string& help_link_text, |
27 int32_t help_topic_id) { | 33 int32_t help_topic_id) { |
28 NOTIMPLEMENTED(); | 34 NOTIMPLEMENTED(); |
29 } | 35 } |
30 | 36 |
31 void LockScreenController::ClearErrors() { | 37 void LockScreenController::ClearErrors() { |
32 NOTIMPLEMENTED(); | 38 NOTIMPLEMENTED(); |
33 } | 39 } |
(...skipping 12 matching lines...) Expand all Loading... |
46 mojom::AuthType auth_type, | 52 mojom::AuthType auth_type, |
47 const base::string16& initial_value) { | 53 const base::string16& initial_value) { |
48 NOTIMPLEMENTED(); | 54 NOTIMPLEMENTED(); |
49 } | 55 } |
50 | 56 |
51 void LockScreenController::LoadUsers(std::unique_ptr<base::ListValue> users, | 57 void LockScreenController::LoadUsers(std::unique_ptr<base::ListValue> users, |
52 bool show_guest) { | 58 bool show_guest) { |
53 NOTIMPLEMENTED(); | 59 NOTIMPLEMENTED(); |
54 } | 60 } |
55 | 61 |
56 void LockScreenController::AuthenticateUser(const AccountId& account_id, | 62 void LockScreenController::AuthenticateUser( |
57 const std::string& password, | 63 const AccountId& account_id, |
58 bool authenticated_by_pin) { | 64 const std::string& password, |
| 65 bool authenticated_by_pin, |
| 66 mojom::LockScreenClient::AuthenticateUserCallback callback) { |
59 if (!lock_screen_client_) | 67 if (!lock_screen_client_) |
60 return; | 68 return; |
61 | 69 |
| 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( |
| 76 &LockScreenController::DoAuthenticateUser, base::Unretained(this), |
| 77 account_id, password, authenticated_by_pin, std::move(callback)); |
62 chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind( | 78 chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind( |
63 &LockScreenController::DoAuthenticateUser, base::Unretained(this), | 79 &LockScreenController::OnGetSystemSalt, base::Unretained(this))); |
64 account_id, password, authenticated_by_pin)); | |
65 } | 80 } |
66 | 81 |
67 void LockScreenController::AttemptUnlock(const AccountId& account_id) { | 82 void LockScreenController::AttemptUnlock(const AccountId& account_id) { |
68 if (!lock_screen_client_) | 83 if (!lock_screen_client_) |
69 return; | 84 return; |
70 lock_screen_client_->AttemptUnlock(account_id); | 85 lock_screen_client_->AttemptUnlock(account_id); |
71 } | 86 } |
72 | 87 |
73 void LockScreenController::HardlockPod(const AccountId& account_id) { | 88 void LockScreenController::HardlockPod(const AccountId& account_id) { |
74 if (!lock_screen_client_) | 89 if (!lock_screen_client_) |
75 return; | 90 return; |
76 lock_screen_client_->HardlockPod(account_id); | 91 lock_screen_client_->HardlockPod(account_id); |
77 } | 92 } |
78 | 93 |
79 void LockScreenController::RecordClickOnLockIcon(const AccountId& account_id) { | 94 void LockScreenController::RecordClickOnLockIcon(const AccountId& account_id) { |
80 if (!lock_screen_client_) | 95 if (!lock_screen_client_) |
81 return; | 96 return; |
82 lock_screen_client_->RecordClickOnLockIcon(account_id); | 97 lock_screen_client_->RecordClickOnLockIcon(account_id); |
83 } | 98 } |
84 | 99 |
85 void LockScreenController::DoAuthenticateUser(const AccountId& account_id, | 100 void LockScreenController::DoAuthenticateUser( |
86 const std::string& password, | 101 const AccountId& account_id, |
87 bool authenticated_by_pin, | 102 const std::string& password, |
88 const std::string& system_salt) { | 103 bool authenticated_by_pin, |
| 104 mojom::LockScreenClient::AuthenticateUserCallback callback, |
| 105 const std::string& system_salt) { |
89 // Hash password before sending through mojo. | 106 // Hash password before sending through mojo. |
90 // TODO(xiaoyinh): Pin is hashed differently by using a different salt and | 107 // TODO(xiaoyinh): Pin is hashed differently by using a different salt and |
91 // a different hash algorithm. Update this part in PinStorage. | 108 // a different hash algorithm. Update this part in PinStorage. |
92 chromeos::Key key(password); | 109 chromeos::Key key(password); |
93 key.Transform(chromeos::Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); | 110 key.Transform(chromeos::Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); |
94 lock_screen_client_->AuthenticateUser(account_id, key.GetSecret(), | 111 lock_screen_client_->AuthenticateUser( |
95 authenticated_by_pin); | 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); |
96 } | 117 } |
97 | 118 |
98 } // namespace ash | 119 } // namespace ash |
OLD | NEW |