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