| 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_QUICK_UNLOCK_PIN_STORAGE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_QUICK_UNLOCK_PIN_STORAGE_PREFS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_QUICK_UNLOCK_PIN_STORAGE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_QUICK_UNLOCK_PIN_STORAGE_PREFS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" | |
| 12 | 11 |
| 13 class PrefRegistrySimple; | 12 class PrefRegistrySimple; |
| 14 class PrefService; | 13 class Profile; |
| 15 | 14 |
| 16 namespace chromeos { | 15 namespace chromeos { |
| 17 | 16 |
| 18 class PinStorageTestApi; | 17 class PinStorageTestApi; |
| 19 | 18 |
| 20 namespace quick_unlock { | 19 namespace quick_unlock { |
| 21 | 20 |
| 22 class QuickUnlockStorage; | 21 class QuickUnlockStorage; |
| 23 | 22 |
| 24 class PinStorage { | 23 class PinStoragePrefs { |
| 25 public: | 24 public: |
| 26 // TODO(sammiequon): Pull this value in from policy. See crbug.com/612271. | |
| 27 static const int kMaximumUnlockAttempts = 3; | 25 static const int kMaximumUnlockAttempts = 3; |
| 28 | 26 |
| 29 // Registers profile prefs. | 27 // Registers profile prefs. |
| 30 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 28 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 31 | 29 |
| 32 explicit PinStorage(PrefService* pref_service); | 30 explicit PinStoragePrefs(Profile* profile); |
| 33 ~PinStorage(); | 31 ~PinStoragePrefs(); |
| 34 | |
| 35 // Add a PIN unlock attempt count. | |
| 36 void AddUnlockAttempt(); | |
| 37 // Reset the number of unlock attempts to 0. | |
| 38 void ResetUnlockAttemptCount(); | |
| 39 // Returns the number of unlock attempts. | |
| 40 int unlock_attempt_count() const { return unlock_attempt_count_; } | |
| 41 | 32 |
| 42 // Returns true if a pin is set. | 33 // Returns true if a pin is set. |
| 43 bool IsPinSet() const; | 34 bool IsPinSet() const; |
| 44 // Sets the pin to the given value; IsPinSet will return true. | 35 |
| 36 // Sets the pin to the given value. |
| 45 void SetPin(const std::string& pin); | 37 void SetPin(const std::string& pin); |
| 38 |
| 46 // Removes the pin; IsPinSet will return false. | 39 // Removes the pin; IsPinSet will return false. |
| 47 void RemovePin(); | 40 void RemovePin(); |
| 48 | 41 |
| 49 private: | |
| 50 friend class chromeos::PinStorageTestApi; | |
| 51 friend class QuickUnlockStorage; | |
| 52 | |
| 53 // Is PIN entry currently available? | 42 // Is PIN entry currently available? |
| 54 bool IsPinAuthenticationAvailable() const; | 43 bool IsPinAuthenticationAvailable() const; |
| 55 | 44 |
| 56 // Tries to authenticate the given pin. This will consume an unlock attempt. | 45 // Tries to authenticate the given pin. This will consume an unlock attempt. |
| 57 // This always returns false if IsPinAuthenticationAvailable returns false. | 46 // This always returns false if IsPinAuthenticationAvailable returns false. |
| 47 // |
| 48 // This is a no-op for cryptohome implementation (standard password flow works |
| 49 // there). |
| 58 bool TryAuthenticatePin(const std::string& pin); | 50 bool TryAuthenticatePin(const std::string& pin); |
| 59 | 51 |
| 52 // Implementation should return true if it needs strong auth support, ie, the |
| 53 // user has to type their password every x hours. |
| 54 bool NeedsStrongAuth() const; |
| 55 |
| 56 // Add a PIN unlock attempt count. |
| 57 void AddUnlockAttempt(); |
| 58 |
| 59 // Reset the unlock attempt count to 0. Not applicable to all implementations. |
| 60 void ResetUnlockAttemptCount(); |
| 61 |
| 62 // Returns the number of unlock attempts. |
| 63 int unlock_attempt_count() const { return unlock_attempt_count_; } |
| 64 |
| 65 private: |
| 66 friend class chromeos::PinStorageTestApi; |
| 67 friend class QuickUnlockStorage; |
| 68 |
| 60 // Return the stored salt/secret. This is fetched directly from pref_service_. | 69 // Return the stored salt/secret. This is fetched directly from pref_service_. |
| 61 std::string PinSalt() const; | 70 std::string PinSalt() const; |
| 62 std::string PinSecret() const; | 71 std::string PinSecret() const; |
| 63 | 72 |
| 64 PrefService* pref_service_; | 73 Profile* profile_; |
| 65 int unlock_attempt_count_ = 0; | 74 int unlock_attempt_count_ = 0; |
| 66 | 75 |
| 67 DISALLOW_COPY_AND_ASSIGN(PinStorage); | 76 DISALLOW_COPY_AND_ASSIGN(PinStoragePrefs); |
| 68 }; | 77 }; |
| 69 | 78 |
| 70 } // namespace quick_unlock | 79 } // namespace quick_unlock |
| 71 } // namespace chromeos | 80 } // namespace chromeos |
| 72 | 81 |
| 73 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_QUICK_UNLOCK_PIN_STORAGE_H_ | 82 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_QUICK_UNLOCK_PIN_STORAGE_PREFS_H_ |
| OLD | NEW |