2011-03-16 23:57:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TRANSPORT_H
|
|
|
|
#define __TRANSPORT_H
|
|
|
|
|
2015-02-19 03:03:26 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
#include <atomic>
|
2018-04-17 23:25:04 +02:00
|
|
|
#include <chrono>
|
2018-02-16 22:24:58 +01:00
|
|
|
#include <condition_variable>
|
2016-06-30 02:42:01 +02:00
|
|
|
#include <deque>
|
2016-10-27 23:01:08 +02:00
|
|
|
#include <functional>
|
2015-08-29 00:09:44 +02:00
|
|
|
#include <list>
|
2016-08-19 07:00:12 +02:00
|
|
|
#include <memory>
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
#include <mutex>
|
2015-04-17 07:54:44 +02:00
|
|
|
#include <string>
|
2019-01-05 03:51:11 +01:00
|
|
|
#include <string_view>
|
2018-02-16 22:24:58 +01:00
|
|
|
#include <thread>
|
2020-03-27 02:19:28 +01:00
|
|
|
#include <vector>
|
2015-02-25 00:51:19 +01:00
|
|
|
|
2018-04-17 23:25:04 +02:00
|
|
|
#include <android-base/macros.h>
|
2018-04-03 21:55:18 +02:00
|
|
|
#include <android-base/thread_annotations.h>
|
2016-06-30 02:42:01 +02:00
|
|
|
#include <openssl/rsa.h>
|
|
|
|
|
2018-01-29 05:32:46 +01:00
|
|
|
#include "adb.h"
|
|
|
|
#include "adb_unique_fd.h"
|
2019-12-10 00:44:57 +01:00
|
|
|
#include "types.h"
|
2018-01-29 05:32:46 +01:00
|
|
|
|
2020-03-27 02:19:28 +01:00
|
|
|
// Even though the feature set is used as a set, we only have a dozen or two
|
|
|
|
// of available features at any moment. Vector works much better in terms of
|
|
|
|
// both memory usage and performance for these sizes.
|
|
|
|
using FeatureSet = std::vector<std::string>;
|
2015-05-18 22:06:53 +02:00
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
namespace adb {
|
|
|
|
namespace tls {
|
|
|
|
|
|
|
|
class TlsConnection;
|
|
|
|
|
|
|
|
} // namespace tls
|
|
|
|
} // namespace adb
|
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
const FeatureSet& supported_features();
|
|
|
|
|
2015-09-22 19:43:08 +02:00
|
|
|
// Encodes and decodes FeatureSet objects into human-readable strings.
|
|
|
|
std::string FeatureSetToString(const FeatureSet& features);
|
|
|
|
FeatureSet StringToFeatureSet(const std::string& features_string);
|
|
|
|
|
2015-09-30 22:35:42 +02:00
|
|
|
// Returns true if both local features and |feature_set| support |feature|.
|
|
|
|
bool CanUseFeature(const FeatureSet& feature_set, const std::string& feature);
|
|
|
|
|
2015-09-22 19:43:08 +02:00
|
|
|
// Do not use any of [:;=,] in feature strings, they have special meaning
|
|
|
|
// in the connection banner.
|
2015-11-04 01:53:08 +01:00
|
|
|
extern const char* const kFeatureShell2;
|
|
|
|
// The 'cmd' command is available
|
|
|
|
extern const char* const kFeatureCmd;
|
2016-12-06 02:11:34 +01:00
|
|
|
extern const char* const kFeatureStat2;
|
2019-08-07 23:23:17 +02:00
|
|
|
extern const char* const kFeatureLs2;
|
2017-02-23 02:07:01 +01:00
|
|
|
// The server is running with libusb enabled.
|
|
|
|
extern const char* const kFeatureLibusb;
|
2018-10-22 22:00:05 +02:00
|
|
|
// adbd supports `push --sync`.
|
2017-05-23 23:30:00 +02:00
|
|
|
extern const char* const kFeaturePushSync;
|
2018-10-22 22:00:05 +02:00
|
|
|
// adbd supports installing .apex packages.
|
2018-10-04 17:26:40 +02:00
|
|
|
extern const char* const kFeatureApex;
|
2018-10-22 22:00:05 +02:00
|
|
|
// adbd has b/110953234 fixed.
|
|
|
|
extern const char* const kFeatureFixedPushMkdir;
|
2019-09-13 23:19:01 +02:00
|
|
|
// adbd supports android binder bridge (abb) in interactive mode using shell protocol.
|
2019-01-17 22:13:56 +01:00
|
|
|
extern const char* const kFeatureAbb;
|
2019-09-13 23:19:01 +02:00
|
|
|
// adbd supports abb using raw pipe.
|
|
|
|
extern const char* const kFeatureAbbExec;
|
2019-02-20 22:01:40 +01:00
|
|
|
// adbd properly updates symlink timestamps on push.
|
|
|
|
extern const char* const kFeatureFixedPushSymlinkTimestamp;
|
2020-03-05 04:34:08 +01:00
|
|
|
// Implement `adb remount` via shelling out to /system/bin/remount.
|
2019-07-11 23:15:32 +02:00
|
|
|
extern const char* const kFeatureRemountShell;
|
2020-02-14 02:01:39 +01:00
|
|
|
// adbd supports `track-app` service reporting debuggable/profileable apps.
|
|
|
|
extern const char* const kFeatureTrackApp;
|
2020-03-05 04:34:08 +01:00
|
|
|
// adbd supports version 2 of send/recv.
|
|
|
|
extern const char* const kFeatureSendRecv2;
|
|
|
|
// adbd supports brotli for send/recv v2.
|
|
|
|
extern const char* const kFeatureSendRecv2Brotli;
|
2020-03-27 06:02:03 +01:00
|
|
|
// adbd supports LZ4 for send/recv v2.
|
|
|
|
extern const char* const kFeatureSendRecv2LZ4;
|
2020-05-28 02:52:52 +02:00
|
|
|
// adbd supports Zstd for send/recv v2.
|
|
|
|
extern const char* const kFeatureSendRecv2Zstd;
|
2020-03-31 08:25:16 +02:00
|
|
|
// adbd supports dry-run send for send/recv v2.
|
|
|
|
extern const char* const kFeatureSendRecv2DryRunSend;
|
2015-08-31 19:42:13 +02:00
|
|
|
|
2017-08-17 01:57:01 +02:00
|
|
|
TransportId NextTransportId();
|
|
|
|
|
2018-02-16 22:24:58 +01:00
|
|
|
// Abstraction for a non-blocking packet transport.
|
2018-01-29 05:32:46 +01:00
|
|
|
struct Connection {
|
|
|
|
Connection() = default;
|
|
|
|
virtual ~Connection() = default;
|
|
|
|
|
2018-02-16 22:24:58 +01:00
|
|
|
void SetTransportName(std::string transport_name) {
|
|
|
|
transport_name_ = std::move(transport_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
using ReadCallback = std::function<bool(Connection*, std::unique_ptr<apacket>)>;
|
|
|
|
void SetReadCallback(ReadCallback callback) {
|
|
|
|
CHECK(!read_callback_);
|
|
|
|
read_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called after the Connection has terminated, either by an error or because Stop was called.
|
|
|
|
using ErrorCallback = std::function<void(Connection*, const std::string&)>;
|
|
|
|
void SetErrorCallback(ErrorCallback callback) {
|
|
|
|
CHECK(!error_callback_);
|
|
|
|
error_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Write(std::unique_ptr<apacket> packet) = 0;
|
|
|
|
|
|
|
|
virtual void Start() = 0;
|
|
|
|
virtual void Stop() = 0;
|
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
virtual bool DoTlsHandshake(RSA* key, std::string* auth_key = nullptr) = 0;
|
|
|
|
|
2019-03-28 23:47:44 +01:00
|
|
|
// Stop, and reset the device if it's a USB connection.
|
|
|
|
virtual void Reset();
|
|
|
|
|
2018-02-16 22:24:58 +01:00
|
|
|
std::string transport_name_;
|
|
|
|
ReadCallback read_callback_;
|
|
|
|
ErrorCallback error_callback_;
|
2018-04-06 01:16:04 +02:00
|
|
|
|
|
|
|
static std::unique_ptr<Connection> FromFd(unique_fd fd);
|
2018-02-16 22:24:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Abstraction for a blocking packet transport.
|
|
|
|
struct BlockingConnection {
|
|
|
|
BlockingConnection() = default;
|
|
|
|
BlockingConnection(const BlockingConnection& copy) = delete;
|
|
|
|
BlockingConnection(BlockingConnection&& move) = delete;
|
|
|
|
|
|
|
|
// Destroy a BlockingConnection. Formerly known as 'Close' in atransport.
|
|
|
|
virtual ~BlockingConnection() = default;
|
|
|
|
|
2018-01-29 05:32:46 +01:00
|
|
|
// Read/Write a packet. These functions are concurrently called from a transport's reader/writer
|
|
|
|
// threads.
|
|
|
|
virtual bool Read(apacket* packet) = 0;
|
|
|
|
virtual bool Write(apacket* packet) = 0;
|
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
virtual bool DoTlsHandshake(RSA* key, std::string* auth_key = nullptr) = 0;
|
|
|
|
|
2018-01-29 05:32:46 +01:00
|
|
|
// Terminate a connection.
|
|
|
|
// This method must be thread-safe, and must cause concurrent Reads/Writes to terminate.
|
|
|
|
// Formerly known as 'Kick' in atransport.
|
|
|
|
virtual void Close() = 0;
|
2019-03-28 23:47:44 +01:00
|
|
|
|
|
|
|
// Terminate a connection, and reset it.
|
|
|
|
virtual void Reset() = 0;
|
2018-01-29 05:32:46 +01:00
|
|
|
};
|
|
|
|
|
2018-02-16 22:24:58 +01:00
|
|
|
struct BlockingConnectionAdapter : public Connection {
|
|
|
|
explicit BlockingConnectionAdapter(std::unique_ptr<BlockingConnection> connection);
|
|
|
|
|
|
|
|
virtual ~BlockingConnectionAdapter();
|
|
|
|
|
|
|
|
virtual bool Write(std::unique_ptr<apacket> packet) override final;
|
|
|
|
|
|
|
|
virtual void Start() override final;
|
|
|
|
virtual void Stop() override final;
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
virtual bool DoTlsHandshake(RSA* key, std::string* auth_key) override final;
|
2018-02-16 22:24:58 +01:00
|
|
|
|
2019-03-28 23:47:44 +01:00
|
|
|
virtual void Reset() override final;
|
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
private:
|
|
|
|
void StartReadThread() REQUIRES(mutex_);
|
2018-04-03 21:55:18 +02:00
|
|
|
bool started_ GUARDED_BY(mutex_) = false;
|
|
|
|
bool stopped_ GUARDED_BY(mutex_) = false;
|
2018-02-16 22:24:58 +01:00
|
|
|
|
|
|
|
std::unique_ptr<BlockingConnection> underlying_;
|
2018-04-03 21:55:18 +02:00
|
|
|
std::thread read_thread_ GUARDED_BY(mutex_);
|
|
|
|
std::thread write_thread_ GUARDED_BY(mutex_);
|
2018-02-16 22:24:58 +01:00
|
|
|
|
2018-04-03 21:55:18 +02:00
|
|
|
std::deque<std::unique_ptr<apacket>> write_queue_ GUARDED_BY(mutex_);
|
2018-02-16 22:24:58 +01:00
|
|
|
std::mutex mutex_;
|
|
|
|
std::condition_variable cv_;
|
|
|
|
|
|
|
|
std::once_flag error_flag_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FdConnection : public BlockingConnection {
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
explicit FdConnection(unique_fd fd);
|
|
|
|
~FdConnection();
|
2018-01-29 05:32:46 +01:00
|
|
|
|
|
|
|
bool Read(apacket* packet) override final;
|
|
|
|
bool Write(apacket* packet) override final;
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
bool DoTlsHandshake(RSA* key, std::string* auth_key) override final;
|
2018-01-29 05:32:46 +01:00
|
|
|
|
|
|
|
void Close() override;
|
2019-03-28 23:47:44 +01:00
|
|
|
virtual void Reset() override final { Close(); }
|
2018-01-29 05:32:46 +01:00
|
|
|
|
|
|
|
private:
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
bool DispatchRead(void* buf, size_t len);
|
|
|
|
bool DispatchWrite(void* buf, size_t len);
|
|
|
|
|
2018-01-29 05:32:46 +01:00
|
|
|
unique_fd fd_;
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
std::unique_ptr<adb::tls::TlsConnection> tls_;
|
2018-01-29 05:32:46 +01:00
|
|
|
};
|
|
|
|
|
2018-04-17 23:25:04 +02:00
|
|
|
// Waits for a transport's connection to be not pending. This is a separate
|
|
|
|
// object so that the transport can be destroyed and another thread can be
|
|
|
|
// notified of it in a race-free way.
|
|
|
|
class ConnectionWaitable {
|
|
|
|
public:
|
|
|
|
ConnectionWaitable() = default;
|
|
|
|
~ConnectionWaitable() = default;
|
|
|
|
|
|
|
|
// Waits until the first CNXN packet has been received by the owning
|
|
|
|
// atransport, or the specified timeout has elapsed. Can be called from any
|
|
|
|
// thread.
|
|
|
|
//
|
|
|
|
// Returns true if the CNXN packet was received in a timely fashion, false
|
|
|
|
// otherwise.
|
|
|
|
bool WaitForConnection(std::chrono::milliseconds timeout);
|
|
|
|
|
|
|
|
// Can be called from any thread when the connection stops being pending.
|
|
|
|
// Only the first invocation will be acknowledged, the rest will be no-ops.
|
|
|
|
void SetConnectionEstablished(bool success);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool connection_established_ GUARDED_BY(mutex_) = false;
|
|
|
|
bool connection_established_ready_ GUARDED_BY(mutex_) = false;
|
|
|
|
std::mutex mutex_;
|
|
|
|
std::condition_variable cv_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ConnectionWaitable);
|
|
|
|
};
|
|
|
|
|
2018-08-30 20:37:00 +02:00
|
|
|
enum class ReconnectResult {
|
|
|
|
Retry,
|
|
|
|
Success,
|
|
|
|
Abort,
|
|
|
|
};
|
|
|
|
|
2020-03-28 02:09:56 +01:00
|
|
|
#if ADB_HOST
|
|
|
|
struct usb_handle;
|
|
|
|
#endif
|
|
|
|
|
2019-12-10 00:44:57 +01:00
|
|
|
class atransport : public enable_weak_from_this<atransport> {
|
2017-08-17 01:57:01 +02:00
|
|
|
public:
|
2015-05-18 22:06:53 +02:00
|
|
|
// TODO(danalbert): We expose waaaaaaay too much stuff because this was
|
|
|
|
// historically just a struct, but making the whole thing a more idiomatic
|
|
|
|
// class in one go is a very large change. Given how bad our testing is,
|
|
|
|
// it's better to do this piece by piece.
|
|
|
|
|
2018-08-30 20:37:00 +02:00
|
|
|
using ReconnectCallback = std::function<ReconnectResult(atransport*)>;
|
2018-04-20 19:31:29 +02:00
|
|
|
|
|
|
|
atransport(ReconnectCallback reconnect, ConnectionState state)
|
2018-04-17 23:25:04 +02:00
|
|
|
: id(NextTransportId()),
|
2018-04-20 19:31:29 +02:00
|
|
|
kicked_(false),
|
2018-04-17 23:25:04 +02:00
|
|
|
connection_state_(state),
|
2018-04-20 19:31:29 +02:00
|
|
|
connection_(nullptr),
|
|
|
|
reconnect_(std::move(reconnect)) {
|
2020-04-23 05:57:26 +02:00
|
|
|
#if ADB_HOST
|
|
|
|
connection_waitable_ = std::make_shared<ConnectionWaitable>();
|
|
|
|
#endif
|
|
|
|
|
2017-12-07 20:40:00 +01:00
|
|
|
// Initialize protocol to min version for compatibility with older versions.
|
|
|
|
// Version will be updated post-connect.
|
|
|
|
protocol_version = A_VERSION_MIN;
|
2015-05-18 22:06:53 +02:00
|
|
|
max_payload = MAX_PAYLOAD;
|
|
|
|
}
|
2018-04-20 19:31:29 +02:00
|
|
|
atransport(ConnectionState state = kCsOffline)
|
2018-08-30 20:37:00 +02:00
|
|
|
: atransport([](atransport*) { return ReconnectResult::Abort; }, state) {}
|
2019-12-10 00:44:57 +01:00
|
|
|
~atransport();
|
2015-05-18 22:06:53 +02:00
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
int Write(apacket* p);
|
2019-03-28 23:47:44 +01:00
|
|
|
void Reset();
|
2016-04-18 20:22:34 +02:00
|
|
|
void Kick();
|
2018-04-20 19:31:29 +02:00
|
|
|
bool kicked() const { return kicked_; }
|
2015-05-18 22:06:53 +02:00
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
// ConnectionState can be read by all threads, but can only be written in the main thread.
|
|
|
|
ConnectionState GetConnectionState() const;
|
|
|
|
void SetConnectionState(ConnectionState state);
|
|
|
|
|
2018-04-25 17:56:41 +02:00
|
|
|
void SetConnection(std::unique_ptr<Connection> connection);
|
|
|
|
std::shared_ptr<Connection> connection() {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
|
|
return connection_;
|
|
|
|
}
|
|
|
|
|
2020-03-28 02:09:56 +01:00
|
|
|
#if ADB_HOST
|
2018-12-11 22:11:52 +01:00
|
|
|
void SetUsbHandle(usb_handle* h) { usb_handle_ = h; }
|
|
|
|
usb_handle* GetUsbHandle() { return usb_handle_; }
|
2020-03-28 02:09:56 +01:00
|
|
|
#endif
|
2018-12-11 22:11:52 +01:00
|
|
|
|
2017-08-17 01:57:01 +02:00
|
|
|
const TransportId id;
|
2019-12-09 22:45:31 +01:00
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
bool online = false;
|
|
|
|
TransportType type = kTransportAny;
|
|
|
|
|
|
|
|
// Used to identify transports for clients.
|
2018-07-19 06:18:27 +02:00
|
|
|
std::string serial;
|
|
|
|
std::string product;
|
|
|
|
std::string model;
|
|
|
|
std::string device;
|
|
|
|
std::string devpath;
|
2016-04-30 01:53:52 +02:00
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
// If this is set, the transport will initiate the connection with a
|
|
|
|
// START_TLS command, instead of AUTH.
|
|
|
|
bool use_tls = false;
|
|
|
|
int tls_version = A_STLS_VERSION;
|
|
|
|
int get_tls_version() const;
|
|
|
|
|
2019-10-22 21:30:39 +02:00
|
|
|
#if !ADB_HOST
|
2019-04-26 03:33:35 +02:00
|
|
|
// Used to provide the key to the framework.
|
|
|
|
std::string auth_key;
|
2019-10-22 21:30:39 +02:00
|
|
|
uint64_t auth_id;
|
|
|
|
#endif
|
2019-04-26 03:33:35 +02:00
|
|
|
|
2018-01-29 05:32:46 +01:00
|
|
|
bool IsTcpDevice() const { return type == kTransportLocal; }
|
2015-05-18 22:06:53 +02:00
|
|
|
|
2016-10-06 04:02:29 +02:00
|
|
|
#if ADB_HOST
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
// The current key being authorized.
|
|
|
|
std::shared_ptr<RSA> Key();
|
2016-08-19 07:00:12 +02:00
|
|
|
std::shared_ptr<RSA> NextKey();
|
2018-12-04 10:07:50 +01:00
|
|
|
void ResetKeys();
|
2016-10-06 04:02:29 +02:00
|
|
|
#endif
|
2016-06-30 02:42:01 +02:00
|
|
|
|
2016-10-06 22:31:44 +02:00
|
|
|
char token[TOKEN_SIZE] = {};
|
2015-05-18 22:06:53 +02:00
|
|
|
size_t failed_auth_attempts = 0;
|
|
|
|
|
2018-07-19 06:18:27 +02:00
|
|
|
std::string serial_name() const { return !serial.empty() ? serial : "<unknown>"; }
|
2018-02-28 23:44:23 +01:00
|
|
|
std::string connection_state_name() const;
|
2015-05-18 22:06:53 +02:00
|
|
|
|
|
|
|
void update_version(int version, size_t payload);
|
|
|
|
int get_protocol_version() const;
|
|
|
|
size_t get_max_payload() const;
|
|
|
|
|
2015-09-22 19:43:08 +02:00
|
|
|
const FeatureSet& features() const {
|
2015-05-18 22:06:53 +02:00
|
|
|
return features_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_feature(const std::string& feature) const;
|
2015-09-22 19:43:08 +02:00
|
|
|
|
|
|
|
// Loads the transport's feature set from the given string.
|
|
|
|
void SetFeatures(const std::string& features_string);
|
2015-05-18 22:06:53 +02:00
|
|
|
|
2015-08-29 00:09:44 +02:00
|
|
|
void AddDisconnect(adisconnect* disconnect);
|
|
|
|
void RemoveDisconnect(adisconnect* disconnect);
|
|
|
|
void RunDisconnects();
|
|
|
|
|
2020-04-23 05:57:26 +02:00
|
|
|
#if ADB_HOST
|
2016-03-01 17:58:26 +01:00
|
|
|
// Returns true if |target| matches this transport. A matching |target| can be any of:
|
|
|
|
// * <serial>
|
|
|
|
// * <devpath>
|
|
|
|
// * product:<product>
|
|
|
|
// * model:<model>
|
|
|
|
// * device:<device>
|
|
|
|
//
|
|
|
|
// If this is a local transport, serial will also match [tcp:|udp:]<hostname>[:port] targets.
|
|
|
|
// For example, serial "100.100.100.100:5555" would match any of:
|
|
|
|
// * 100.100.100.100
|
|
|
|
// * tcp:100.100.100.100
|
|
|
|
// * udp:100.100.100.100:5555
|
|
|
|
// This is to make it easier to use the same network target for both fastboot and adb.
|
|
|
|
bool MatchesTarget(const std::string& target) const;
|
|
|
|
|
2018-04-17 23:25:04 +02:00
|
|
|
// Notifies that the atransport is no longer waiting for the connection
|
|
|
|
// being established.
|
|
|
|
void SetConnectionEstablished(bool success);
|
|
|
|
|
|
|
|
// Gets a shared reference to the ConnectionWaitable.
|
|
|
|
std::shared_ptr<ConnectionWaitable> connection_waitable() { return connection_waitable_; }
|
|
|
|
|
2018-08-30 20:37:00 +02:00
|
|
|
// Attempts to reconnect with the underlying Connection.
|
|
|
|
ReconnectResult Reconnect();
|
2020-04-23 05:57:26 +02:00
|
|
|
#endif
|
2018-04-20 19:31:29 +02:00
|
|
|
|
2018-04-17 23:25:04 +02:00
|
|
|
private:
|
2018-04-20 19:31:29 +02:00
|
|
|
std::atomic<bool> kicked_;
|
2016-04-18 20:22:34 +02:00
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
// A set of features transmitted in the banner with the initial connection.
|
|
|
|
// This is stored in the banner as 'features=feature0,feature1,etc'.
|
|
|
|
FeatureSet features_;
|
|
|
|
int protocol_version;
|
|
|
|
size_t max_payload;
|
|
|
|
|
2015-08-29 00:09:44 +02:00
|
|
|
// A list of adisconnect callbacks called when the transport is kicked.
|
|
|
|
std::list<adisconnect*> disconnects_;
|
|
|
|
|
adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.
1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.
The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.
2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.
The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.
To be safe, this patch doesn't change any logic on device.
Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-03-11 01:01:01 +01:00
|
|
|
std::atomic<ConnectionState> connection_state_;
|
2016-10-06 04:02:29 +02:00
|
|
|
#if ADB_HOST
|
2016-08-19 07:00:12 +02:00
|
|
|
std::deque<std::shared_ptr<RSA>> keys_;
|
2016-10-06 04:02:29 +02:00
|
|
|
#endif
|
2016-06-30 02:42:01 +02:00
|
|
|
|
2020-04-23 05:57:26 +02:00
|
|
|
#if ADB_HOST
|
2018-04-17 23:25:04 +02:00
|
|
|
// A sharable object that can be used to wait for the atransport's
|
|
|
|
// connection to be established.
|
|
|
|
std::shared_ptr<ConnectionWaitable> connection_waitable_;
|
2020-04-23 05:57:26 +02:00
|
|
|
#endif
|
2018-04-17 23:25:04 +02:00
|
|
|
|
2018-04-25 17:56:41 +02:00
|
|
|
// The underlying connection object.
|
|
|
|
std::shared_ptr<Connection> connection_ GUARDED_BY(mutex_);
|
|
|
|
|
2020-03-28 02:09:56 +01:00
|
|
|
#if ADB_HOST
|
2018-12-11 22:11:52 +01:00
|
|
|
// USB handle for the connection, if available.
|
|
|
|
usb_handle* usb_handle_ = nullptr;
|
2020-03-28 02:09:56 +01:00
|
|
|
#endif
|
2018-12-11 22:11:52 +01:00
|
|
|
|
2018-04-20 19:31:29 +02:00
|
|
|
// A callback that will be invoked when the atransport needs to reconnect.
|
|
|
|
ReconnectCallback reconnect_;
|
|
|
|
|
2018-04-25 17:56:41 +02:00
|
|
|
std::mutex mutex_;
|
|
|
|
|
2015-05-18 22:06:53 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(atransport);
|
|
|
|
};
|
|
|
|
|
2015-02-25 00:51:19 +01:00
|
|
|
/*
|
|
|
|
* Obtain a transport from the available transports.
|
2015-10-07 23:55:10 +02:00
|
|
|
* If serial is non-null then only the device with that serial will be chosen.
|
2017-08-17 01:57:01 +02:00
|
|
|
* If transport_id is non-zero then only the device with that transport ID will be chosen.
|
2015-10-07 23:55:10 +02:00
|
|
|
* If multiple devices/emulators would match, *is_ambiguous (if non-null)
|
|
|
|
* is set to true and nullptr returned.
|
|
|
|
* If no suitable transport is found, error is set and nullptr returned.
|
2015-02-25 00:51:19 +01:00
|
|
|
*/
|
2017-08-17 01:57:01 +02:00
|
|
|
atransport* acquire_one_transport(TransportType type, const char* serial, TransportId transport_id,
|
|
|
|
bool* is_ambiguous, std::string* error_out,
|
|
|
|
bool accept_any_state = false);
|
2019-03-28 23:47:44 +01:00
|
|
|
void kick_transport(atransport* t, bool reset = false);
|
2015-02-25 00:51:19 +01:00
|
|
|
void update_transports(void);
|
|
|
|
|
2017-05-04 07:37:10 +02:00
|
|
|
// Iterates across all of the current and pending transports.
|
|
|
|
// Stops iteration and returns false if fn returns false, otherwise returns true.
|
|
|
|
bool iterate_transports(std::function<bool(const atransport*)> fn);
|
|
|
|
|
2018-04-20 19:31:29 +02:00
|
|
|
void init_reconnect_handler(void);
|
2015-02-25 00:51:19 +01:00
|
|
|
void init_transport_registration(void);
|
2016-06-23 23:19:37 +02:00
|
|
|
void init_mdns_transport_discovery(void);
|
2015-05-01 02:32:03 +02:00
|
|
|
std::string list_transports(bool long_listing);
|
2020-04-23 05:57:26 +02:00
|
|
|
|
|
|
|
#if ADB_HOST
|
2015-02-25 00:51:19 +01:00
|
|
|
atransport* find_transport(const char* serial);
|
2020-04-23 05:57:26 +02:00
|
|
|
|
2015-08-27 21:03:11 +02:00
|
|
|
void kick_all_tcp_devices();
|
2020-04-23 05:57:26 +02:00
|
|
|
#endif
|
|
|
|
|
2017-05-09 22:43:35 +02:00
|
|
|
void kick_all_transports();
|
2020-04-23 05:57:26 +02:00
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
void kick_all_tcp_tls_transports();
|
2020-04-23 05:57:26 +02:00
|
|
|
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
#if !ADB_HOST
|
|
|
|
void kick_all_transports_by_auth_key(std::string_view auth_key);
|
|
|
|
#endif
|
2015-02-25 00:51:19 +01:00
|
|
|
|
adbd: implement a nonblocking USB Connection.
Implement a Connection that implements a nonblocking interface to
functionfs, to replace the existing implementation that uses two
threads that loop and call read and write respectively. The existing
implementation is vulnerable to a race condition that can occur when a
connection is terminated, where one thread can notice failure and
complete reinitialization of the USB endpoints before the other thread
noticed anything went wrong, resulting in either the first packet
coming from the other end disappearing in to the void, or the other end
getting a packet of garbage.
As a side benefit, this improves performance on walleye from:
push 100MiB: 10 runs: median 49.48 MiB/s, mean 50.00 MiB/s, stddev: 2.77 MiB/s
pull 100MiB: 10 runs: median 75.82 MiB/s, mean 76.18 MiB/s, stddev: 6.60 MiB/s
to:
push 100MiB: 10 runs: median 73.90 MiB/s, mean 73.51 MiB/s, stddev: 5.26 MiB/s
pull 100MiB: 10 runs: median 105.90 MiB/s, mean 107.19 MiB/s, stddev: 6.10 MiB/s
Test: python test_device.py
Change-Id: I9b77c1057965edfef739ed9736e5d76613adf60a
2018-10-12 01:33:05 +02:00
|
|
|
void register_transport(atransport* transport);
|
2020-03-28 02:09:56 +01:00
|
|
|
|
|
|
|
#if ADB_HOST
|
|
|
|
void init_usb_transport(atransport* t, usb_handle* usb);
|
|
|
|
void register_usb_transport(usb_handle* h, const char* serial, const char* devpath,
|
|
|
|
unsigned writeable);
|
|
|
|
|
|
|
|
// This should only be used for transports with connection_state == kCsNoPerm.
|
|
|
|
void unregister_usb_transport(usb_handle* usb);
|
|
|
|
#endif
|
2015-02-25 00:51:19 +01:00
|
|
|
|
2016-06-23 23:19:37 +02:00
|
|
|
/* Connect to a network address and register it as a device */
|
|
|
|
void connect_device(const std::string& address, std::string* response);
|
|
|
|
|
2015-02-25 00:51:19 +01:00
|
|
|
/* cause new transports to be init'd and added to the list */
|
2018-08-09 01:20:14 +02:00
|
|
|
bool register_socket_transport(unique_fd s, std::string serial, int port, int local,
|
[adbwifi] Add A_STLS command.
This command will be sent by adbd to notify the client that the
connection will be over TLS.
When client connects, it will send the CNXN packet, as usual. If the
server connection has TLS enabled, it will send the A_STLS packet
(regardless of whether auth is required). At this point, the client's
only valid response is to send a A_STLS packet. Once both sides have
exchanged the A_STLS packet, both will start the TLS handshake.
If auth is required, then the client will receive a CertificateRequest
with a list of known public keys (SHA256 hash) that it can use in its
certificate. Otherwise, the list will be empty and the client can assume
that either any key will work, or none will work.
If the handshake was successful, the server will send the CNXN packet
and the usual adb protocol is resumed over TLS. If the handshake failed,
both sides will disconnect, as there's no point to retry because the
server's known keys have already been communicated.
Bug: 111434128
Test: WIP; will add to adb_test.py/adb_device.py.
Enable wireless debugging in the Settings, then 'adb connect
<ip>:<port>'. Connection should succeed if key is in keystore. Used
wireshark to check for packet encryption.
Change-Id: I3d60647491c6c6b92297e4f628707a6457fa9420
2020-01-21 22:19:42 +01:00
|
|
|
atransport::ReconnectCallback reconnect, bool use_tls,
|
|
|
|
int* error = nullptr);
|
2015-02-25 00:51:19 +01:00
|
|
|
|
2017-05-17 00:02:45 +02:00
|
|
|
bool check_header(apacket* p, atransport* t);
|
2015-02-25 00:51:19 +01:00
|
|
|
|
2019-03-28 23:47:44 +01:00
|
|
|
void close_usb_devices(bool reset = false);
|
|
|
|
void close_usb_devices(std::function<bool(const atransport*)> predicate, bool reset = false);
|
2015-02-25 00:51:19 +01:00
|
|
|
|
|
|
|
void send_packet(apacket* p, atransport* t);
|
|
|
|
|
2017-08-15 03:57:54 +02:00
|
|
|
asocket* create_device_tracker(bool long_output);
|
2015-02-25 00:51:19 +01:00
|
|
|
|
2019-01-23 04:36:15 +01:00
|
|
|
#if !ADB_HOST
|
2019-07-19 05:44:39 +02:00
|
|
|
unique_fd adb_listen(std::string_view addr, std::string* error);
|
|
|
|
void server_socket_thread(std::function<unique_fd(std::string_view, std::string*)> listen_func,
|
|
|
|
std::string_view addr);
|
2019-01-23 04:36:15 +01:00
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
2019-07-19 05:44:39 +02:00
|
|
|
void qemu_socket_thread(std::string_view addr);
|
2019-01-23 04:36:15 +01:00
|
|
|
bool use_qemu_goldfish();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-03-16 23:57:42 +01:00
|
|
|
#endif /* __TRANSPORT_H */
|