Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/chromeos/login/quick_unlock/pin_storage.cc

Issue 2387253002: cros: Added policies for screen unlock. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/login/quick_unlock/pin_storage.h" 5 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" 9 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 22 matching lines...) Expand all
33 // Computes the hash for |pin| and |salt|. 33 // Computes the hash for |pin| and |salt|.
34 std::string ComputeSecret(const std::string& pin, const std::string& salt) { 34 std::string ComputeSecret(const std::string& pin, const std::string& salt) {
35 Key key(pin); 35 Key key(pin);
36 key.Transform(Key::KEY_TYPE_SALTED_PBKDF2_AES256_1234, salt); 36 key.Transform(Key::KEY_TYPE_SALTED_PBKDF2_AES256_1234, salt);
37 return key.GetSecret(); 37 return key.GetSecret();
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 // static 42 // static
43 const base::TimeDelta PinStorage::kStrongAuthTimeout =
44 base::TimeDelta::FromHours(24);
45
46 // static
47 void PinStorage::RegisterProfilePrefs( 43 void PinStorage::RegisterProfilePrefs(
48 user_prefs::PrefRegistrySyncable* registry) { 44 user_prefs::PrefRegistrySyncable* registry) {
49 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "", 45 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, "",
50 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 46 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
51 registry->RegisterStringPref(prefs::kQuickUnlockPinSecret, "", 47 registry->RegisterStringPref(prefs::kQuickUnlockPinSecret, "",
52 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 48 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
53 } 49 }
54 50
55 PinStorage::PinStorage(PrefService* pref_service) 51 PinStorage::PinStorage(PrefService* pref_service)
56 : pref_service_(pref_service) {} 52 : pref_service_(pref_service) {}
57 53
58 PinStorage::~PinStorage() {} 54 PinStorage::~PinStorage() {}
59 55
60 void PinStorage::MarkStrongAuth() { 56 void PinStorage::MarkStrongAuth() {
61 last_strong_auth_ = base::Time::Now(); 57 last_strong_auth_ = base::Time::Now();
62 ResetUnlockAttemptCount(); 58 ResetUnlockAttemptCount();
63 } 59 }
64 60
65 bool PinStorage::HasStrongAuth() const { 61 bool PinStorage::HasStrongAuth() const {
66 return !last_strong_auth_.is_null(); 62 return !last_strong_auth_.is_null();
67 } 63 }
68 64
65 bool PinStorage::NeedsStrongAuth() const {
66 PasswordConfirmation strong_auth_interval =
67 static_cast<PasswordConfirmation>(pref_service_->GetInteger(
68 prefs::kScreenUnlockPasswordConfirmationFrequency));
69 base::TimeDelta strong_auth_timeout;
70 switch (strong_auth_interval) {
jdufault 2016/10/04 17:55:06 Have a helper function that converts PasswordConfi
sammiequon 2016/10/18 22:47:49 Done.
71 case PasswordConfirmation::SIX_HOURS:
72 strong_auth_timeout = base::TimeDelta::FromHours(6);
73 break;
74 case PasswordConfirmation::TWELVE_HOURS:
75 strong_auth_timeout = base::TimeDelta::FromHours(12);
76 break;
77 case PasswordConfirmation::DAY:
78 strong_auth_timeout = base::TimeDelta::FromDays(1);
79 break;
80 case PasswordConfirmation::WEEK:
81 strong_auth_timeout = base::TimeDelta::FromDays(7);
82 break;
83 default:
84 NOTREACHED();
85 return true;
86 }
87
88 return TimeSinceLastStrongAuth() > strong_auth_timeout;
89 }
90
69 base::TimeDelta PinStorage::TimeSinceLastStrongAuth() const { 91 base::TimeDelta PinStorage::TimeSinceLastStrongAuth() const {
70 DCHECK(!last_strong_auth_.is_null()); 92 DCHECK(!last_strong_auth_.is_null());
71 return base::Time::Now() - last_strong_auth_; 93 return base::Time::Now() - last_strong_auth_;
72 } 94 }
73 95
74 void PinStorage::AddUnlockAttempt() { 96 void PinStorage::AddUnlockAttempt() {
75 ++unlock_attempt_count_; 97 ++unlock_attempt_count_;
76 } 98 }
77 99
78 void PinStorage::ResetUnlockAttemptCount() { 100 void PinStorage::ResetUnlockAttemptCount() {
(...skipping 10 matching lines...) Expand all
89 111
90 pref_service_->SetString(prefs::kQuickUnlockPinSalt, salt); 112 pref_service_->SetString(prefs::kQuickUnlockPinSalt, salt);
91 pref_service_->SetString(prefs::kQuickUnlockPinSecret, secret); 113 pref_service_->SetString(prefs::kQuickUnlockPinSecret, secret);
92 } 114 }
93 115
94 void PinStorage::RemovePin() { 116 void PinStorage::RemovePin() {
95 pref_service_->SetString(prefs::kQuickUnlockPinSalt, ""); 117 pref_service_->SetString(prefs::kQuickUnlockPinSalt, "");
96 pref_service_->SetString(prefs::kQuickUnlockPinSecret, ""); 118 pref_service_->SetString(prefs::kQuickUnlockPinSecret, "");
97 } 119 }
98 120
121 bool PinStorage::IsPinUnlockEnabled() const {
jdufault 2016/10/04 17:55:05 Implement this as part of IsQuickUnlockEnabled().
sammiequon 2016/10/18 22:47:49 Aren't these seperate, like quick unlock could be
jdufault 2016/10/21 19:03:44 There's more code than just PinStorage that needs
sammiequon 2016/10/21 23:49:24 Done.
122 const base::ListValue* screen_lock_whitelist =
123 pref_service_->GetList(prefs::kScreenUnlockWhitelist);
124 auto all_value = base::StringValue("all");
jdufault 2016/10/04 17:55:05 Is this how other policy code handles logic like t
sammiequon 2016/10/18 22:47:49 https://cs.chromium.org/chromium/src/chrome/browse
125 auto pin_value = base::StringValue("pin");
126 return screen_lock_whitelist->Find(all_value) !=
127 screen_lock_whitelist->end() ||
128 screen_lock_whitelist->Find(pin_value) != screen_lock_whitelist->end();
129 }
130
99 std::string PinStorage::PinSalt() const { 131 std::string PinStorage::PinSalt() const {
100 return pref_service_->GetString(prefs::kQuickUnlockPinSalt); 132 return pref_service_->GetString(prefs::kQuickUnlockPinSalt);
101 } 133 }
102 134
103 std::string PinStorage::PinSecret() const { 135 std::string PinStorage::PinSecret() const {
104 return pref_service_->GetString(prefs::kQuickUnlockPinSecret); 136 return pref_service_->GetString(prefs::kQuickUnlockPinSecret);
105 } 137 }
106 138
107 bool PinStorage::IsPinAuthenticationAvailable() const { 139 bool PinStorage::IsPinAuthenticationAvailable() const {
108 const bool exceeded_unlock_attempts = 140 const bool exceeded_unlock_attempts =
109 unlock_attempt_count() >= kMaximumUnlockAttempts; 141 unlock_attempt_count() >= kMaximumUnlockAttempts;
110 const bool has_strong_auth = 142 const bool has_strong_auth = HasStrongAuth() && !NeedsStrongAuth();
111 HasStrongAuth() && TimeSinceLastStrongAuth() < kStrongAuthTimeout;
112 143
113 return IsQuickUnlockEnabled() && IsPinSet() && has_strong_auth && 144 return IsPinUnlockEnabled() && IsQuickUnlockEnabled() && IsPinSet() &&
114 !exceeded_unlock_attempts; 145 has_strong_auth && !exceeded_unlock_attempts;
115 } 146 }
116 147
117 bool PinStorage::TryAuthenticatePin(const std::string& pin) { 148 bool PinStorage::TryAuthenticatePin(const std::string& pin) {
118 if (!IsPinAuthenticationAvailable()) 149 if (!IsPinAuthenticationAvailable())
119 return false; 150 return false;
120 151
121 AddUnlockAttempt(); 152 AddUnlockAttempt();
122 return ComputeSecret(pin, PinSalt()) == PinSecret(); 153 return ComputeSecret(pin, PinSalt()) == PinSecret();
123 } 154 }
124 155
125 } // namespace chromeos 156 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698