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 #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 bool PairingRegistry::Pairing::operator==(const Pairing& other) const { | |
|
Lambros
2013/05/31 18:51:59
nit: move this below const int kKeySize (or move c
Jamie
2013/06/19 17:56:44
Done.
| |
| 16 return created_time == other.created_time && | |
| 17 client_id == other.client_id && | |
| 18 client_name == other.client_name && | |
| 19 shared_secret == other.shared_secret; | |
| 20 } | |
| 21 | |
| 15 // How many bytes of random data to use for the client id and shared secret. | 22 // How many bytes of random data to use for the client id and shared secret. |
| 16 const int kKeySize = 16; | 23 const int kKeySize = 16; |
| 17 | 24 |
| 18 PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate, | 25 PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate, |
| 19 const PairedClients& paired_clients) | 26 const PairedClients& paired_clients) |
| 20 : delegate_(delegate.Pass()) { | 27 : delegate_(delegate.Pass()) { |
| 21 DCHECK(delegate_); | 28 DCHECK(delegate_); |
| 22 paired_clients_ = paired_clients; | 29 paired_clients_ = paired_clients; |
| 23 } | 30 } |
| 24 | 31 |
| 25 PairingRegistry::~PairingRegistry() { | 32 PairingRegistry::~PairingRegistry() { |
| 26 } | 33 } |
| 27 | 34 |
| 28 const PairingRegistry::Pairing& PairingRegistry::CreatePairing( | 35 const PairingRegistry::Pairing& PairingRegistry::CreatePairing( |
| 29 const std::string& client_name) { | 36 const std::string& client_name) { |
| 30 DCHECK(CalledOnValidThread()); | 37 DCHECK(CalledOnValidThread()); |
| 31 | 38 |
| 32 Pairing result; | 39 Pairing result; |
| 40 result.created_time = base::Time::Now(); | |
| 33 result.client_name = client_name; | 41 result.client_name = client_name; |
| 34 result.client_id = base::GenerateGUID(); | 42 result.client_id = base::GenerateGUID(); |
| 35 | 43 |
| 36 // Create a random shared secret to authenticate this client. | 44 // Create a random shared secret to authenticate this client. |
| 37 char buffer[kKeySize]; | 45 char buffer[kKeySize]; |
| 38 crypto::RandBytes(buffer, arraysize(buffer)); | 46 crypto::RandBytes(buffer, arraysize(buffer)); |
| 39 result.shared_secret = std::string(buffer, buffer+arraysize(buffer)); | 47 result.shared_secret = std::string(buffer, buffer+arraysize(buffer)); |
| 40 | 48 |
| 41 // Save the result via the Delegate and return it to the caller. | 49 // Save the result via the Delegate and return it to the caller. |
| 42 paired_clients_[result.client_id] = result; | 50 paired_clients_[result.client_id] = result; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 54 result = i->second.shared_secret; | 62 result = i->second.shared_secret; |
| 55 } | 63 } |
| 56 return result; | 64 return result; |
| 57 } | 65 } |
| 58 | 66 |
| 59 void NotImplementedPairingRegistryDelegate::Save( | 67 void NotImplementedPairingRegistryDelegate::Save( |
| 60 const PairingRegistry::PairedClients& paired_clients) { | 68 const PairingRegistry::PairedClients& paired_clients) { |
| 61 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
| 62 }; | 70 }; |
| 63 | 71 |
| 72 PairingRegistry::PairedClients | |
| 73 NotImplementedPairingRegistryDelegate::LoadOnCurrentThread() { | |
| 74 NOTIMPLEMENTED(); | |
| 75 return PairingRegistry::PairedClients(); | |
| 76 } | |
| 77 | |
| 64 } // namespace protocol | 78 } // namespace protocol |
| 65 } // namespace remoting | 79 } // namespace remoting |
| OLD | NEW |