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