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

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: Reviewer feedback. 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 bool is_valid() const;
48
49 base::Time created_time() const { return created_time_; }
50 std::string client_id() const { return client_id_; }
51 std::string client_name() const { return client_name_; }
52 std::string shared_secret() const { return shared_secret_; }
53
54 private:
55 base::Time created_time_;
56 std::string client_name_;
57 std::string client_id_;
58 std::string shared_secret_;
35 }; 59 };
36 60
37 // Mapping from client id to pairing information. 61 // Mapping from client id to pairing information.
38 typedef std::map<std::string, Pairing> PairedClients; 62 typedef std::map<std::string, Pairing> PairedClients;
39 63
40 // Delegate::GetPairing callback. 64 // Delegate callbacks.
41 typedef base::Callback<void(Pairing)> GetPairingCallback; 65 typedef base::Callback<void(Pairing client_information)> GetPairingCallback;
66 typedef base::Callback<void(bool success)> AddPairingCallback;
42 67
43 // Interface representing the persistent storage back-end. 68 // Interface representing the persistent storage back-end.
44 class Delegate { 69 class Delegate {
45 public: 70 public:
46 virtual ~Delegate() {} 71 virtual ~Delegate() {}
47 72
48 // Add pairing information to persistent storage. Must not block. 73 // Add pairing information to persistent storage. If a non-NULL callback
49 virtual void AddPairing(const Pairing& new_paired_client) = 0; 74 // is provided, invoke it on completion to indicate success or failure.
75 // Must not block.
76 //
77 // TODO(jamiewalch): Plumb the callback into the RequestPairing flow so
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;
50 82
51 // Retrieve the Pairing for the specified client id. If none is 83 // Retrieve the Pairing for the specified client id. If none is found,
52 // found, invoke the callback with a Pairing in which (at least) 84 // invoke the callback with a default pairing. Must not block.
53 // the shared_secret is empty.
54 virtual void GetPairing(const std::string& client_id, 85 virtual void GetPairing(const std::string& client_id,
55 const GetPairingCallback& callback) = 0; 86 const GetPairingCallback& callback) = 0;
56 }; 87 };
57 88
58 explicit PairingRegistry(scoped_ptr<Delegate> delegate); 89 explicit PairingRegistry(scoped_ptr<Delegate> delegate);
59 90
60 // Create a pairing for a new client and save it to disk. 91 // Create a pairing for a new client and save it to disk.
61 Pairing CreatePairing(const std::string& client_name); 92 Pairing CreatePairing(const std::string& client_name);
62 93
63 // Get the pairing for the specified client id. See the corresponding 94 // Get the pairing for the specified client id. See the corresponding
64 // Delegate method for details. 95 // Delegate method for details.
65 void GetPairing(const std::string& client_id, 96 void GetPairing(const std::string& client_id,
66 const GetPairingCallback& callback); 97 const GetPairingCallback& callback);
67 98
68 private: 99 private:
69 friend class base::RefCountedThreadSafe<PairingRegistry>; 100 friend class base::RefCountedThreadSafe<PairingRegistry>;
70 101
71 virtual ~PairingRegistry(); 102 virtual ~PairingRegistry();
72 103
73 scoped_ptr<Delegate> delegate_; 104 scoped_ptr<Delegate> delegate_;
74 105
75 DISALLOW_COPY_AND_ASSIGN(PairingRegistry); 106 DISALLOW_COPY_AND_ASSIGN(PairingRegistry);
76 }; 107 };
77 108
78 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save. 109 // Temporary delegate that just logs NOTIMPLEMENTED for Load/Save.
79 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms. 110 // TODO(jamiewalch): Delete once Delegates are implemented for all platforms.
80 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate { 111 class NotImplementedPairingRegistryDelegate : public PairingRegistry::Delegate {
81 public: 112 public:
82 virtual void AddPairing( 113 virtual void AddPairing(
83 const PairingRegistry::Pairing& paired_clients) OVERRIDE; 114 const PairingRegistry::Pairing& paired_clients,
115 const PairingRegistry::AddPairingCallback& callback) OVERRIDE;
84 virtual void GetPairing( 116 virtual void GetPairing(
85 const std::string& client_id, 117 const std::string& client_id,
86 const PairingRegistry::GetPairingCallback& callback) OVERRIDE; 118 const PairingRegistry::GetPairingCallback& callback) OVERRIDE;
87 }; 119 };
88 120
89 } // namespace protocol 121 } // namespace protocol
90 } // namespace remoting 122 } // namespace remoting
91 123
92 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_H_ 124 #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