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

Side by Side Diff: chromeos/components/tether/ble_connection_manager.cc

Issue 2804123002: BleConnectionManager: Check when receiving BLE advertisements if a SecureChannel already exists. No… (Closed)
Patch Set: khorimoto@ comments. Created 3 years, 8 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chromeos/components/tether/ble_connection_manager.h" 5 #include "chromeos/components/tether/ble_connection_manager.h"
6 6
7 #include "chromeos/components/tether/ble_constants.h" 7 #include "chromeos/components/tether/ble_constants.h"
8 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection. h" 8 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection. h"
9 #include "components/proximity_auth/logging/logging.h" 9 #include "components/proximity_auth/logging/logging.h"
10 #include "device/bluetooth/bluetooth_uuid.h" 10 #include "device/bluetooth/bluetooth_uuid.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 connection_attempt_timeout_timer_->Start( 94 connection_attempt_timeout_timer_->Start(
95 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_millis), 95 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_millis),
96 base::Bind(&ConnectionMetadata::OnConnectionAttemptTimeout, 96 base::Bind(&ConnectionMetadata::OnConnectionAttemptTimeout,
97 weak_ptr_factory_.GetWeakPtr())); 97 weak_ptr_factory_.GetWeakPtr()));
98 } 98 }
99 99
100 void BleConnectionManager::ConnectionMetadata::OnConnectionAttemptTimeout() { 100 void BleConnectionManager::ConnectionMetadata::OnConnectionAttemptTimeout() {
101 manager_->OnConnectionAttemptTimeout(remote_device_); 101 manager_->OnConnectionAttemptTimeout(remote_device_);
102 } 102 }
103 103
104 bool BleConnectionManager::ConnectionMetadata::HasSecureChannel() {
105 return secure_channel_ != nullptr;
106 }
107
104 void BleConnectionManager::ConnectionMetadata::SetSecureChannel( 108 void BleConnectionManager::ConnectionMetadata::SetSecureChannel(
105 std::unique_ptr<cryptauth::SecureChannel> secure_channel) { 109 std::unique_ptr<cryptauth::SecureChannel> secure_channel) {
106 DCHECK(!secure_channel_); 110 DCHECK(!secure_channel_);
107 111
108 // The connection has succeeded, so cancel the timeout. 112 // The connection has succeeded, so cancel the timeout.
109 connection_attempt_timeout_timer_->Stop(); 113 connection_attempt_timeout_timer_->Stop();
110 114
111 secure_channel_ = std::move(secure_channel); 115 secure_channel_ = std::move(secure_channel);
112 secure_channel_->AddObserver(this); 116 secure_channel_->AddObserver(this);
113 secure_channel_->Initialize(); 117 secure_channel_->Initialize();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 void BleConnectionManager::OnReceivedAdvertisementFromDevice( 311 void BleConnectionManager::OnReceivedAdvertisementFromDevice(
308 const std::string& device_address, 312 const std::string& device_address,
309 cryptauth::RemoteDevice remote_device) { 313 cryptauth::RemoteDevice remote_device) {
310 std::shared_ptr<ConnectionMetadata> connection_metadata = 314 std::shared_ptr<ConnectionMetadata> connection_metadata =
311 GetConnectionMetadata(remote_device); 315 GetConnectionMetadata(remote_device);
312 if (!connection_metadata) { 316 if (!connection_metadata) {
313 // If an advertisement is received from a device that is not registered, 317 // If an advertisement is received from a device that is not registered,
314 // ignore it. 318 // ignore it.
315 PA_LOG(WARNING) << "Received an advertisement from a device which is not " 319 PA_LOG(WARNING) << "Received an advertisement from a device which is not "
316 << "registered. Bluetooth address: " << device_address 320 << "registered. Bluetooth address: " << device_address
317 << ", Remote Device ID: " << remote_device.GetDeviceId(); 321 << ", Remote Device ID: "
322 << remote_device.GetTruncatedDeviceIdForLogs();
318 return; 323 return;
319 } 324 }
320 325
326 if (connection_metadata->HasSecureChannel()) {
327 PA_LOG(WARNING) << "Received another advertisement from a registered "
328 << "device which is already being actively communicated "
329 << "with. Bluetooth address: " << device_address
330 << ", Remote Device ID: "
331 << remote_device.GetTruncatedDeviceIdForLogs();
332 return;
333 }
334
321 PA_LOG(INFO) << "Received advertisement from device with ID " 335 PA_LOG(INFO) << "Received advertisement from device with ID "
322 << remote_device.GetTruncatedDeviceIdForLogs() << ". " 336 << remote_device.GetTruncatedDeviceIdForLogs() << ". "
323 << "Starting authentication handshake to that device."; 337 << "Starting authentication handshake to that device.";
324 338
325 // Create a connection to that device. 339 // Create a connection to that device.
326 std::unique_ptr<cryptauth::Connection> connection = 340 std::unique_ptr<cryptauth::Connection> connection =
327 cryptauth::weave::BluetoothLowEnergyWeaveClientConnection::Factory:: 341 cryptauth::weave::BluetoothLowEnergyWeaveClientConnection::Factory::
328 NewInstance(remote_device, device_address, adapter_, 342 NewInstance(remote_device, device_address, adapter_,
329 device::BluetoothUUID(std::string(kGattServerUuid)), 343 device::BluetoothUUID(std::string(kGattServerUuid)),
330 bluetooth_throttler_); 344 bluetooth_throttler_);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 << cryptauth::SecureChannel::StatusToString(new_status); 503 << cryptauth::SecureChannel::StatusToString(new_status);
490 for (auto& observer : observer_list_) { 504 for (auto& observer : observer_list_) {
491 observer.OnSecureChannelStatusChanged(remote_device, old_status, 505 observer.OnSecureChannelStatusChanged(remote_device, old_status,
492 new_status); 506 new_status);
493 } 507 }
494 } 508 }
495 509
496 } // namespace tether 510 } // namespace tether
497 511
498 } // namespace chromeos 512 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/ble_connection_manager.h ('k') | chromeos/components/tether/ble_connection_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698