1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_INTERNAL_AUTH_H_
6 #define CHROME_BROWSER_INTERNAL_AUTH_H_
11 #include "base/gtest_prod_util.h"
13 // Call InternalAuthVerification methods on any thread.
14 class InternalAuthVerification {
16 InternalAuthVerification() = delete;
17 InternalAuthVerification(const InternalAuthVerification&) = delete;
18 InternalAuthVerification& operator=(const InternalAuthVerification&) = delete;
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);
27 friend class InternalAuthGeneration;
28 friend class InternalAuthVerificationService;
29 friend class InternalAuthGenerationService;
30 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce);
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);
38 static void set_verification_window_seconds(int seconds) {
39 verification_window_seconds_ = seconds;
43 static int get_verification_window_ticks();
45 static int verification_window_seconds_;
48 // Not thread-safe. Make all calls on the same thread (UI thread).
49 class InternalAuthGeneration {
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);
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);
64 // Used only by tests.
65 static void GenerateNewKey();
68 #endif // CHROME_BROWSER_INTERNAL_AUTH_H_