[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" |
avi | dd4e61435 | 2015-12-09 00:44:49 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 13 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 14 | // Call InternalAuthVerification methods on any thread. |
| 15 | class InternalAuthVerification { |
| 16 | public: |
| 17 | // Used by consumer of passport in order to verify credentials. |
| 18 | static bool VerifyPassport( |
| 19 | const std::string& passport, |
| 20 | const std::string& domain, |
| 21 | const std::map<std::string, std::string>& var_value_map); |
| 22 | |
| 23 | private: |
[email protected] | 08b14a5 | 2012-07-02 23:30:36 | [diff] [blame] | 24 | friend class InternalAuthGeneration; |
| 25 | friend class InternalAuthVerificationService; |
| 26 | friend class InternalAuthGenerationService; |
| 27 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce); |
| 28 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 29 | // We allow for easy separation of InternalAuthVerification and |
| 30 | // InternalAuthGeneration so the only thing they share (besides time) is |
| 31 | // a key (regenerated infrequently). |
| 32 | static void ChangeKey(const std::string& key); |
| 33 | |
| 34 | #ifdef UNIT_TEST |
| 35 | static void set_verification_window_seconds(int seconds) { |
| 36 | verification_window_seconds_ = seconds; |
| 37 | } |
| 38 | #endif |
| 39 | |
| 40 | static int get_verification_window_ticks(); |
| 41 | |
| 42 | static int verification_window_seconds_; |
| 43 | |
[email protected] | 08b14a5 | 2012-07-02 23:30:36 | [diff] [blame] | 44 | DISALLOW_IMPLICIT_CONSTRUCTORS(InternalAuthVerification); |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | // Not thread-safe. Make all calls on the same thread (UI thread). |
| 48 | class InternalAuthGeneration { |
| 49 | private: |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 50 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BasicGeneration); |
| 51 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, DoubleGeneration); |
| 52 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BadGeneration); |
| 53 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BasicVerification); |
| 54 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BruteForce); |
| 55 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce); |
| 56 | FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ChangeKey); |
[email protected] | 08b14a5 | 2012-07-02 23:30:36 | [diff] [blame] | 57 | |
| 58 | // Generates passport; do this only after successful check of credentials. |
| 59 | static std::string GeneratePassport( |
| 60 | const std::string& domain, |
| 61 | const std::map<std::string, std::string>& var_value_map); |
| 62 | |
| 63 | // Used only by tests. |
| 64 | static void GenerateNewKey(); |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 65 | }; |
| 66 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 67 | #endif // CHROME_BROWSER_INTERNAL_AUTH_H_ |