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 #include "remoting/protocol/pairing_registry.h" | 5 #include "remoting/protocol/pairing_registry.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "crypto/random.h" | 10 #include "crypto/random.h" |
11 | 11 |
12 namespace remoting { | 12 namespace remoting { |
13 namespace protocol { | 13 namespace protocol { |
14 | 14 |
15 // How many bytes of random data to use for the client id and shared secret. | 15 // How many bytes of random data to use for the client id and shared secret. |
16 const int kKeySize = 16; | 16 const int kKeySize = 16; |
17 | 17 |
18 PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate, | 18 PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate) |
19 const PairedClients& paired_clients) | |
20 : delegate_(delegate.Pass()) { | 19 : delegate_(delegate.Pass()) { |
21 DCHECK(delegate_); | 20 DCHECK(delegate_); |
22 paired_clients_ = paired_clients; | |
23 } | 21 } |
24 | 22 |
25 PairingRegistry::~PairingRegistry() { | 23 PairingRegistry::~PairingRegistry() { |
26 } | 24 } |
27 | 25 |
28 const PairingRegistry::Pairing& PairingRegistry::CreatePairing( | 26 PairingRegistry::Pairing PairingRegistry::CreatePairing( |
rmsousa
2013/06/13 04:26:19
Not for current CL:
This is now a very thin layer
Jamie
2013/06/13 17:22:15
That's true. At one point there was some code here
| |
29 const std::string& client_name) { | 27 const std::string& client_name) { |
30 DCHECK(CalledOnValidThread()); | 28 DCHECK(CalledOnValidThread()); |
31 | 29 |
32 Pairing result; | 30 Pairing result; |
33 result.client_name = client_name; | 31 result.client_name = client_name; |
34 result.client_id = base::GenerateGUID(); | 32 result.client_id = base::GenerateGUID(); |
35 | 33 |
36 // Create a random shared secret to authenticate this client. | 34 // Create a random shared secret to authenticate this client. |
37 char buffer[kKeySize]; | 35 char buffer[kKeySize]; |
38 crypto::RandBytes(buffer, arraysize(buffer)); | 36 crypto::RandBytes(buffer, arraysize(buffer)); |
39 if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), | 37 if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), |
40 &result.shared_secret)) { | 38 &result.shared_secret)) { |
41 LOG(FATAL) << "Base64Encode failed."; | 39 LOG(FATAL) << "Base64Encode failed."; |
42 } | 40 } |
43 | 41 |
44 // Save the result via the Delegate and return it to the caller. | 42 // Save the result via the Delegate and return it to the caller. |
45 paired_clients_[result.client_id] = result; | 43 delegate_->AddPairing(result); |
46 delegate_->Save(paired_clients_); | |
47 | |
48 return paired_clients_[result.client_id]; | |
49 } | |
50 | |
51 std::string PairingRegistry::GetSecret(const std::string& client_id) const { | |
52 DCHECK(CalledOnValidThread()); | |
53 | |
54 std::string result; | |
55 PairedClients::const_iterator i = paired_clients_.find(client_id); | |
56 if (i != paired_clients_.end()) { | |
57 result = i->second.shared_secret; | |
58 } | |
59 return result; | 44 return result; |
60 } | 45 } |
61 | 46 |
62 void NotImplementedPairingRegistryDelegate::Save( | 47 void PairingRegistry::GetPairing(const std::string& client_id, |
63 const PairingRegistry::PairedClients& paired_clients) { | 48 const GetPairingCallback& callback) { |
49 DCHECK(CalledOnValidThread()); | |
50 delegate_->GetPairing(client_id, callback); | |
51 } | |
52 | |
53 void NotImplementedPairingRegistryDelegate::AddPairing( | |
54 const PairingRegistry::Pairing& new_paired_client) { | |
64 NOTIMPLEMENTED(); | 55 NOTIMPLEMENTED(); |
65 } | 56 } |
66 | 57 |
58 void NotImplementedPairingRegistryDelegate::GetPairing( | |
59 const std::string& client_id, | |
60 const PairingRegistry::GetPairingCallback& callback) { | |
61 NOTIMPLEMENTED(); | |
62 callback.Run(PairingRegistry::Pairing()); | |
63 } | |
64 | |
65 | |
67 } // namespace protocol | 66 } // namespace protocol |
68 } // namespace remoting | 67 } // namespace remoting |
OLD | NEW |