[email protected] | 472ef48 | 2012-05-25 09:15:11 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_INTERNAL_AUTH_H_ |
| 6 | #define CHROME_BROWSER_INTERNAL_AUTH_H_ |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/gtest_prod_util.h" |
| 12 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 13 | // Call InternalAuthVerification methods on any thread. |
| 14 | class InternalAuthVerification { |
| 15 | public: |
Peter Boström | fadb175 | 2021-09-30 19:17:01 | [diff] [blame] | 16 | InternalAuthVerification() = delete; |
| 17 | InternalAuthVerification(const InternalAuthVerification&) = delete; |
| 18 | InternalAuthVerification& operator=(const InternalAuthVerification&) = delete; |
| 19 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 20 | // Used by consumer of passport in order to verify credentials. |
| 21 | static bool VerifyPassport( |
| 22 | const std::string& passport, |
| 23 | const std::string& domain, |
| 24 | const std::map<std::string, std::string>& var_value_map); |
| 25 | |
| 26 | private: |
[email protected] | 08b14a5 | 2012-07-02 23:30:36 | [diff] [blame] | 27 | friend class InternalAuthGeneration; |
| 28 | friend class InternalAuthVerificationService; |
| 29 | friend class InternalAuthGenerationService; |
| 30 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce); |
| 31 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 32 | // We allow for easy separation of InternalAuthVerification and |
| 33 | // InternalAuthGeneration so the only thing they share (besides time) is |
| 34 | // a key (regenerated infrequently). |
| 35 | static void ChangeKey(const std::string& key); |
| 36 | |
| 37 | #ifdef UNIT_TEST |
| 38 | static void set_verification_window_seconds(int seconds) { |
| 39 | verification_window_seconds_ = seconds; |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | static int get_verification_window_ticks(); |
| 44 | |
| 45 | static int verification_window_seconds_; |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | // Not thread-safe. Make all calls on the same thread (UI thread). |
| 49 | class InternalAuthGeneration { |
| 50 | private: |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 51 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BasicGeneration); |
| 52 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, DoubleGeneration); |
| 53 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BadGeneration); |
| 54 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BasicVerification); |
| 55 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BruteForce); |
| 56 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce); |
| 57 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ChangeKey); |
[email protected] | 08b14a5 | 2012-07-02 23:30:36 | [diff] [blame] | 58 | |
| 59 | // Generates passport; do this only after successful check of credentials. |
| 60 | static std::string GeneratePassport( |
| 61 | const std::string& domain, |
| 62 | const std::map<std::string, std::string>& var_value_map); |
| 63 | |
| 64 | // Used only by tests. |
| 65 | static void GenerateNewKey(); |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 66 | }; |
| 67 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 68 | #endif // CHROME_BROWSER_INTERNAL_AUTH_H_ |