Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: remoting/protocol/pairing_registry.h

Issue 17063003: Changes to PairingRegistry to facilitate per-platform implementions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed spacing. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/pairing_host_authenticator.cc ('k') | remoting/protocol/pairing_registry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16
16 namespace remoting { 17 namespace remoting {
17 namespace protocol { 18 namespace protocol {
18 19
20 // TODO(jamiewalch): This class is little more than a wrapper around the
21 // Pairing and Delegate classes. Refactor it away.
22
19 // PairingRegistry holds information about paired clients to support 23 // PairingRegistry holds information about paired clients to support
20 // PIN-less authentication. For each paired client, the registry holds 24 // PIN-less authentication. For each paired client, the registry holds
21 // the following information: 25 // the following information:
22 // * The name of the client. This is supplied by the client and is not 26 // * The name of the client. This is supplied by the client and is not
23 // guaranteed to be unique. 27 // guaranteed to be unique.
24 // * The unique id of the client. This is generated on-demand by this 28 // * 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. 29 // 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 30 // * 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. 31 // class and used in the SPAKE2 exchange to mutually verify identity.
28 class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, 32 class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>,
29 public base::NonThreadSafe { 33 public base::NonThreadSafe {
30 public: 34 public:
31 struct Pairing { 35 struct Pairing {
32 std::string client_id; 36 Pairing();
33 std::string client_name; 37 Pairing(const base::Time& created_time,
34 std::string shared_secret; 38 const std::string& client_name,
39 const std::string& client_id,
40 const std::string& shared_secret);
41 ~Pairing();
42
43 static Pairing Create(const std::string& client_name);
44
45 bool operator==(const Pairing& other) const;
46
47 base::Time created_time() const { return created_time_; }
48 std::string client_id() const { return client_id_; }
49 std::string client_name() const { return client_name_; }
50 std::string shared_secret() const { return shared_secret_; }
51
52 private:
53 base::Time created_time_;
54 std::string client_name_;
55 std::string client_id_;
56 std::string shared_secret_;
35 }; 57 };
36 58
37 // Mapping from client id to pairing information. 59 // Mapping from client id to pairing information.
38 typedef std::map<std::string, Pairing> PairedClients; 60 typedef std::map<std::string, Pairing> PairedClients;
39 61
40 // Delegate::GetPairing callback. 62 // Delegate callbacks.
41 typedef base::Callback<void(Pairing)> GetPairingCallback; 63 typedef base::Callback<void(Pairing client_information)> GetPairingCallback;
64 typedef base::Callback<void(bool success)> AddPairingCallback;
42 65
43 // Interface representing the persistent storage back-end. 66 // Interface representing the persistent storage back-end.
44 class Delegate { 67 class Delegate {
45 public: 68 public:
46 virtual ~Delegate() {} 69 virtual ~Delegate() {}
47 70
48 // Add pairing information to persistent storage. Must not block. 71 // Add pairing information to persistent storage. If a non-NULL callback
49 virtual void AddPairing(const Pairing& new_paired_client) = 0; 72 // is provided, invoke it on completion to indicate success or failure.
73 // Must not block.
74 //
75 // TODO(jamiewalch): Plumb the callback into the RequestPairing flow so
76 // that the client isn't sent the pairing information until it has been
77 // saved.
78 virtual void AddPairing(const Pairing& new_paired_client,
79 const AddPairingCallback& callback) = 0;
50 80
51 // Retrieve the Pairing for the specified client id. If none is 81 // Retrieve the Pairing for the specified client id. If none is
52 // found, invoke the callback with a Pairing in which (at least) 82 // found, invoke the callback with a Pairing in which (at least)
53 // the shared_secret is empty. 83 // the client_name is empty. Must not block.
rmsousa 2013/06/17 23:56:10 The check in the code is for client_id. client_nam
Jamie 2013/06/18 00:16:00 Done.
54 virtual void GetPairing(const std::string& client_id, 84 virtual void GetPairing(const std::string& client_id,
55 const GetPairingCallback& callback) = 0; 85 const GetPairingCallback& callback) = 0;
56 }; 86 };
57 87
58 explicit PairingRegistry(scoped_ptr<Delegate> delegate); 88 explicit PairingRegistry(scoped_ptr<Delegate> delegate);
59 89
60 // Create a pairing for a new client and save it to disk. 90 // Create a pairing for a new client and save it to disk.
61 Pairing CreatePairing(const std::string& client_name); 91 Pairing CreatePairing(const std::string& client_name);
62 92
63 // Get the pairing for the specified client id. See the corresponding 93 // Get the pairing for the specified client id. See the corresponding
64 // Delegate method for details. 94 // Delegate method for details.
65 void GetPairing(const std::string& client_id, 95 void GetPairing(const std::string& client_id,
66 const GetPairingCallback& callback); 96 const GetPairingCallback& callback);
67 97
68 private: 98 private:
69 friend class base::RefCountedThreadSafe<PairingRegistry>; 99 friend class base::RefCountedThreadSafe<PairingRegistry>;
70 100
71 virtual ~PairingRegistry(); 101 virtual ~PairingRegistry();
72 102
73 scoped_ptr<Delegate> delegate_; 103 scoped_ptr<Delegate> delegate_;
74 104
75 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); 105 DISALLOW_COPY_AND_ASSIGN(PairingRegistry);
76 }; 106 };
77 107
78 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. 108 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save.
79 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. 109 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms.
80 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { 110 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate {
81 public: 111 public:
82 virtual void AddPairing( 112 virtual void AddPairing(
83 const PairingRegistry::Pairing& paired_clients) OVERRIDE; 113 const PairingRegistry::Pairing& paired_clients,
114 const PairingRegistry::AddPairingCallback& callback) OVERRIDE;
84 virtual void GetPairing( 115 virtual void GetPairing(
85 const std::string& client_id, 116 const std::string& client_id,
86 const PairingRegistry::GetPairingCallback& callback) OVERRIDE; 117 const PairingRegistry::GetPairingCallback& callback) OVERRIDE;
87 }; 118 };
88 119
89 } // namespace protocol 120 } // namespace protocol
90 } // namespace remoting 121 } // namespace remoting
91 122
92 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ 123 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_
OLDNEW
« no previous file with comments | « remoting/protocol/pairing_host_authenticator.cc ('k') | remoting/protocol/pairing_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698