blob: 23e2ee8e14beb1e7a718195f90d7256e47fe46b7 [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"
avidd4e614352015-12-09 00:44:4912#include "base/macros.h"
[email protected]c6e584c2011-05-18 11:58:4413
[email protected]c6e584c2011-05-18 11:58:4414// Call InternalAuthVerification methods on any thread.
15class InternalAuthVerification {
16 public:
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);
22
23 private:
[email protected]08b14a52012-07-02 23:30:3624 friend class InternalAuthGeneration;
25 friend class InternalAuthVerificationService;
26 friend class InternalAuthGenerationService;
27 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce);
28
[email protected]c6e584c2011-05-18 11:58:4429 // 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);
33
34#ifdef UNIT_TEST
35 static void set_verification_window_seconds(int seconds) {
36 verification_window_seconds_ = seconds;
37 }
38#endif
39
40 static int get_verification_window_ticks();
41
42 static int verification_window_seconds_;
43
[email protected]08b14a52012-07-02 23:30:3644 DISALLOW_IMPLICIT_CONSTRUCTORS(InternalAuthVerification);
[email protected]c6e584c2011-05-18 11:58:4445};
46
47// Not thread-safe. Make all calls on the same thread (UI thread).
48class InternalAuthGeneration {
49 private:
[email protected]c6e584c2011-05-18 11:58:4450 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);
[email protected]08b14a52012-07-02 23:30:3657
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);
62
63 // Used only by tests.
64 static void GenerateNewKey();
[email protected]c6e584c2011-05-18 11:58:4465};
66
[email protected]c6e584c2011-05-18 11:58:4467#endif // CHROME_BROWSER_INTERNAL_AUTH_H_