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.
5 #ifndef CHROME_BROWSER_INTERNAL_AUTH_H_
6 #define CHROME_BROWSER_INTERNAL_AUTH_H_
11 #include "base/gtest_prod_util.h"
12 #include "base/macros.h"
14 // Call InternalAuthVerification methods on any thread.
15 class InternalAuthVerification {
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);
24 friend class InternalAuthGeneration;
25 friend class InternalAuthVerificationService;
26 friend class InternalAuthGenerationService;
27 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce);
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);
35 static void set_verification_window_seconds(int seconds) {
36 verification_window_seconds_ = seconds;
40 static int get_verification_window_ticks();
42 static int verification_window_seconds_;
44 DISALLOW_IMPLICIT_CONSTRUCTORS(InternalAuthVerification);
47 // Not thread-safe. Make all calls on the same thread (UI thread).
48 class InternalAuthGeneration {
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);
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);
63 // Used only by tests.
64 static void GenerateNewKey();
67 #endif // CHROME_BROWSER_INTERNAL_AUTH_H_