blob: 3df1b1d6b2c26a67968d1a7cbcc5685b9cb6c0ac [file] [log] [blame]
[email protected]472ef482012-05-25 09:15:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c6e584c2011-05-18 11:58:442// 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]c6e584c2011-05-18 11:58:447
8#include <map>
9#include <string>
10
11#include "base/gtest_prod_util.h"
12
[email protected]c6e584c2011-05-18 11:58:4413// Call InternalAuthVerification methods on any thread.
14class InternalAuthVerification {
15 public:
Peter Boströmfadb1752021-09-30 19:17:0116 InternalAuthVerification() = delete;
17 InternalAuthVerification(const InternalAuthVerification&) = delete;
18 InternalAuthVerification& operator=(const InternalAuthVerification&) = delete;
19
[email protected]c6e584c2011-05-18 11:58:4420 // 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);
25
26 private:
[email protected]08b14a52012-07-02 23:30:3627 friend class InternalAuthGeneration;
28 friend class InternalAuthVerificationService;
29 friend class InternalAuthGenerationService;
30 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce);
31
[email protected]c6e584c2011-05-18 11:58:4432 // 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);
36
37#ifdef UNIT_TEST
38 static void set_verification_window_seconds(int seconds) {
39 verification_window_seconds_ = seconds;
40 }
41#endif
42
43 static int get_verification_window_ticks();
44
45 static int verification_window_seconds_;
[email protected]c6e584c2011-05-18 11:58:4446};
47
48// Not thread-safe. Make all calls on the same thread (UI thread).
49class InternalAuthGeneration {
50 private:
[email protected]c6e584c2011-05-18 11:58:4451 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);
[email protected]08b14a52012-07-02 23:30:3658
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);
63
64 // Used only by tests.
65 static void GenerateNewKey();
[email protected]c6e584c2011-05-18 11:58:4466};
67
[email protected]c6e584c2011-05-18 11:58:4468#endif // CHROME_BROWSER_INTERNAL_AUTH_H_