Chromium Code Reviews| 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" | |
| 16 | |
| 17 namespace base { | |
| 18 class TaskRunner; | |
| 19 } // namespace base | |
| 15 | 20 |
| 16 namespace remoting { | 21 namespace remoting { |
| 17 namespace protocol { | 22 namespace protocol { |
| 18 | 23 |
| 19 // PairingRegistry holds information about paired clients to support | 24 // PairingRegistry holds information about paired clients to support |
| 20 // PIN-less authentication. For each paired client, the registry holds | 25 // PIN-less authentication. For each paired client, the registry holds |
| 21 // the following information: | 26 // the following information: |
| 22 // * The name of the client. This is supplied by the client and is not | 27 // * The name of the client. This is supplied by the client and is not |
| 23 // guaranteed to be unique. | 28 // guaranteed to be unique. |
| 24 // * The unique id of the client. This is generated on-demand by this | 29 // * The unique id of the client. This is generated on-demand by this |
| 25 // class and sent in plain-text by the client during authentication. | 30 // class and sent in plain-text by the client during authentication. |
| 26 // * The shared secret for the client. This is generated on-demand by this | 31 // * The shared secret for the client. This is generated on-demand by this |
| 27 // class and used in the SPAKE2 exchange to mutually verify identity. | 32 // class and used in the SPAKE2 exchange to mutually verify identity. |
| 28 class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, | 33 class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, |
| 29 public base::NonThreadSafe { | 34 public base::NonThreadSafe { |
| 30 public: | 35 public: |
| 31 struct Pairing { | 36 struct Pairing { |
| 37 bool operator==(const Pairing& other) const; | |
|
Lambros
2013/05/31 18:51:59
Is this used only in unittest? If so, consider mov
Jamie
2013/06/19 17:56:44
It is only used in the unit test, but I've now mad
| |
| 38 | |
| 39 base::Time created_time; | |
| 32 std::string client_id; | 40 std::string client_id; |
| 33 std::string client_name; | 41 std::string client_name; |
| 34 std::string shared_secret; | 42 std::string shared_secret; |
| 35 }; | 43 }; |
| 36 | 44 |
| 37 // Mapping from client id to pairing information. | 45 // Mapping from client id to pairing information. |
| 38 typedef std::map<std::string, Pairing> PairedClients; | 46 typedef std::map<std::string, Pairing> PairedClients; |
| 39 | 47 |
| 40 // Interface representing the persistent storage back-end. | 48 // Interface representing the persistent storage back-end. |
| 41 class Delegate { | 49 class Delegate { |
| 42 public: | 50 public: |
| 43 virtual ~Delegate() {} | 51 virtual ~Delegate() {} |
| 44 | 52 |
| 45 // Save pairing information to persistent storage. Must not block. | 53 // Save pairing information to persistent storage. Must not block. |
| 46 virtual void Save(const PairedClients& paired_clients) = 0; | 54 virtual void Save(const PairedClients& paired_clients) = 0; |
| 55 | |
| 56 // Load the pairing information synchronously from persistent storage. | |
|
Lambros
2013/05/31 18:51:59
nit: Loads (and elsewhere)
http://google-styleguid
Jamie
2013/06/19 17:56:44
I've updated the implementation methods as you sug
| |
| 57 // Note that this method is not used by the PairingRegistry class; instead | |
| 58 // it should be called on the result of CreateDelegate prior to creating | |
| 59 // a PairingRegistry. Unlike Save, LoadOnCurrentThread may block while | |
| 60 // loading the pairings--it is the caller's responsibility to make sure | |
| 61 // it is called on a suitable thread. | |
| 62 virtual PairedClients LoadOnCurrentThread() = 0; | |
| 47 }; | 63 }; |
| 48 | 64 |
| 49 explicit PairingRegistry(scoped_ptr<Delegate> delegate, | 65 explicit PairingRegistry(scoped_ptr<Delegate> delegate, |
| 50 const PairedClients& paired_clients); | 66 const PairedClients& paired_clients); |
| 51 | 67 |
| 52 // Create a pairing for a new client and save it to disk. | 68 // Create a pairing for a new client and save it to disk. |
| 53 const Pairing& CreatePairing(const std::string& client_name); | 69 const Pairing& CreatePairing(const std::string& client_name); |
| 54 | 70 |
| 55 // Look up the shared secret for the specified client id. Returns an empty | 71 // Look up the shared secret for the specified client id. Returns an empty |
| 56 // string if the client id is not known. | 72 // string if the client id is not known. |
| 57 std::string GetSecret(const std::string &client_id) const; | 73 std::string GetSecret(const std::string &client_id) const; |
| 58 | 74 |
| 75 // Return a platform-specific Delegate that will save to permanent storage | |
|
Lambros
2013/05/31 18:51:59
Can this be moved to remoting/host ?
Jamie
2013/06/19 17:56:44
It could, but the Create pattern is very common in
Lambros
2013/06/20 17:59:20
The pattern is fine, but it doesn't belong in remo
Jamie
2013/06/20 20:17:09
Good point. There were actually quite a lot of cla
| |
| 76 // using the specified TaskRunner. Return NULL on platforms that don't | |
| 77 // support pairing. | |
| 78 static scoped_ptr<Delegate> CreateDelegate( | |
| 79 scoped_refptr<base::TaskRunner> task_runner); | |
| 80 | |
| 59 private: | 81 private: |
| 60 friend class base::RefCountedThreadSafe<PairingRegistry>; | 82 friend class base::RefCountedThreadSafe<PairingRegistry>; |
| 61 | 83 |
| 62 virtual ~PairingRegistry(); | 84 virtual ~PairingRegistry(); |
| 63 | 85 |
| 64 // Callback for the Delegate::Load method. Invoked when the stored pairings | 86 // Callback for the Delegate::Load method. Invoked when the stored pairings |
| 65 // have been loaded. | 87 // have been loaded. |
| 66 void OnLoad(const PairedClients& paired_clients); | 88 void OnLoad(const PairedClients& paired_clients); |
| 67 | 89 |
| 68 scoped_ptr<Delegate> delegate_; | 90 scoped_ptr<Delegate> delegate_; |
| 69 PairedClients paired_clients_; | 91 PairedClients paired_clients_; |
| 70 | 92 |
| 71 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); | 93 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); |
| 72 }; | 94 }; |
| 73 | 95 |
| 74 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. | 96 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. |
|
Lambros
2013/05/31 18:51:59
Can we remove this class as well?
Jamie
2013/06/19 17:56:44
Done.
| |
| 75 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. | 97 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. |
| 76 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { | 98 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { |
| 77 public: | 99 public: |
| 78 virtual void Save( | 100 virtual void Save( |
| 79 const PairingRegistry::PairedClients& paired_clients) OVERRIDE; | 101 const PairingRegistry::PairedClients& paired_clients) OVERRIDE; |
| 102 virtual PairingRegistry::PairedClients LoadOnCurrentThread() OVERRIDE; | |
| 80 }; | 103 }; |
| 81 | 104 |
| 82 } // namespace protocol | 105 } // namespace protocol |
| 83 } // namespace remoting | 106 } // namespace remoting |
| 84 | 107 |
| 85 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ | 108 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ |
| OLD | NEW |