blob: aa303330cad4c91e32f8b258f69a355b80c22104 [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
[email protected]08b14a52012-07-02 23:30:3611#include "base/basictypes.h"
[email protected]c6e584c2011-05-18 11:58:4412#include "base/gtest_prod_util.h"
13
[email protected]08b14a52012-07-02 23:30:3614namespace chrome {
[email protected]c6e584c2011-05-18 11:58:4415
16// Call InternalAuthVerification methods on any thread.
17class 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);
24
25 private:
[email protected]08b14a52012-07-02 23:30:3626 friend class InternalAuthGeneration;
27 friend class InternalAuthVerificationService;
28 friend class InternalAuthGenerationService;
29 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce);
30
[email protected]c6e584c2011-05-18 11:58:4431 // 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);
35
36#ifdef UNIT_TEST
37 static void set_verification_window_seconds(int seconds) {
38 verification_window_seconds_ = seconds;
39 }
40#endif
41
42 static int get_verification_window_ticks();
43
44 static int verification_window_seconds_;
45
[email protected]08b14a52012-07-02 23:30:3646 DISALLOW_IMPLICIT_CONSTRUCTORS(InternalAuthVerification);
[email protected]c6e584c2011-05-18 11:58:4447};
48
49// Not thread-safe. Make all calls on the same thread (UI thread).
50class InternalAuthGeneration {
51 private:
[email protected]c6e584c2011-05-18 11:58:4452 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);
[email protected]08b14a52012-07-02 23:30:3659
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);
64
65 // Used only by tests.
66 static void GenerateNewKey();
[email protected]c6e584c2011-05-18 11:58:4467};
68
[email protected]08b14a52012-07-02 23:30:3669} // namespace chrome
[email protected]c6e584c2011-05-18 11:58:4470
71#endif // CHROME_BROWSER_INTERNAL_AUTH_H_