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

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: 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
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: " << remote_device.GetDeviceId();
318 return; 322 return;
319 } 323 }
320 324
325 if (connection_metadata->HasSecureChannel()) {
326 PA_LOG(WARNING) << "Received another advertisement from a registered "
327 << "device which is already being actively communicated "
328 << "with. Bluetooth address: " << device_address
329 << ", Remote Device ID: " << remote_device.GetDeviceId();
Kyle Horimoto 2017/04/06 21:17:30 Truncate the device ID.
Ryan Hansberry 2017/04/06 22:14:59 Done for here and the log above as well.
330 return;
331 }
332
321 PA_LOG(INFO) << "Received advertisement from device with ID " 333 PA_LOG(INFO) << "Received advertisement from device with ID "
322 << remote_device.GetTruncatedDeviceIdForLogs() << ". " 334 << remote_device.GetTruncatedDeviceIdForLogs() << ". "
323 << "Starting authentication handshake to that device."; 335 << "Starting authentication handshake to that device.";
324 336
325 // Create a connection to that device. 337 // Create a connection to that device.
326 std::unique_ptr<cryptauth::Connection> connection = 338 std::unique_ptr<cryptauth::Connection> connection =
327 cryptauth::weave::BluetoothLowEnergyWeaveClientConnection::Factory:: 339 cryptauth::weave::BluetoothLowEnergyWeaveClientConnection::Factory::
328 NewInstance(remote_device, device_address, adapter_, 340 NewInstance(remote_device, device_address, adapter_,
329 device::BluetoothUUID(std::string(kGattServerUuid)), 341 device::BluetoothUUID(std::string(kGattServerUuid)),
330 bluetooth_throttler_); 342 bluetooth_throttler_);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 << cryptauth::SecureChannel::StatusToString(new_status); 501 << cryptauth::SecureChannel::StatusToString(new_status);
490 for (auto& observer : observer_list_) { 502 for (auto& observer : observer_list_) {
491 observer.OnSecureChannelStatusChanged(remote_device, old_status, 503 observer.OnSecureChannelStatusChanged(remote_device, old_status,
492 new_status); 504 new_status);
493 } 505 }
494 } 506 }
495 507
496 } // namespace tether 508 } // namespace tether
497 509
498 } // namespace chromeos 510 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698