OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_p rivate_api.h" | 5 #include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_p rivate_api.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h" | 7 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h" |
8 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h" | 8 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h" |
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
10 #include "chrome/common/pref_names.h" | |
10 #include "chromeos/login/auth/extended_authenticator.h" | 11 #include "chromeos/login/auth/extended_authenticator.h" |
11 #include "chromeos/login/auth/user_context.h" | 12 #include "chromeos/login/auth/user_context.h" |
13 #include "components/prefs/pref_service.h" | |
12 #include "extensions/browser/event_router.h" | 14 #include "extensions/browser/event_router.h" |
13 | 15 |
14 namespace extensions { | 16 namespace extensions { |
15 | 17 |
16 namespace quick_unlock_private = api::quick_unlock_private; | 18 namespace quick_unlock_private = api::quick_unlock_private; |
17 namespace SetModes = quick_unlock_private::SetModes; | 19 namespace SetModes = quick_unlock_private::SetModes; |
18 namespace GetActiveModes = quick_unlock_private::GetActiveModes; | 20 namespace GetActiveModes = quick_unlock_private::GetActiveModes; |
21 namespace GetUsablePin = quick_unlock_private::GetUsablePin; | |
19 namespace GetAvailableModes = quick_unlock_private::GetAvailableModes; | 22 namespace GetAvailableModes = quick_unlock_private::GetAvailableModes; |
20 namespace OnActiveModesChanged = quick_unlock_private::OnActiveModesChanged; | 23 namespace OnActiveModesChanged = quick_unlock_private::OnActiveModesChanged; |
24 using PinState = quick_unlock_private::PinState; | |
21 using QuickUnlockMode = quick_unlock_private::QuickUnlockMode; | 25 using QuickUnlockMode = quick_unlock_private::QuickUnlockMode; |
22 using QuickUnlockModeList = std::vector<QuickUnlockMode>; | 26 using QuickUnlockModeList = std::vector<QuickUnlockMode>; |
23 | 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 const char kModesAndCredentialsLengthMismatch[] = | 30 const char kModesAndCredentialsLengthMismatch[] = |
27 "|modes| and |credentials| must have the same number of elements"; | 31 "|modes| and |credentials| must have the same number of elements"; |
28 const char kMultipleModesNotSupported[] = | 32 const char kMultipleModesNotSupported[] = |
29 "At most one quick unlock mode can be active."; | 33 "At most one quick unlock mode can be active."; |
30 | 34 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 QuickUnlockPrivateGetActiveModesFunction:: | 90 QuickUnlockPrivateGetActiveModesFunction:: |
87 ~QuickUnlockPrivateGetActiveModesFunction() {} | 91 ~QuickUnlockPrivateGetActiveModesFunction() {} |
88 | 92 |
89 ExtensionFunction::ResponseAction | 93 ExtensionFunction::ResponseAction |
90 QuickUnlockPrivateGetActiveModesFunction::Run() { | 94 QuickUnlockPrivateGetActiveModesFunction::Run() { |
91 const QuickUnlockModeList modes = | 95 const QuickUnlockModeList modes = |
92 ComputeActiveModes(chrome_details_.GetProfile()); | 96 ComputeActiveModes(chrome_details_.GetProfile()); |
93 return RespondNow(ArgumentList(GetActiveModes::Results::Create(modes))); | 97 return RespondNow(ArgumentList(GetActiveModes::Results::Create(modes))); |
94 } | 98 } |
95 | 99 |
100 // quickUnlockPrivate.getUsablePin | |
101 | |
102 QuickUnlockPrivateGetUsablePinFunction::QuickUnlockPrivateGetUsablePinFunction() | |
103 : chrome_details_(this) {} | |
104 | |
105 QuickUnlockPrivateGetUsablePinFunction:: | |
106 ~QuickUnlockPrivateGetUsablePinFunction() {} | |
107 | |
108 ExtensionFunction::ResponseAction | |
109 QuickUnlockPrivateGetUsablePinFunction::Run() { | |
110 params_ = GetUsablePin::Params::Create(*args_); | |
jdufault
2016/09/29 19:36:52
setModes needs to validate these checks as well.
sammiequon
2016/09/30 00:35:08
Done.
| |
111 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
112 | |
113 Profile* profile = chrome_details_.GetProfile(); | |
114 PrefService* prefservice = profile->GetPrefs(); | |
115 | |
116 std::string tried_password = params_->attempted_password; | |
117 int minimum_length = prefservice->GetInteger(prefs::kPinUnlockMinimumLength); | |
118 int maximum_length = prefservice->GetInteger(prefs::kPinUnlockMaximumLength); | |
119 | |
120 // Check if the pin is shorter than the minimum specified length. | |
121 if (int{tried_password.size()} < minimum_length) { | |
122 return RespondNow(ArgumentList( | |
123 GetUsablePin::Results::Create(PinState::PIN_STATE_SHORTER_THAN_MIN))); | |
124 } | |
125 | |
126 // If the maximum specified length is shorter or equal to the minimum | |
127 // specified length, there is no maximum length. Otherwise check if the pin is | |
128 // longer than the maximum specified length. | |
129 if (maximum_length > minimum_length && | |
130 int{tried_password.size()} > maximum_length) { | |
131 return RespondNow(ArgumentList( | |
132 GetUsablePin::Results::Create(PinState::PIN_STATE_LONGER_THAN_MAX))); | |
133 } | |
134 | |
135 // If the pin length is two or less, there is no need to check for same | |
136 // character and increasing pin. | |
137 const int pin_check_easy_threshold = 2; | |
138 if (int{tried_password.size()} < pin_check_easy_threshold) { | |
139 return RespondNow( | |
140 ArgumentList(GetUsablePin::Results::Create(PinState::PIN_STATE_GOOD))); | |
141 } | |
142 | |
143 // Check for same digits, increasing pin simutaneously. | |
144 bool is_same = true, is_increasing = true; | |
145 char last_char; | |
146 for (int j = 0; j < int{tried_password.size()}; j++) { | |
147 if (j == 0) { | |
148 last_char = tried_password[j]; | |
149 continue; | |
150 } | |
151 is_same = is_same && (tried_password[j] == last_char); | |
152 is_increasing = is_increasing && (tried_password[j] == last_char + 1); | |
153 last_char = tried_password[j]; | |
154 } | |
155 | |
156 // Each digit of the pin is the same. | |
157 if (is_same) { | |
158 return RespondNow(ArgumentList( | |
159 GetUsablePin::Results::Create(PinState::PIN_STATE_ALL_SAME_NUM))); | |
160 } | |
161 | |
162 // Each digit of the pin increases by 1. | |
163 if (is_increasing) { | |
164 return RespondNow(ArgumentList( | |
165 GetUsablePin::Results::Create(PinState::PIN_STATE_INCREASING))); | |
166 } | |
167 | |
168 return RespondNow( | |
169 ArgumentList(GetUsablePin::Results::Create(PinState::PIN_STATE_GOOD))); | |
170 } | |
171 | |
96 // quickUnlockPrivate.setModes | 172 // quickUnlockPrivate.setModes |
97 | 173 |
98 QuickUnlockPrivateSetModesFunction::QuickUnlockPrivateSetModesFunction() | 174 QuickUnlockPrivateSetModesFunction::QuickUnlockPrivateSetModesFunction() |
99 : chrome_details_(this) {} | 175 : chrome_details_(this) {} |
100 | 176 |
101 QuickUnlockPrivateSetModesFunction::~QuickUnlockPrivateSetModesFunction() {} | 177 QuickUnlockPrivateSetModesFunction::~QuickUnlockPrivateSetModesFunction() {} |
102 | 178 |
103 void QuickUnlockPrivateSetModesFunction::SetAuthenticatorAllocatorForTesting( | 179 void QuickUnlockPrivateSetModesFunction::SetAuthenticatorAllocatorForTesting( |
104 const QuickUnlockPrivateSetModesFunction::AuthenticatorAllocator& | 180 const QuickUnlockPrivateSetModesFunction::AuthenticatorAllocator& |
105 allocator) { | 181 allocator) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 299 } |
224 | 300 |
225 std::unique_ptr<base::ListValue> args = OnActiveModesChanged::Create(modes); | 301 std::unique_ptr<base::ListValue> args = OnActiveModesChanged::Create(modes); |
226 std::unique_ptr<Event> event( | 302 std::unique_ptr<Event> event( |
227 new Event(events::QUICK_UNLOCK_PRIVATE_ON_ACTIVE_MODES_CHANGED, | 303 new Event(events::QUICK_UNLOCK_PRIVATE_ON_ACTIVE_MODES_CHANGED, |
228 OnActiveModesChanged::kEventName, std::move(args))); | 304 OnActiveModesChanged::kEventName, std::move(args))); |
229 EventRouter::Get(browser_context())->BroadcastEvent(std::move(event)); | 305 EventRouter::Get(browser_context())->BroadcastEvent(std::move(event)); |
230 } | 306 } |
231 | 307 |
232 } // namespace extensions | 308 } // namespace extensions |
OLD | NEW |