OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_INTERNAL_AUTH_H_ |
| 6 #define CHROME_BROWSER_INTERNAL_AUTH_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "base/gtest_prod_util.h" |
| 13 |
| 14 class WebSocketProxyPrivateGetPassportForTCPFunction; |
| 15 |
| 16 namespace browser { |
| 17 |
| 18 // Call InternalAuthVerification methods on any thread. |
| 19 class InternalAuthVerification { |
| 20 public: |
| 21 // Used by consumer of passport in order to verify credentials. |
| 22 static bool VerifyPassport( |
| 23 const std::string& passport, |
| 24 const std::string& domain, |
| 25 const std::map<std::string, std::string>& var_value_map); |
| 26 |
| 27 private: |
| 28 // We allow for easy separation of InternalAuthVerification and |
| 29 // InternalAuthGeneration so the only thing they share (besides time) is |
| 30 // a key (regenerated infrequently). |
| 31 static void ChangeKey(const std::string& key); |
| 32 |
| 33 #ifdef UNIT_TEST |
| 34 static void set_verification_window_seconds(int seconds) { |
| 35 verification_window_seconds_ = seconds; |
| 36 } |
| 37 #endif |
| 38 |
| 39 static int get_verification_window_ticks(); |
| 40 |
| 41 static int verification_window_seconds_; |
| 42 |
| 43 friend class InternalAuthGeneration; |
| 44 friend class InternalAuthVerificationService; |
| 45 friend class InternalAuthGenerationService; |
| 46 |
| 47 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce); |
| 48 }; |
| 49 |
| 50 // Not thread-safe. Make all calls on the same thread (UI thread). |
| 51 class InternalAuthGeneration { |
| 52 private: |
| 53 // Generates passport; do this only after successful check of credentials. |
| 54 static std::string GeneratePassport( |
| 55 const std::string& domain, |
| 56 const std::map<std::string, std::string>& var_value_map); |
| 57 |
| 58 // Used only by tests. |
| 59 static void GenerateNewKey(); |
| 60 |
| 61 friend class ::WebSocketProxyPrivateGetPassportForTCPFunction; |
| 62 |
| 63 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BasicGeneration); |
| 64 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, DoubleGeneration); |
| 65 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BadGeneration); |
| 66 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BasicVerification); |
| 67 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, BruteForce); |
| 68 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ExpirationAndBruteForce); |
| 69 FRIEND_TEST_ALL_PREFIXES(InternalAuthTest, ChangeKey); |
| 70 }; |
| 71 |
| 72 } // namespace browser |
| 73 |
| 74 #endif // CHROME_BROWSER_INTERNAL_AUTH_H_ |
OLD | NEW |