Loading adb/Android.bp +46 −2 Original line number Diff line number Diff line Loading @@ -225,9 +225,11 @@ cc_library_host_static { srcs: libadb_srcs + [ "client/auth.cpp", "client/adb_wifi.cpp", "client/usb_libusb.cpp", "client/usb_dispatch.cpp", "client/transport_mdns.cpp", "client/pairing/pairing_client.cpp", ], generated_headers: ["platform_tools_version"], Loading Loading @@ -257,6 +259,8 @@ cc_library_host_static { static_libs: [ "libadb_crypto", "libadb_protos", "libadb_pairing_connection", "libadb_tls_connection", "libbase", "libcrypto_utils", "libcrypto", Loading @@ -266,6 +270,7 @@ cc_library_host_static { "libutils", "liblog", "libcutils", "libprotobuf-cpp-lite", ], } Loading @@ -274,8 +279,12 @@ cc_test_host { defaults: ["adb_defaults"], srcs: libadb_test_srcs, static_libs: [ "libadb_crypto", "libadb_crypto_static", "libadb_host", "libadb_pairing_auth_static", "libadb_pairing_connection_static", "libadb_protos_static", "libadb_tls_connection_static", "libbase", "libcutils", "libcrypto_utils", Loading @@ -283,6 +292,8 @@ cc_test_host { "liblog", "libmdnssd", "libdiagnose_usb", "libprotobuf-cpp-lite", "libssl", "libusb", ], Loading Loading @@ -314,12 +325,16 @@ cc_benchmark { }, static_libs: [ "libadb_crypto_static", "libadb_tls_connection_static", "libadbd_auth", "libbase", "libcutils", "libcrypto_utils", "libcrypto_static", "libdiagnose_usb", "liblog", "libssl", "libusb", ], } Loading Loading @@ -354,6 +369,10 @@ cc_binary_host { static_libs: [ "libadb_crypto", "libadb_host", "libadb_pairing_auth", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libandroidfw", "libbase", "libcutils", Loading @@ -365,6 +384,7 @@ cc_binary_host { "liblz4", "libmdnssd", "libprotobuf-cpp-lite", "libssl", "libusb", "libutils", "liblog", Loading Loading @@ -415,6 +435,7 @@ cc_library_static { srcs: libadb_srcs + libadb_linux_srcs + libadb_posix_srcs + [ "daemon/auth.cpp", "daemon/jdwp_service.cpp", "daemon/adb_wifi.cpp", ], local_include_dirs: [ Loading @@ -430,6 +451,9 @@ cc_library_static { shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libadbd_auth", "libasyncio", "libbase", Loading Loading @@ -484,6 +508,10 @@ cc_library { ], shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libadbd_auth", "libasyncio", "libbase", Loading Loading @@ -532,6 +560,9 @@ cc_library { ], shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_tls_connection", "libadbd_auth", "libadbd_services", "libasyncio", Loading Loading @@ -580,9 +611,14 @@ cc_binary { "libmdnssd", "libminijail", "libselinux", "libssl", ], shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libadbd_auth", "libcrypto", ], Loading Loading @@ -659,6 +695,9 @@ cc_test { static_libs: [ "libadbd", "libadbd_auth", "libadb_crypto_static", "libadb_pairing_connection_static", "libadb_tls_connection_static", "libbase", "libcutils", "libcrypto_utils", Loading Loading @@ -773,8 +812,12 @@ cc_test_host { "fastdeploy/deploypatchgenerator/patch_utils_test.cpp", ], static_libs: [ "libadb_crypto", "libadb_crypto_static", "libadb_host", "libadb_pairing_auth_static", "libadb_pairing_connection_static", "libadb_protos_static", "libadb_tls_connection_static", "libandroidfw", "libbase", "libcutils", Loading @@ -785,6 +828,7 @@ cc_test_host { "liblog", "libmdnssd", "libprotobuf-cpp-lite", "libssl", "libusb", "libutils", "libziparchive", Loading adb/adb.cpp +32 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ #include "adb_listeners.h" #include "adb_unique_fd.h" #include "adb_utils.h" #include "adb_wifi.h" #include "sysdeps/chrono.h" #include "transport.h" Loading Loading @@ -140,6 +141,9 @@ void print_packet(const char *label, apacket *p) case A_CLSE: tag = "CLSE"; break; case A_WRTE: tag = "WRTE"; break; case A_AUTH: tag = "AUTH"; break; case A_STLS: tag = "ATLS"; break; default: tag = "????"; break; } Loading Loading @@ -209,6 +213,15 @@ std::string get_connection_string() { android::base::Join(connection_properties, ';').c_str()); } void send_tls_request(atransport* t) { D("Calling send_tls_request"); apacket* p = get_apacket(); p->msg.command = A_STLS; p->msg.arg0 = A_STLS_VERSION; p->msg.data_length = 0; send_packet(p, t); } void send_connect(atransport* t) { D("Calling send_connect"); apacket* cp = get_apacket(); Loading Loading @@ -299,7 +312,12 @@ static void handle_new_connection(atransport* t, apacket* p) { #if ADB_HOST handle_online(t); #else if (!auth_required) { if (t->use_tls) { // We still handshake in TLS mode. If auth_required is disabled, // we'll just not verify the client's certificate. This should be the // first packet the client receives to indicate the new protocol. send_tls_request(t); } else if (!auth_required) { LOG(INFO) << "authentication not required"; handle_online(t); send_connect(t); Loading @@ -324,8 +342,21 @@ void handle_packet(apacket *p, atransport *t) case A_CNXN: // CONNECT(version, maxdata, "system-id-string") handle_new_connection(t, p); break; case A_STLS: // TLS(version, "") t->use_tls = true; #if ADB_HOST send_tls_request(t); adb_auth_tls_handshake(t); #else adbd_auth_tls_handshake(t); #endif break; case A_AUTH: // All AUTH commands are ignored in TLS mode if (t->use_tls) { break; } switch (p->msg.arg0) { #if ADB_HOST case ADB_AUTH_TOKEN: Loading adb/adb.h +6 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304; #define A_CLSE 0x45534c43 #define A_WRTE 0x45545257 #define A_AUTH 0x48545541 #define A_STLS 0x534C5453 // ADB protocol version. // Version revision: Loading @@ -53,6 +54,10 @@ constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304; #define A_VERSION_SKIP_CHECKSUM 0x01000001 #define A_VERSION 0x01000001 // Stream-based TLS protocol version #define A_STLS_VERSION_MIN 0x01000000 #define A_STLS_VERSION 0x01000000 // Used for help/version information. #define ADB_VERSION_MAJOR 1 #define ADB_VERSION_MINOR 0 Loading Loading @@ -229,6 +234,7 @@ void handle_online(atransport* t); void handle_offline(atransport* t); void send_connect(atransport* t); void send_tls_request(atransport* t); void parse_banner(const std::string&, atransport* t); Loading adb/adb_auth.h +8 −0 Original line number Diff line number Diff line Loading @@ -38,10 +38,14 @@ void adb_auth_init(); int adb_auth_keygen(const char* filename); int adb_auth_pubkey(const char* filename); std::string adb_auth_get_userkey(); bssl::UniquePtr<EVP_PKEY> adb_auth_get_user_privkey(); std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys(); void send_auth_response(const char* token, size_t token_size, atransport* t); int adb_tls_set_certificate(SSL* ssl); void adb_auth_tls_handshake(atransport* t); #else // !ADB_HOST extern bool auth_required; Loading @@ -57,6 +61,10 @@ void adbd_notify_framework_connected_key(atransport* t); void send_auth_request(atransport *t); void adbd_auth_tls_handshake(atransport* t); int adbd_tls_verify_cert(X509_STORE_CTX* ctx, std::string* auth_key); bssl::UniquePtr<STACK_OF(X509_NAME)> adbd_tls_client_ca_list(); #endif // ADB_HOST #endif // __ADB_AUTH_H adb/adb_wifi.h 0 → 100644 +37 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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. */ #pragma once #include <string> #include "adb.h" #if ADB_HOST void adb_wifi_init(void); void adb_wifi_pair_device(const std::string& host, const std::string& password, std::string& response); bool adb_wifi_is_known_host(const std::string& host); #else // !ADB_HOST struct AdbdAuthContext; void adbd_wifi_init(AdbdAuthContext* ctx); void adbd_wifi_secure_connect(atransport* t); #endif Loading
adb/Android.bp +46 −2 Original line number Diff line number Diff line Loading @@ -225,9 +225,11 @@ cc_library_host_static { srcs: libadb_srcs + [ "client/auth.cpp", "client/adb_wifi.cpp", "client/usb_libusb.cpp", "client/usb_dispatch.cpp", "client/transport_mdns.cpp", "client/pairing/pairing_client.cpp", ], generated_headers: ["platform_tools_version"], Loading Loading @@ -257,6 +259,8 @@ cc_library_host_static { static_libs: [ "libadb_crypto", "libadb_protos", "libadb_pairing_connection", "libadb_tls_connection", "libbase", "libcrypto_utils", "libcrypto", Loading @@ -266,6 +270,7 @@ cc_library_host_static { "libutils", "liblog", "libcutils", "libprotobuf-cpp-lite", ], } Loading @@ -274,8 +279,12 @@ cc_test_host { defaults: ["adb_defaults"], srcs: libadb_test_srcs, static_libs: [ "libadb_crypto", "libadb_crypto_static", "libadb_host", "libadb_pairing_auth_static", "libadb_pairing_connection_static", "libadb_protos_static", "libadb_tls_connection_static", "libbase", "libcutils", "libcrypto_utils", Loading @@ -283,6 +292,8 @@ cc_test_host { "liblog", "libmdnssd", "libdiagnose_usb", "libprotobuf-cpp-lite", "libssl", "libusb", ], Loading Loading @@ -314,12 +325,16 @@ cc_benchmark { }, static_libs: [ "libadb_crypto_static", "libadb_tls_connection_static", "libadbd_auth", "libbase", "libcutils", "libcrypto_utils", "libcrypto_static", "libdiagnose_usb", "liblog", "libssl", "libusb", ], } Loading Loading @@ -354,6 +369,10 @@ cc_binary_host { static_libs: [ "libadb_crypto", "libadb_host", "libadb_pairing_auth", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libandroidfw", "libbase", "libcutils", Loading @@ -365,6 +384,7 @@ cc_binary_host { "liblz4", "libmdnssd", "libprotobuf-cpp-lite", "libssl", "libusb", "libutils", "liblog", Loading Loading @@ -415,6 +435,7 @@ cc_library_static { srcs: libadb_srcs + libadb_linux_srcs + libadb_posix_srcs + [ "daemon/auth.cpp", "daemon/jdwp_service.cpp", "daemon/adb_wifi.cpp", ], local_include_dirs: [ Loading @@ -430,6 +451,9 @@ cc_library_static { shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libadbd_auth", "libasyncio", "libbase", Loading Loading @@ -484,6 +508,10 @@ cc_library { ], shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libadbd_auth", "libasyncio", "libbase", Loading Loading @@ -532,6 +560,9 @@ cc_library { ], shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_tls_connection", "libadbd_auth", "libadbd_services", "libasyncio", Loading Loading @@ -580,9 +611,14 @@ cc_binary { "libmdnssd", "libminijail", "libselinux", "libssl", ], shared_libs: [ "libadb_crypto", "libadb_pairing_connection", "libadb_protos", "libadb_tls_connection", "libadbd_auth", "libcrypto", ], Loading Loading @@ -659,6 +695,9 @@ cc_test { static_libs: [ "libadbd", "libadbd_auth", "libadb_crypto_static", "libadb_pairing_connection_static", "libadb_tls_connection_static", "libbase", "libcutils", "libcrypto_utils", Loading Loading @@ -773,8 +812,12 @@ cc_test_host { "fastdeploy/deploypatchgenerator/patch_utils_test.cpp", ], static_libs: [ "libadb_crypto", "libadb_crypto_static", "libadb_host", "libadb_pairing_auth_static", "libadb_pairing_connection_static", "libadb_protos_static", "libadb_tls_connection_static", "libandroidfw", "libbase", "libcutils", Loading @@ -785,6 +828,7 @@ cc_test_host { "liblog", "libmdnssd", "libprotobuf-cpp-lite", "libssl", "libusb", "libutils", "libziparchive", Loading
adb/adb.cpp +32 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ #include "adb_listeners.h" #include "adb_unique_fd.h" #include "adb_utils.h" #include "adb_wifi.h" #include "sysdeps/chrono.h" #include "transport.h" Loading Loading @@ -140,6 +141,9 @@ void print_packet(const char *label, apacket *p) case A_CLSE: tag = "CLSE"; break; case A_WRTE: tag = "WRTE"; break; case A_AUTH: tag = "AUTH"; break; case A_STLS: tag = "ATLS"; break; default: tag = "????"; break; } Loading Loading @@ -209,6 +213,15 @@ std::string get_connection_string() { android::base::Join(connection_properties, ';').c_str()); } void send_tls_request(atransport* t) { D("Calling send_tls_request"); apacket* p = get_apacket(); p->msg.command = A_STLS; p->msg.arg0 = A_STLS_VERSION; p->msg.data_length = 0; send_packet(p, t); } void send_connect(atransport* t) { D("Calling send_connect"); apacket* cp = get_apacket(); Loading Loading @@ -299,7 +312,12 @@ static void handle_new_connection(atransport* t, apacket* p) { #if ADB_HOST handle_online(t); #else if (!auth_required) { if (t->use_tls) { // We still handshake in TLS mode. If auth_required is disabled, // we'll just not verify the client's certificate. This should be the // first packet the client receives to indicate the new protocol. send_tls_request(t); } else if (!auth_required) { LOG(INFO) << "authentication not required"; handle_online(t); send_connect(t); Loading @@ -324,8 +342,21 @@ void handle_packet(apacket *p, atransport *t) case A_CNXN: // CONNECT(version, maxdata, "system-id-string") handle_new_connection(t, p); break; case A_STLS: // TLS(version, "") t->use_tls = true; #if ADB_HOST send_tls_request(t); adb_auth_tls_handshake(t); #else adbd_auth_tls_handshake(t); #endif break; case A_AUTH: // All AUTH commands are ignored in TLS mode if (t->use_tls) { break; } switch (p->msg.arg0) { #if ADB_HOST case ADB_AUTH_TOKEN: Loading
adb/adb.h +6 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304; #define A_CLSE 0x45534c43 #define A_WRTE 0x45545257 #define A_AUTH 0x48545541 #define A_STLS 0x534C5453 // ADB protocol version. // Version revision: Loading @@ -53,6 +54,10 @@ constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304; #define A_VERSION_SKIP_CHECKSUM 0x01000001 #define A_VERSION 0x01000001 // Stream-based TLS protocol version #define A_STLS_VERSION_MIN 0x01000000 #define A_STLS_VERSION 0x01000000 // Used for help/version information. #define ADB_VERSION_MAJOR 1 #define ADB_VERSION_MINOR 0 Loading Loading @@ -229,6 +234,7 @@ void handle_online(atransport* t); void handle_offline(atransport* t); void send_connect(atransport* t); void send_tls_request(atransport* t); void parse_banner(const std::string&, atransport* t); Loading
adb/adb_auth.h +8 −0 Original line number Diff line number Diff line Loading @@ -38,10 +38,14 @@ void adb_auth_init(); int adb_auth_keygen(const char* filename); int adb_auth_pubkey(const char* filename); std::string adb_auth_get_userkey(); bssl::UniquePtr<EVP_PKEY> adb_auth_get_user_privkey(); std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys(); void send_auth_response(const char* token, size_t token_size, atransport* t); int adb_tls_set_certificate(SSL* ssl); void adb_auth_tls_handshake(atransport* t); #else // !ADB_HOST extern bool auth_required; Loading @@ -57,6 +61,10 @@ void adbd_notify_framework_connected_key(atransport* t); void send_auth_request(atransport *t); void adbd_auth_tls_handshake(atransport* t); int adbd_tls_verify_cert(X509_STORE_CTX* ctx, std::string* auth_key); bssl::UniquePtr<STACK_OF(X509_NAME)> adbd_tls_client_ca_list(); #endif // ADB_HOST #endif // __ADB_AUTH_H
adb/adb_wifi.h 0 → 100644 +37 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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. */ #pragma once #include <string> #include "adb.h" #if ADB_HOST void adb_wifi_init(void); void adb_wifi_pair_device(const std::string& host, const std::string& password, std::string& response); bool adb_wifi_is_known_host(const std::string& host); #else // !ADB_HOST struct AdbdAuthContext; void adbd_wifi_init(AdbdAuthContext* ctx); void adbd_wifi_secure_connect(atransport* t); #endif