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 class WebproxyGetTokenFunction; |
| 13 #ifdef UNIT_TEST |
| 14 class InternalAuthTest_BasicGeneration_Test; |
| 15 class InternalAuthTest_DoubleGeneration_Test; |
| 16 class InternalAuthTest_BadGeneration_Test; |
| 17 class InternalAuthTest_BasicVerification_Test; |
| 18 class InternalAuthTest_BruteForce_Test; |
| 19 class InternalAuthTest_ExpirationAndBruteForce_Test; |
| 20 class InternalAuthTest_ChangeKey_Test; |
| 21 #endif |
| 22 |
| 23 namespace browser { |
| 24 |
| 25 // Call InternalAuthVerification methods on any thread. |
| 26 class InternalAuthVerification { |
| 27 public: |
| 28 // Used by consumer of token in order to verify credentials. |
| 29 static bool VerifyToken( |
| 30 const std::string& token, |
| 31 const std::string& domain, |
| 32 const std::map<std::string, std::string>& var_value_map); |
| 33 |
| 34 private: |
| 35 // We allow easy separation of InternalAuthVerification and |
| 36 // InternalAuthGeneration so the only thing they share (besides time) is |
| 37 // a key (regenerated infrequently). |
| 38 static void ChangeKey(const std::string& key); |
| 39 |
| 40 #ifdef UNIT_TEST |
| 41 static void set_verification_window_seconds(int seconds) { |
| 42 verification_window_seconds_ = seconds; |
| 43 } |
| 44 #endif |
| 45 |
| 46 static int get_verification_window_ticks(); |
| 47 |
| 48 static int verification_window_seconds_; |
| 49 |
| 50 friend class InternalAuthGeneration; |
| 51 friend class InternalAuthVerificationService; |
| 52 friend class InternalAuthGenerationService; |
| 53 #ifdef UNIT_TEST |
| 54 friend class ::InternalAuthTest_ExpirationAndBruteForce_Test; |
| 55 #endif |
| 56 }; |
| 57 |
| 58 // Not thread-safe. Make all calls on the same thread (UI thread). |
| 59 class InternalAuthGeneration { |
| 60 private: |
| 61 // Generates token; do this only after successful check of credentials. |
| 62 static std::string GenerateToken( |
| 63 const std::string& domain, |
| 64 const std::map<std::string, std::string>& var_value_map); |
| 65 |
| 66 // Used only by tests. |
| 67 static void GenerateNewKey(); |
| 68 |
| 69 friend class ::WebproxyGetTokenFunction; |
| 70 #ifdef UNIT_TEST |
| 71 friend class ::InternalAuthTest_BasicGeneration_Test; |
| 72 friend class ::InternalAuthTest_DoubleGeneration_Test; |
| 73 friend class ::InternalAuthTest_BadGeneration_Test; |
| 74 friend class ::InternalAuthTest_BasicVerification_Test; |
| 75 friend class ::InternalAuthTest_BruteForce_Test; |
| 76 friend class ::InternalAuthTest_ExpirationAndBruteForce_Test; |
| 77 friend class ::InternalAuthTest_ChangeKey_Test; |
| 78 #endif |
| 79 }; |
| 80 |
| 81 } // namespace browser |
| 82 |
| 83 #endif // CHROME_BROWSER_INTERNAL_AUTH_H_ |
OLD | NEW |