| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 5 #ifndef REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
| 6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 namespace protocol { | 18 namespace protocol { |
| 19 | 19 |
| 20 // TODO(jamiewalch): This class is little more than a wrapper around the | |
| 21 // Pairing and Delegate classes. Refactor it away. | |
| 22 | |
| 23 // PairingRegistry holds information about paired clients to support | 20 // PairingRegistry holds information about paired clients to support |
| 24 // PIN-less authentication. For each paired client, the registry holds | 21 // PIN-less authentication. For each paired client, the registry holds |
| 25 // the following information: | 22 // the following information: |
| 26 // * The name of the client. This is supplied by the client and is not | 23 // * The name of the client. This is supplied by the client and is not |
| 27 // guaranteed to be unique. | 24 // guaranteed to be unique. |
| 28 // * The unique id of the client. This is generated on-demand by this | 25 // * The unique id of the client. This is generated on-demand by this |
| 29 // class and sent in plain-text by the client during authentication. | 26 // class and sent in plain-text by the client during authentication. |
| 30 // * The shared secret for the client. This is generated on-demand by this | 27 // * The shared secret for the client. This is generated on-demand by this |
| 31 // class and used in the SPAKE2 exchange to mutually verify identity. | 28 // class and used in the SPAKE2 exchange to mutually verify identity. |
| 32 class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, | 29 class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 55 base::Time created_time_; | 52 base::Time created_time_; |
| 56 std::string client_name_; | 53 std::string client_name_; |
| 57 std::string client_id_; | 54 std::string client_id_; |
| 58 std::string shared_secret_; | 55 std::string shared_secret_; |
| 59 }; | 56 }; |
| 60 | 57 |
| 61 // Mapping from client id to pairing information. | 58 // Mapping from client id to pairing information. |
| 62 typedef std::map<std::string, Pairing> PairedClients; | 59 typedef std::map<std::string, Pairing> PairedClients; |
| 63 | 60 |
| 64 // Delegate callbacks. | 61 // Delegate callbacks. |
| 65 typedef base::Callback<void(Pairing client_information)> GetPairingCallback; | 62 typedef base::Callback<void(const std::string& pairings_json)> LoadCallback; |
| 66 typedef base::Callback<void(bool success)> AddPairingCallback; | 63 typedef base::Callback<void(bool success)> SaveCallback; |
| 64 typedef base::Callback<void(Pairing pariring)> GetPairingCallback; |
| 67 | 65 |
| 68 // Interface representing the persistent storage back-end. | 66 // Interface representing the persistent storage back-end. |
| 69 class Delegate { | 67 class Delegate { |
| 70 public: | 68 public: |
| 71 virtual ~Delegate() {} | 69 virtual ~Delegate() {} |
| 72 | 70 |
| 73 // Add pairing information to persistent storage. If a non-NULL callback | 71 // Save JSON-encoded pairing information to persistent storage. If |
| 74 // is provided, invoke it on completion to indicate success or failure. | 72 // a non-NULL callback is provided, invoke it on completion to |
| 75 // Must not block. | 73 // indicate success or failure. Must not block. |
| 76 // | 74 virtual void Save(const std::string& pairings_json, |
| 77 // TODO(jamiewalch): Plumb the callback into the RequestPairing flow so | 75 const SaveCallback& callback) = 0; |
| 78 // that the client isn't sent the pairing information until it has been | |
| 79 // saved. | |
| 80 virtual void AddPairing(const Pairing& new_paired_client, | |
| 81 const AddPairingCallback& callback) = 0; | |
| 82 | 76 |
| 83 // Retrieve the Pairing for the specified client id. If none is found, | 77 // Retrieve the JSON-encoded pairing information from persistent |
| 84 // invoke the callback with a default pairing. Must not block. | 78 // storage. Must not block. |
| 85 virtual void GetPairing(const std::string& client_id, | 79 virtual void Load(const LoadCallback& callback) = 0; |
| 86 const GetPairingCallback& callback) = 0; | |
| 87 }; | 80 }; |
| 88 | 81 |
| 89 explicit PairingRegistry(scoped_ptr<Delegate> delegate); | 82 explicit PairingRegistry(scoped_ptr<Delegate> delegate); |
| 90 | 83 |
| 91 // Create a pairing for a new client and save it to disk. | 84 // Creates a pairing for a new client and saves it to disk. |
| 85 // |
| 86 // TODO(jamiewalch): Plumb the Save callback into the RequestPairing flow |
| 87 // so that the client isn't sent the pairing information until it has been |
| 88 // saved. |
| 92 Pairing CreatePairing(const std::string& client_name); | 89 Pairing CreatePairing(const std::string& client_name); |
| 93 | 90 |
| 94 // Get the pairing for the specified client id. See the corresponding | 91 // Gets the pairing for the specified client id. See the corresponding |
| 95 // Delegate method for details. | 92 // Delegate method for details. If none is found, the callback is invoked |
| 93 // with an invalid Pairing. |
| 96 void GetPairing(const std::string& client_id, | 94 void GetPairing(const std::string& client_id, |
| 97 const GetPairingCallback& callback); | 95 const GetPairingCallback& callback); |
| 98 | 96 |
| 99 private: | 97 private: |
| 98 FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, AddPairing); |
| 99 friend class NegotiatingAuthenticatorTest; |
| 100 friend class base::RefCountedThreadSafe<PairingRegistry>; | 100 friend class base::RefCountedThreadSafe<PairingRegistry>; |
| 101 | 101 |
| 102 virtual ~PairingRegistry(); | 102 virtual ~PairingRegistry(); |
| 103 | 103 |
| 104 void AddPairing(const Pairing& pairing);; |
| 105 void MergePairingAndSave(const Pairing& pairing, |
| 106 const std::string& pairings_json); |
| 107 void DoGetPairing(const std::string& client_id, |
| 108 const GetPairingCallback& callback, |
| 109 const std::string& pairings_json); |
| 110 |
| 111 static PairedClients DecodeJson(const std::string& pairings_json); |
| 112 static std::string EncodeJson(const PairedClients& clients); |
| 113 |
| 104 scoped_ptr<Delegate> delegate_; | 114 scoped_ptr<Delegate> delegate_; |
| 105 | 115 |
| 106 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); | 116 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); |
| 107 }; | 117 }; |
| 108 | 118 |
| 109 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. | |
| 110 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. | |
| 111 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { | |
| 112 public: | |
| 113 virtual void AddPairing( | |
| 114 const PairingRegistry::Pairing& paired_clients, | |
| 115 const PairingRegistry::AddPairingCallback& callback) OVERRIDE; | |
| 116 virtual void GetPairing( | |
| 117 const std::string& client_id, | |
| 118 const PairingRegistry::GetPairingCallback& callback) OVERRIDE; | |
| 119 }; | |
| 120 | |
| 121 } // namespace protocol | 119 } // namespace protocol |
| 122 } // namespace remoting | 120 } // namespace remoting |
| 123 | 121 |
| 124 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 122 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
| OLD | NEW |