Roll src/third_party/WebKit eb1578b:b559582 (svn 193425:193437)
[chromium-blink-merge.git] / chrome / browser / internal_auth.h
blobaa303330cad4c91e32f8b258f69a355b80c22104
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_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
14 namespace chrome {
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);
25 private:
26 friend class InternalAuthGeneration;
27 friend class InternalAuthVerificationService;
28 friend class InternalAuthGenerationService;
29 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce);
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);
36 #ifdef UNIT_TEST
37 static void set_verification_window_seconds(int seconds) {
38 verification_window_seconds_ = seconds;
40 #endif
42 static int get_verification_window_ticks();
44 static int verification_window_seconds_;
46 DISALLOW_IMPLICIT_CONSTRUCTORS(InternalAuthVerification);
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);
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);
65 // Used only by tests.
66 static void GenerateNewKey();
69 } // namespace chrome
71 #endif // CHROME_BROWSER_INTERNAL_AUTH_H_