[go: nahoru, domu]

blob: dd5a085137f85410548b25f88c0e35d11f0e53c1 [file] [log] [blame]
xiaoyinh2bbdd102017-05-18 23:29:421// 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
jdufaulteb4c9f1e2017-06-08 23:08:307#include "ash/login/ui/lock_screen.h"
xiaoyinh2bbdd102017-05-18 23:29:428#include "chromeos/cryptohome/system_salt_getter.h"
9#include "chromeos/login/auth/user_context.h"
10
11namespace ash {
12
13LockScreenController::LockScreenController() = default;
14
15LockScreenController::~LockScreenController() = default;
16
17void LockScreenController::BindRequest(mojom::LockScreenRequest request) {
18 bindings_.AddBinding(this, std::move(request));
19}
20
xiaoyinh2bbdd102017-05-18 23:29:4221void LockScreenController::SetClient(mojom::LockScreenClientPtr client) {
22 lock_screen_client_ = std::move(client);
23}
24
jdufaulteb4c9f1e2017-06-08 23:08:3025void LockScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) {
26 ::ash::ShowLockScreen();
27 std::move(on_shown).Run(true);
28}
29
xiaoyinh2bbdd102017-05-18 23:29:4230void 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
37void LockScreenController::ClearErrors() {
38 NOTIMPLEMENTED();
39}
40
xiaoyinh9f6fa0e2017-06-07 19:22:3241void LockScreenController::ShowUserPodCustomIcon(
42 const AccountId& account_id,
43 mojom::UserPodCustomIconOptionsPtr icon) {
44 NOTIMPLEMENTED();
45}
46
47void LockScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
48 NOTIMPLEMENTED();
49}
50
51void LockScreenController::SetAuthType(const AccountId& account_id,
52 mojom::AuthType auth_type,
53 const base::string16& initial_value) {
54 NOTIMPLEMENTED();
55}
56
57void LockScreenController::LoadUsers(std::unique_ptr<base::ListValue> users,
58 bool show_guest) {
59 NOTIMPLEMENTED();
60}
61
jdufaulteb4c9f1e2017-06-08 23:08:3062void LockScreenController::AuthenticateUser(
63 const AccountId& account_id,
64 const std::string& password,
65 bool authenticated_by_pin,
66 mojom::LockScreenClient::AuthenticateUserCallback callback) {
xiaoyinh9f6fa0e2017-06-07 19:22:3267 if (!lock_screen_client_)
68 return;
69
jdufaulteb4c9f1e2017-06-08 23:08:3070 // 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(
xiaoyinh9f6fa0e2017-06-07 19:22:3276 &LockScreenController::DoAuthenticateUser, base::Unretained(this),
jdufaulteb4c9f1e2017-06-08 23:08:3077 account_id, password, authenticated_by_pin, std::move(callback));
78 chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind(
79 &LockScreenController::OnGetSystemSalt, base::Unretained(this)));
xiaoyinh9f6fa0e2017-06-07 19:22:3280}
81
82void LockScreenController::AttemptUnlock(const AccountId& account_id) {
83 if (!lock_screen_client_)
84 return;
85 lock_screen_client_->AttemptUnlock(account_id);
86}
87
88void LockScreenController::HardlockPod(const AccountId& account_id) {
89 if (!lock_screen_client_)
90 return;
91 lock_screen_client_->HardlockPod(account_id);
92}
93
94void LockScreenController::RecordClickOnLockIcon(const AccountId& account_id) {
95 if (!lock_screen_client_)
96 return;
97 lock_screen_client_->RecordClickOnLockIcon(account_id);
98}
99
jdufaulteb4c9f1e2017-06-08 23:08:30100void 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) {
xiaoyinh2bbdd102017-05-18 23:29:42106 // 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);
jdufaulteb4c9f1e2017-06-08 23:08:30111 lock_screen_client_->AuthenticateUser(
112 account_id, key.GetSecret(), authenticated_by_pin, std::move(callback));
113}
114
115void LockScreenController::OnGetSystemSalt(const std::string& system_salt) {
116 std::move(pending_user_auth_).Run(system_salt);
xiaoyinh2bbdd102017-05-18 23:29:42117}
118
119} // namespace ash