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/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 20 matching lines...) Expand all Loading... |
31 return salt; | 31 return salt; |
32 } | 32 } |
33 | 33 |
34 // Computes the hash for |pin| and |salt|. | 34 // Computes the hash for |pin| and |salt|. |
35 std::string ComputeSecret(const std::string& pin, const std::string& salt) { | 35 std::string ComputeSecret(const std::string& pin, const std::string& salt) { |
36 Key key(pin); | 36 Key key(pin); |
37 key.Transform(Key::KEY_TYPE_SALTED_PBKDF2_AES256_1234, salt); | 37 key.Transform(Key::KEY_TYPE_SALTED_PBKDF2_AES256_1234, salt); |
38 return key.GetSecret(); | 38 return key.GetSecret(); |
39 } | 39 } |
40 | 40 |
41 base::TimeDelta PasswordConfirmationFrequencyToTimeDelta( | |
42 PasswordConfirmationFrequency frequency) { | |
43 switch (frequency) { | |
44 case PasswordConfirmationFrequency::SIX_HOURS: | |
45 return base::TimeDelta::FromHours(6); | |
46 case PasswordConfirmationFrequency::TWELVE_HOURS: | |
47 return base::TimeDelta::FromHours(12); | |
48 case PasswordConfirmationFrequency::DAY: | |
49 return base::TimeDelta::FromDays(1); | |
50 case PasswordConfirmationFrequency::WEEK: | |
51 return base::TimeDelta::FromDays(7); | |
52 } | |
53 NOTREACHED(); | |
54 return base::TimeDelta(); | |
55 } | |
56 | |
57 } // namespace | 41 } // namespace |
58 | 42 |
59 // static | 43 // static |
60 void PinStorage::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 44 void PinStorage::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
61 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, ""); | 45 registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, ""); |
62 registry->RegisterStringPref(prefs::kQuickUnlockPinSecret, ""); | 46 registry->RegisterStringPref(prefs::kQuickUnlockPinSecret, ""); |
63 } | 47 } |
64 | 48 |
65 PinStorage::PinStorage(PrefService* pref_service) | 49 PinStorage::PinStorage(PrefService* pref_service) |
66 : pref_service_(pref_service) {} | 50 : pref_service_(pref_service) {} |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool PinStorage::TryAuthenticatePin(const std::string& pin) { | 118 bool PinStorage::TryAuthenticatePin(const std::string& pin) { |
135 if (!IsPinAuthenticationAvailable()) | 119 if (!IsPinAuthenticationAvailable()) |
136 return false; | 120 return false; |
137 | 121 |
138 AddUnlockAttempt(); | 122 AddUnlockAttempt(); |
139 return ComputeSecret(pin, PinSalt()) == PinSecret(); | 123 return ComputeSecret(pin, PinSalt()) == PinSecret(); |
140 } | 124 } |
141 | 125 |
142 } // namespace quick_unlock | 126 } // namespace quick_unlock |
143 } // namespace chromeos | 127 } // namespace chromeos |
OLD | NEW |