Loading adb/adb.cpp +18 −20 Original line number Diff line number Diff line Loading @@ -53,8 +53,6 @@ #include <sys/mount.h> #endif ADB_MUTEX_DEFINE(D_lock); #if !ADB_HOST const char* adb_device_banner = "device"; static android::base::LogdLogger gLogdLogger; Loading Loading @@ -184,7 +182,7 @@ static void setup_trace_mask() { for (const auto& elem : elements) { const auto& flag = trace_flags.find(elem); if (flag == trace_flags.end()) { D("Unknown trace flag: %s\n", flag->first.c_str()); D("Unknown trace flag: %s", flag->first.c_str()); continue; } Loading Loading @@ -234,13 +232,13 @@ void put_apacket(apacket *p) void handle_online(atransport *t) { D("adb: online\n"); D("adb: online"); t->online = 1; } void handle_offline(atransport *t) { D("adb: offline\n"); D("adb: offline"); //Close the associated usb t->online = 0; Loading Loading @@ -294,7 +292,7 @@ void print_packet(const char *label, apacket *p) static void send_ready(unsigned local, unsigned remote, atransport *t) { D("Calling send_ready \n"); D("Calling send_ready"); apacket *p = get_apacket(); p->msg.command = A_OKAY; p->msg.arg0 = local; Loading @@ -304,7 +302,7 @@ static void send_ready(unsigned local, unsigned remote, atransport *t) static void send_close(unsigned local, unsigned remote, atransport *t) { D("Calling send_close \n"); D("Calling send_close"); apacket *p = get_apacket(); p->msg.command = A_CLSE; p->msg.arg0 = local; Loading Loading @@ -339,7 +337,7 @@ std::string get_connection_string() { } void send_connect(atransport* t) { D("Calling send_connect \n"); D("Calling send_connect"); apacket* cp = get_apacket(); cp->msg.command = A_CNXN; cp->msg.arg0 = t->get_protocol_version(); Loading Loading @@ -369,7 +367,7 @@ static void qual_overwrite(char** dst, const std::string& src) { } void parse_banner(const std::string& banner, atransport* t) { D("parse_banner: %s\n", banner.c_str()); D("parse_banner: %s", banner.c_str()); // The format is something like: // "device::ro.product.name=x;ro.product.model=y;ro.product.device=z;". Loading Loading @@ -402,23 +400,23 @@ void parse_banner(const std::string& banner, atransport* t) { const std::string& type = pieces[0]; if (type == "bootloader") { D("setting connection_state to kCsBootloader\n"); D("setting connection_state to kCsBootloader"); t->connection_state = kCsBootloader; update_transports(); } else if (type == "device") { D("setting connection_state to kCsDevice\n"); D("setting connection_state to kCsDevice"); t->connection_state = kCsDevice; update_transports(); } else if (type == "recovery") { D("setting connection_state to kCsRecovery\n"); D("setting connection_state to kCsRecovery"); t->connection_state = kCsRecovery; update_transports(); } else if (type == "sideload") { D("setting connection_state to kCsSideload\n"); D("setting connection_state to kCsSideload"); t->connection_state = kCsSideload; update_transports(); } else { D("setting connection_state to kCsHost\n"); D("setting connection_state to kCsHost"); t->connection_state = kCsHost; } } Loading Loading @@ -450,7 +448,7 @@ void handle_packet(apacket *p, atransport *t) { asocket *s; D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0], D("handle_packet() %c%c%c%c", ((char*) (&(p->msg.command)))[0], ((char*) (&(p->msg.command)))[1], ((char*) (&(p->msg.command)))[2], ((char*) (&(p->msg.command)))[3]); Loading Loading @@ -526,7 +524,7 @@ void handle_packet(apacket *p, atransport *t) /* Other READY messages must use the same local-id */ s->ready(s); } else { D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s\n", D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s", p->msg.arg0, p->msg.arg1, s->peer->id, p->msg.arg1, t->serial); } } Loading @@ -547,7 +545,7 @@ void handle_packet(apacket *p, atransport *t) * socket has a peer on the same transport. */ if (p->msg.arg0 == 0 && s->peer && s->peer->transport != t) { D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s\n", D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s", p->msg.arg1, t->serial, s->peer->transport->serial); } else { s->close(s); Loading @@ -563,7 +561,7 @@ void handle_packet(apacket *p, atransport *t) p->len = p->msg.data_length; if(s->enqueue(s, p) == 0) { D("Enqueue the socket\n"); D("Enqueue the socket"); send_ready(s->id, rid, t); } return; Loading Loading @@ -1125,9 +1123,9 @@ int handle_host_request(const char* service, TransportType type, if (!strncmp(service, "devices", 7)) { bool long_listing = (strcmp(service+7, "-l") == 0); if (long_listing || service[7] == 0) { D("Getting device list...\n"); D("Getting device list..."); std::string device_list = list_transports(long_listing); D("Sending device list...\n"); D("Sending device list..."); return SendOkay(reply_fd, device_list); } return 1; Loading adb/adb_auth.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -32,13 +32,13 @@ bool auth_required = true; void send_auth_request(atransport *t) { D("Calling send_auth_request\n"); D("Calling send_auth_request"); apacket *p; int ret; ret = adb_auth_generate_token(t->token, sizeof(t->token)); if (ret != sizeof(t->token)) { D("Error generating token ret=%d\n", ret); D("Error generating token ret=%d", ret); return; } Loading @@ -52,13 +52,13 @@ void send_auth_request(atransport *t) void send_auth_response(uint8_t *token, size_t token_size, atransport *t) { D("Calling send_auth_response\n"); D("Calling send_auth_response"); apacket *p = get_apacket(); int ret; ret = adb_auth_sign(t->key, token, token_size, p->data); if (!ret) { D("Error signing the token\n"); D("Error signing the token"); put_apacket(p); return; } Loading @@ -71,13 +71,13 @@ void send_auth_response(uint8_t *token, size_t token_size, atransport *t) void send_auth_publickey(atransport *t) { D("Calling send_auth_publickey\n"); D("Calling send_auth_publickey"); apacket *p = get_apacket(); int ret; ret = adb_auth_get_userkey(p->data, MAX_PAYLOAD_V1); if (!ret) { D("Failed to get user public key\n"); D("Failed to get user public key"); put_apacket(p); return; } Loading adb/adb_auth_client.cpp +16 −16 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ static void read_keys(const char *file, struct listnode *list) f = fopen(file, "re"); if (!f) { D("Can't open '%s'\n", file); D("Can't open '%s'", file); return; } Loading @@ -69,7 +69,7 @@ static void read_keys(const char *file, struct listnode *list) auto key = reinterpret_cast<adb_public_key*>( calloc(1, sizeof(adb_public_key) + 4)); if (key == nullptr) { D("Can't malloc key\n"); D("Can't malloc key"); break; } Loading @@ -79,13 +79,13 @@ static void read_keys(const char *file, struct listnode *list) ret = __b64_pton(buf, (u_char *)&key->key, sizeof(key->key) + 4); if (ret != sizeof(key->key)) { D("%s: Invalid base64 data ret=%d\n", file, ret); D("%s: Invalid base64 data ret=%d", file, ret); free(key); continue; } if (key->key.len != RSANUMWORDS) { D("%s: Invalid key len %d\n", file, key->key.len); D("%s: Invalid key len %d", file, key->key.len); free(key); continue; } Loading Loading @@ -117,7 +117,7 @@ static void load_keys(struct listnode *list) while ((path = *paths++)) { if (!stat(path, &buf)) { D("Loading keys from '%s'\n", path); D("Loading keys from '%s'", path); read_keys(path, list); } } Loading Loading @@ -163,7 +163,7 @@ int adb_auth_verify(uint8_t* token, uint8_t* sig, int siglen) static void usb_disconnected(void* unused, atransport* t) { D("USB disconnect\n"); D("USB disconnect"); usb_transport = NULL; needs_retry = false; } Loading @@ -176,7 +176,7 @@ static void adb_auth_event(int fd, unsigned events, void *data) if (events & FDE_READ) { ret = unix_read(fd, response, sizeof(response)); if (ret <= 0) { D("Framework disconnect\n"); D("Framework disconnect"); if (usb_transport) fdevent_remove(&usb_transport->auth_fde); framework_fd = -1; Loading @@ -199,26 +199,26 @@ void adb_auth_confirm_key(unsigned char *key, size_t len, atransport *t) } if (framework_fd < 0) { D("Client not connected\n"); D("Client not connected"); needs_retry = true; return; } if (key[len - 1] != '\0') { D("Key must be a null-terminated string\n"); D("Key must be a null-terminated string"); return; } ret = snprintf(msg, sizeof(msg), "PK%s", key); if (ret >= (signed)sizeof(msg)) { D("Key too long. ret=%d\n", ret); D("Key too long. ret=%d", ret); return; } D("Sending '%s'\n", msg); D("Sending '%s'", msg); ret = unix_write(framework_fd, msg, ret); if (ret < 0) { D("Failed to write PK, errno=%d\n", errno); D("Failed to write PK, errno=%d", errno); return; } Loading @@ -236,7 +236,7 @@ static void adb_auth_listener(int fd, unsigned events, void *data) s = adb_socket_accept(fd, &addr, &alen); if (s < 0) { D("Failed to accept: errno=%d\n", errno); D("Failed to accept: errno=%d", errno); return; } Loading @@ -251,7 +251,7 @@ static void adb_auth_listener(int fd, unsigned events, void *data) void adbd_cloexec_auth_socket() { int fd = android_get_control_socket("adbd"); if (fd == -1) { D("Failed to get adbd socket\n"); D("Failed to get adbd socket"); return; } fcntl(fd, F_SETFD, FD_CLOEXEC); Loading @@ -260,12 +260,12 @@ void adbd_cloexec_auth_socket() { void adbd_auth_init(void) { int fd = android_get_control_socket("adbd"); if (fd == -1) { D("Failed to get adbd socket\n"); D("Failed to get adbd socket"); return; } if (listen(fd, 4) == -1) { D("Failed to listen on '%d'\n", fd); D("Failed to listen on '%d'", fd); return; } Loading adb/adb_auth_host.cpp +29 −29 Original line number Diff line number Diff line Loading @@ -164,26 +164,26 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path) if (snprintf(path, sizeof(path), "%s.pub", private_key_path) >= (int)sizeof(path)) { D("Path too long while writing public key\n"); D("Path too long while writing public key"); return 0; } if (!RSA_to_RSAPublicKey(private_key, &pkey)) { D("Failed to convert to publickey\n"); D("Failed to convert to publickey"); return 0; } outfile = fopen(path, "w"); if (!outfile) { D("Failed to open '%s'\n", path); D("Failed to open '%s'", path); return 0; } D("Writing public key to '%s'\n", path); D("Writing public key to '%s'", path); #if defined(OPENSSL_IS_BORINGSSL) if (!EVP_EncodedLength(&encoded_length, sizeof(pkey))) { D("Public key too large to base64 encode\n"); D("Public key too large to base64 encode"); goto out; } #else Loading @@ -194,7 +194,7 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path) encoded = new uint8_t[encoded_length]; if (encoded == nullptr) { D("Allocation failure\n"); D("Allocation failure"); goto out; } Loading @@ -203,7 +203,7 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path) if (fwrite(encoded, encoded_length, 1, outfile) != 1 || fwrite(info, strlen(info), 1, outfile) != 1) { D("Write error while writing public key\n"); D("Write error while writing public key"); goto out; } Loading @@ -226,10 +226,10 @@ static int generate_key(const char *file) FILE *f = NULL; int ret = 0; D("generate_key '%s'\n", file); D("generate_key '%s'", file); if (!pkey || !exponent || !rsa) { D("Failed to allocate key\n"); D("Failed to allocate key"); goto out; } Loading @@ -241,7 +241,7 @@ static int generate_key(const char *file) f = fopen(file, "w"); if (!f) { D("Failed to open '%s'\n", file); D("Failed to open '%s'", file); umask(old_mask); goto out; } Loading @@ -249,12 +249,12 @@ static int generate_key(const char *file) umask(old_mask); if (!PEM_write_PrivateKey(f, pkey, NULL, NULL, 0, NULL, NULL)) { D("Failed to write key\n"); D("Failed to write key"); goto out; } if (!write_public_keyfile(rsa, file)) { D("Failed to write public key\n"); D("Failed to write public key"); goto out; } Loading @@ -271,11 +271,11 @@ out: static int read_key(const char *file, struct listnode *list) { D("read_key '%s'\n", file); D("read_key '%s'", file); FILE* fp = fopen(file, "r"); if (!fp) { D("Failed to open '%s': %s\n", file, strerror(errno)); D("Failed to open '%s': %s", file, strerror(errno)); return 0; } Loading @@ -283,7 +283,7 @@ static int read_key(const char *file, struct listnode *list) key->rsa = RSA_new(); if (!PEM_read_RSAPrivateKey(fp, &key->rsa, NULL, NULL)) { D("Failed to read key\n"); D("Failed to read key"); fclose(fp); RSA_free(key->rsa); delete key; Loading @@ -307,7 +307,7 @@ static int get_user_keyfilepath(char *filename, size_t len) WCHAR path[MAX_PATH]; const HRESULT hr = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path); if (FAILED(hr)) { D("SHGetFolderPathW failed: %s\n", D("SHGetFolderPathW failed: %s", SystemErrorCodeToString(hr).c_str()); return -1; } Loading @@ -322,7 +322,7 @@ static int get_user_keyfilepath(char *filename, size_t len) format = "%s/%s"; #endif D("home '%s'\n", home); D("home '%s'", home); if (snprintf(android_dir, sizeof(android_dir), format, home, ANDROID_PATH) >= (int)sizeof(android_dir)) Loading @@ -330,7 +330,7 @@ static int get_user_keyfilepath(char *filename, size_t len) if (stat(android_dir, &buf)) { if (adb_mkdir(android_dir, 0750) < 0) { D("Cannot mkdir '%s'\n", android_dir); D("Cannot mkdir '%s'", android_dir); return -1; } } Loading @@ -346,15 +346,15 @@ static int get_user_key(struct listnode *list) ret = get_user_keyfilepath(path, sizeof(path)); if (ret < 0 || ret >= (signed)sizeof(path)) { D("Error getting user key filename\n"); D("Error getting user key filename"); return 0; } D("user key '%s'\n", path); D("user key '%s'", path); if (stat(path, &buf) == -1) { if (!generate_key(path)) { D("Failed to generate new key\n"); D("Failed to generate new key"); return 0; } } Loading @@ -370,7 +370,7 @@ static void get_vendor_keys(struct listnode* key_list) { for (auto& path : android::base::Split(adb_keys_path, ENV_PATH_SEPARATOR_STR)) { if (!read_key(path.c_str(), key_list)) { D("Failed to read '%s'\n", path.c_str()); D("Failed to read '%s'", path.c_str()); } } } Loading @@ -382,7 +382,7 @@ int adb_auth_sign(void *node, const unsigned char* token, size_t token_size, struct adb_private_key *key = node_to_item(node, struct adb_private_key, node); if (token_size != TOKEN_SIZE) { D("Unexpected token size %zd\n", token_size); D("Unexpected token size %zd", token_size); return 0; } Loading @@ -390,7 +390,7 @@ int adb_auth_sign(void *node, const unsigned char* token, size_t token_size, return 0; } D("adb_auth_sign len=%d\n", len); D("adb_auth_sign len=%d", len); return (int)len; } Loading Loading @@ -421,7 +421,7 @@ int adb_auth_get_userkey(unsigned char *data, size_t len) char path[PATH_MAX]; int ret = get_user_keyfilepath(path, sizeof(path) - 4); if (ret < 0 || ret >= (signed)(sizeof(path) - 4)) { D("Error getting user key filename\n"); D("Error getting user key filename"); return 0; } strcat(path, ".pub"); Loading @@ -433,12 +433,12 @@ int adb_auth_get_userkey(unsigned char *data, size_t len) unsigned size; char* file_data = reinterpret_cast<char*>(load_file(path, &size)); if (file_data == nullptr) { D("Can't load '%s'\n", path); D("Can't load '%s'", path); return 0; } if (len < (size_t)(size + 1)) { D("%s: Content too large ret=%d\n", path, size); D("%s: Content too large ret=%d", path, size); free(file_data); return 0; } Loading @@ -460,13 +460,13 @@ void adb_auth_init(void) { int ret; D("adb_auth_init\n"); D("adb_auth_init"); list_init(&key_list); ret = get_user_key(&key_list); if (!ret) { D("Failed to get user key\n"); D("Failed to get user key"); return; } Loading adb/adb_client.cpp +9 −9 Original line number Diff line number Diff line Loading @@ -90,14 +90,14 @@ static int switch_socket_transport(int fd, std::string* error) { adb_close(fd); return -1; } D("Switch transport in progress\n"); D("Switch transport in progress"); if (!adb_status(fd, error)) { adb_close(fd); D("Switch transport failed: %s\n", error->c_str()); D("Switch transport failed: %s", error->c_str()); return -1; } D("Switch transport success\n"); D("Switch transport success"); return 0; } Loading @@ -123,7 +123,7 @@ bool adb_status(int fd, std::string* error) { } int _adb_connect(const std::string& service, std::string* error) { D("_adb_connect: %s\n", service.c_str()); D("_adb_connect: %s", service.c_str()); if (service.empty() || service.size() > 1024) { *error = android::base::StringPrintf("bad service name length (%zd)", service.size()); Loading Loading @@ -164,7 +164,7 @@ int _adb_connect(const std::string& service, std::string* error) { return -1; } D("_adb_connect: return fd %d\n", fd); D("_adb_connect: return fd %d", fd); return fd; } Loading @@ -172,7 +172,7 @@ int adb_connect(const std::string& service, std::string* error) { // first query the adb server's version int fd = _adb_connect("host:version", error); D("adb_connect: service %s\n", service.c_str()); D("adb_connect: service %s", service.c_str()); if (fd == -2 && __adb_server_name) { fprintf(stderr,"** Cannot start server on remote host\n"); // error is the original network connection error Loading Loading @@ -246,11 +246,11 @@ int adb_connect(const std::string& service, std::string* error) { fd = _adb_connect(service, error); if (fd == -1) { D("_adb_connect error: %s\n", error->c_str()); D("_adb_connect error: %s", error->c_str()); } else if(fd == -2) { fprintf(stderr,"** daemon still not running\n"); } D("adb_connect: return fd %d\n", fd); D("adb_connect: return fd %d", fd); return fd; error: Loading @@ -277,7 +277,7 @@ bool adb_command(const std::string& service) { } bool adb_query(const std::string& service, std::string* result, std::string* error) { D("adb_query: %s\n", service.c_str()); D("adb_query: %s", service.c_str()); int fd = adb_connect(service, error); if (fd < 0) { return false; Loading Loading
adb/adb.cpp +18 −20 Original line number Diff line number Diff line Loading @@ -53,8 +53,6 @@ #include <sys/mount.h> #endif ADB_MUTEX_DEFINE(D_lock); #if !ADB_HOST const char* adb_device_banner = "device"; static android::base::LogdLogger gLogdLogger; Loading Loading @@ -184,7 +182,7 @@ static void setup_trace_mask() { for (const auto& elem : elements) { const auto& flag = trace_flags.find(elem); if (flag == trace_flags.end()) { D("Unknown trace flag: %s\n", flag->first.c_str()); D("Unknown trace flag: %s", flag->first.c_str()); continue; } Loading Loading @@ -234,13 +232,13 @@ void put_apacket(apacket *p) void handle_online(atransport *t) { D("adb: online\n"); D("adb: online"); t->online = 1; } void handle_offline(atransport *t) { D("adb: offline\n"); D("adb: offline"); //Close the associated usb t->online = 0; Loading Loading @@ -294,7 +292,7 @@ void print_packet(const char *label, apacket *p) static void send_ready(unsigned local, unsigned remote, atransport *t) { D("Calling send_ready \n"); D("Calling send_ready"); apacket *p = get_apacket(); p->msg.command = A_OKAY; p->msg.arg0 = local; Loading @@ -304,7 +302,7 @@ static void send_ready(unsigned local, unsigned remote, atransport *t) static void send_close(unsigned local, unsigned remote, atransport *t) { D("Calling send_close \n"); D("Calling send_close"); apacket *p = get_apacket(); p->msg.command = A_CLSE; p->msg.arg0 = local; Loading Loading @@ -339,7 +337,7 @@ std::string get_connection_string() { } void send_connect(atransport* t) { D("Calling send_connect \n"); D("Calling send_connect"); apacket* cp = get_apacket(); cp->msg.command = A_CNXN; cp->msg.arg0 = t->get_protocol_version(); Loading Loading @@ -369,7 +367,7 @@ static void qual_overwrite(char** dst, const std::string& src) { } void parse_banner(const std::string& banner, atransport* t) { D("parse_banner: %s\n", banner.c_str()); D("parse_banner: %s", banner.c_str()); // The format is something like: // "device::ro.product.name=x;ro.product.model=y;ro.product.device=z;". Loading Loading @@ -402,23 +400,23 @@ void parse_banner(const std::string& banner, atransport* t) { const std::string& type = pieces[0]; if (type == "bootloader") { D("setting connection_state to kCsBootloader\n"); D("setting connection_state to kCsBootloader"); t->connection_state = kCsBootloader; update_transports(); } else if (type == "device") { D("setting connection_state to kCsDevice\n"); D("setting connection_state to kCsDevice"); t->connection_state = kCsDevice; update_transports(); } else if (type == "recovery") { D("setting connection_state to kCsRecovery\n"); D("setting connection_state to kCsRecovery"); t->connection_state = kCsRecovery; update_transports(); } else if (type == "sideload") { D("setting connection_state to kCsSideload\n"); D("setting connection_state to kCsSideload"); t->connection_state = kCsSideload; update_transports(); } else { D("setting connection_state to kCsHost\n"); D("setting connection_state to kCsHost"); t->connection_state = kCsHost; } } Loading Loading @@ -450,7 +448,7 @@ void handle_packet(apacket *p, atransport *t) { asocket *s; D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0], D("handle_packet() %c%c%c%c", ((char*) (&(p->msg.command)))[0], ((char*) (&(p->msg.command)))[1], ((char*) (&(p->msg.command)))[2], ((char*) (&(p->msg.command)))[3]); Loading Loading @@ -526,7 +524,7 @@ void handle_packet(apacket *p, atransport *t) /* Other READY messages must use the same local-id */ s->ready(s); } else { D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s\n", D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s", p->msg.arg0, p->msg.arg1, s->peer->id, p->msg.arg1, t->serial); } } Loading @@ -547,7 +545,7 @@ void handle_packet(apacket *p, atransport *t) * socket has a peer on the same transport. */ if (p->msg.arg0 == 0 && s->peer && s->peer->transport != t) { D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s\n", D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s", p->msg.arg1, t->serial, s->peer->transport->serial); } else { s->close(s); Loading @@ -563,7 +561,7 @@ void handle_packet(apacket *p, atransport *t) p->len = p->msg.data_length; if(s->enqueue(s, p) == 0) { D("Enqueue the socket\n"); D("Enqueue the socket"); send_ready(s->id, rid, t); } return; Loading Loading @@ -1125,9 +1123,9 @@ int handle_host_request(const char* service, TransportType type, if (!strncmp(service, "devices", 7)) { bool long_listing = (strcmp(service+7, "-l") == 0); if (long_listing || service[7] == 0) { D("Getting device list...\n"); D("Getting device list..."); std::string device_list = list_transports(long_listing); D("Sending device list...\n"); D("Sending device list..."); return SendOkay(reply_fd, device_list); } return 1; Loading
adb/adb_auth.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -32,13 +32,13 @@ bool auth_required = true; void send_auth_request(atransport *t) { D("Calling send_auth_request\n"); D("Calling send_auth_request"); apacket *p; int ret; ret = adb_auth_generate_token(t->token, sizeof(t->token)); if (ret != sizeof(t->token)) { D("Error generating token ret=%d\n", ret); D("Error generating token ret=%d", ret); return; } Loading @@ -52,13 +52,13 @@ void send_auth_request(atransport *t) void send_auth_response(uint8_t *token, size_t token_size, atransport *t) { D("Calling send_auth_response\n"); D("Calling send_auth_response"); apacket *p = get_apacket(); int ret; ret = adb_auth_sign(t->key, token, token_size, p->data); if (!ret) { D("Error signing the token\n"); D("Error signing the token"); put_apacket(p); return; } Loading @@ -71,13 +71,13 @@ void send_auth_response(uint8_t *token, size_t token_size, atransport *t) void send_auth_publickey(atransport *t) { D("Calling send_auth_publickey\n"); D("Calling send_auth_publickey"); apacket *p = get_apacket(); int ret; ret = adb_auth_get_userkey(p->data, MAX_PAYLOAD_V1); if (!ret) { D("Failed to get user public key\n"); D("Failed to get user public key"); put_apacket(p); return; } Loading
adb/adb_auth_client.cpp +16 −16 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ static void read_keys(const char *file, struct listnode *list) f = fopen(file, "re"); if (!f) { D("Can't open '%s'\n", file); D("Can't open '%s'", file); return; } Loading @@ -69,7 +69,7 @@ static void read_keys(const char *file, struct listnode *list) auto key = reinterpret_cast<adb_public_key*>( calloc(1, sizeof(adb_public_key) + 4)); if (key == nullptr) { D("Can't malloc key\n"); D("Can't malloc key"); break; } Loading @@ -79,13 +79,13 @@ static void read_keys(const char *file, struct listnode *list) ret = __b64_pton(buf, (u_char *)&key->key, sizeof(key->key) + 4); if (ret != sizeof(key->key)) { D("%s: Invalid base64 data ret=%d\n", file, ret); D("%s: Invalid base64 data ret=%d", file, ret); free(key); continue; } if (key->key.len != RSANUMWORDS) { D("%s: Invalid key len %d\n", file, key->key.len); D("%s: Invalid key len %d", file, key->key.len); free(key); continue; } Loading Loading @@ -117,7 +117,7 @@ static void load_keys(struct listnode *list) while ((path = *paths++)) { if (!stat(path, &buf)) { D("Loading keys from '%s'\n", path); D("Loading keys from '%s'", path); read_keys(path, list); } } Loading Loading @@ -163,7 +163,7 @@ int adb_auth_verify(uint8_t* token, uint8_t* sig, int siglen) static void usb_disconnected(void* unused, atransport* t) { D("USB disconnect\n"); D("USB disconnect"); usb_transport = NULL; needs_retry = false; } Loading @@ -176,7 +176,7 @@ static void adb_auth_event(int fd, unsigned events, void *data) if (events & FDE_READ) { ret = unix_read(fd, response, sizeof(response)); if (ret <= 0) { D("Framework disconnect\n"); D("Framework disconnect"); if (usb_transport) fdevent_remove(&usb_transport->auth_fde); framework_fd = -1; Loading @@ -199,26 +199,26 @@ void adb_auth_confirm_key(unsigned char *key, size_t len, atransport *t) } if (framework_fd < 0) { D("Client not connected\n"); D("Client not connected"); needs_retry = true; return; } if (key[len - 1] != '\0') { D("Key must be a null-terminated string\n"); D("Key must be a null-terminated string"); return; } ret = snprintf(msg, sizeof(msg), "PK%s", key); if (ret >= (signed)sizeof(msg)) { D("Key too long. ret=%d\n", ret); D("Key too long. ret=%d", ret); return; } D("Sending '%s'\n", msg); D("Sending '%s'", msg); ret = unix_write(framework_fd, msg, ret); if (ret < 0) { D("Failed to write PK, errno=%d\n", errno); D("Failed to write PK, errno=%d", errno); return; } Loading @@ -236,7 +236,7 @@ static void adb_auth_listener(int fd, unsigned events, void *data) s = adb_socket_accept(fd, &addr, &alen); if (s < 0) { D("Failed to accept: errno=%d\n", errno); D("Failed to accept: errno=%d", errno); return; } Loading @@ -251,7 +251,7 @@ static void adb_auth_listener(int fd, unsigned events, void *data) void adbd_cloexec_auth_socket() { int fd = android_get_control_socket("adbd"); if (fd == -1) { D("Failed to get adbd socket\n"); D("Failed to get adbd socket"); return; } fcntl(fd, F_SETFD, FD_CLOEXEC); Loading @@ -260,12 +260,12 @@ void adbd_cloexec_auth_socket() { void adbd_auth_init(void) { int fd = android_get_control_socket("adbd"); if (fd == -1) { D("Failed to get adbd socket\n"); D("Failed to get adbd socket"); return; } if (listen(fd, 4) == -1) { D("Failed to listen on '%d'\n", fd); D("Failed to listen on '%d'", fd); return; } Loading
adb/adb_auth_host.cpp +29 −29 Original line number Diff line number Diff line Loading @@ -164,26 +164,26 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path) if (snprintf(path, sizeof(path), "%s.pub", private_key_path) >= (int)sizeof(path)) { D("Path too long while writing public key\n"); D("Path too long while writing public key"); return 0; } if (!RSA_to_RSAPublicKey(private_key, &pkey)) { D("Failed to convert to publickey\n"); D("Failed to convert to publickey"); return 0; } outfile = fopen(path, "w"); if (!outfile) { D("Failed to open '%s'\n", path); D("Failed to open '%s'", path); return 0; } D("Writing public key to '%s'\n", path); D("Writing public key to '%s'", path); #if defined(OPENSSL_IS_BORINGSSL) if (!EVP_EncodedLength(&encoded_length, sizeof(pkey))) { D("Public key too large to base64 encode\n"); D("Public key too large to base64 encode"); goto out; } #else Loading @@ -194,7 +194,7 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path) encoded = new uint8_t[encoded_length]; if (encoded == nullptr) { D("Allocation failure\n"); D("Allocation failure"); goto out; } Loading @@ -203,7 +203,7 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path) if (fwrite(encoded, encoded_length, 1, outfile) != 1 || fwrite(info, strlen(info), 1, outfile) != 1) { D("Write error while writing public key\n"); D("Write error while writing public key"); goto out; } Loading @@ -226,10 +226,10 @@ static int generate_key(const char *file) FILE *f = NULL; int ret = 0; D("generate_key '%s'\n", file); D("generate_key '%s'", file); if (!pkey || !exponent || !rsa) { D("Failed to allocate key\n"); D("Failed to allocate key"); goto out; } Loading @@ -241,7 +241,7 @@ static int generate_key(const char *file) f = fopen(file, "w"); if (!f) { D("Failed to open '%s'\n", file); D("Failed to open '%s'", file); umask(old_mask); goto out; } Loading @@ -249,12 +249,12 @@ static int generate_key(const char *file) umask(old_mask); if (!PEM_write_PrivateKey(f, pkey, NULL, NULL, 0, NULL, NULL)) { D("Failed to write key\n"); D("Failed to write key"); goto out; } if (!write_public_keyfile(rsa, file)) { D("Failed to write public key\n"); D("Failed to write public key"); goto out; } Loading @@ -271,11 +271,11 @@ out: static int read_key(const char *file, struct listnode *list) { D("read_key '%s'\n", file); D("read_key '%s'", file); FILE* fp = fopen(file, "r"); if (!fp) { D("Failed to open '%s': %s\n", file, strerror(errno)); D("Failed to open '%s': %s", file, strerror(errno)); return 0; } Loading @@ -283,7 +283,7 @@ static int read_key(const char *file, struct listnode *list) key->rsa = RSA_new(); if (!PEM_read_RSAPrivateKey(fp, &key->rsa, NULL, NULL)) { D("Failed to read key\n"); D("Failed to read key"); fclose(fp); RSA_free(key->rsa); delete key; Loading @@ -307,7 +307,7 @@ static int get_user_keyfilepath(char *filename, size_t len) WCHAR path[MAX_PATH]; const HRESULT hr = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path); if (FAILED(hr)) { D("SHGetFolderPathW failed: %s\n", D("SHGetFolderPathW failed: %s", SystemErrorCodeToString(hr).c_str()); return -1; } Loading @@ -322,7 +322,7 @@ static int get_user_keyfilepath(char *filename, size_t len) format = "%s/%s"; #endif D("home '%s'\n", home); D("home '%s'", home); if (snprintf(android_dir, sizeof(android_dir), format, home, ANDROID_PATH) >= (int)sizeof(android_dir)) Loading @@ -330,7 +330,7 @@ static int get_user_keyfilepath(char *filename, size_t len) if (stat(android_dir, &buf)) { if (adb_mkdir(android_dir, 0750) < 0) { D("Cannot mkdir '%s'\n", android_dir); D("Cannot mkdir '%s'", android_dir); return -1; } } Loading @@ -346,15 +346,15 @@ static int get_user_key(struct listnode *list) ret = get_user_keyfilepath(path, sizeof(path)); if (ret < 0 || ret >= (signed)sizeof(path)) { D("Error getting user key filename\n"); D("Error getting user key filename"); return 0; } D("user key '%s'\n", path); D("user key '%s'", path); if (stat(path, &buf) == -1) { if (!generate_key(path)) { D("Failed to generate new key\n"); D("Failed to generate new key"); return 0; } } Loading @@ -370,7 +370,7 @@ static void get_vendor_keys(struct listnode* key_list) { for (auto& path : android::base::Split(adb_keys_path, ENV_PATH_SEPARATOR_STR)) { if (!read_key(path.c_str(), key_list)) { D("Failed to read '%s'\n", path.c_str()); D("Failed to read '%s'", path.c_str()); } } } Loading @@ -382,7 +382,7 @@ int adb_auth_sign(void *node, const unsigned char* token, size_t token_size, struct adb_private_key *key = node_to_item(node, struct adb_private_key, node); if (token_size != TOKEN_SIZE) { D("Unexpected token size %zd\n", token_size); D("Unexpected token size %zd", token_size); return 0; } Loading @@ -390,7 +390,7 @@ int adb_auth_sign(void *node, const unsigned char* token, size_t token_size, return 0; } D("adb_auth_sign len=%d\n", len); D("adb_auth_sign len=%d", len); return (int)len; } Loading Loading @@ -421,7 +421,7 @@ int adb_auth_get_userkey(unsigned char *data, size_t len) char path[PATH_MAX]; int ret = get_user_keyfilepath(path, sizeof(path) - 4); if (ret < 0 || ret >= (signed)(sizeof(path) - 4)) { D("Error getting user key filename\n"); D("Error getting user key filename"); return 0; } strcat(path, ".pub"); Loading @@ -433,12 +433,12 @@ int adb_auth_get_userkey(unsigned char *data, size_t len) unsigned size; char* file_data = reinterpret_cast<char*>(load_file(path, &size)); if (file_data == nullptr) { D("Can't load '%s'\n", path); D("Can't load '%s'", path); return 0; } if (len < (size_t)(size + 1)) { D("%s: Content too large ret=%d\n", path, size); D("%s: Content too large ret=%d", path, size); free(file_data); return 0; } Loading @@ -460,13 +460,13 @@ void adb_auth_init(void) { int ret; D("adb_auth_init\n"); D("adb_auth_init"); list_init(&key_list); ret = get_user_key(&key_list); if (!ret) { D("Failed to get user key\n"); D("Failed to get user key"); return; } Loading
adb/adb_client.cpp +9 −9 Original line number Diff line number Diff line Loading @@ -90,14 +90,14 @@ static int switch_socket_transport(int fd, std::string* error) { adb_close(fd); return -1; } D("Switch transport in progress\n"); D("Switch transport in progress"); if (!adb_status(fd, error)) { adb_close(fd); D("Switch transport failed: %s\n", error->c_str()); D("Switch transport failed: %s", error->c_str()); return -1; } D("Switch transport success\n"); D("Switch transport success"); return 0; } Loading @@ -123,7 +123,7 @@ bool adb_status(int fd, std::string* error) { } int _adb_connect(const std::string& service, std::string* error) { D("_adb_connect: %s\n", service.c_str()); D("_adb_connect: %s", service.c_str()); if (service.empty() || service.size() > 1024) { *error = android::base::StringPrintf("bad service name length (%zd)", service.size()); Loading Loading @@ -164,7 +164,7 @@ int _adb_connect(const std::string& service, std::string* error) { return -1; } D("_adb_connect: return fd %d\n", fd); D("_adb_connect: return fd %d", fd); return fd; } Loading @@ -172,7 +172,7 @@ int adb_connect(const std::string& service, std::string* error) { // first query the adb server's version int fd = _adb_connect("host:version", error); D("adb_connect: service %s\n", service.c_str()); D("adb_connect: service %s", service.c_str()); if (fd == -2 && __adb_server_name) { fprintf(stderr,"** Cannot start server on remote host\n"); // error is the original network connection error Loading Loading @@ -246,11 +246,11 @@ int adb_connect(const std::string& service, std::string* error) { fd = _adb_connect(service, error); if (fd == -1) { D("_adb_connect error: %s\n", error->c_str()); D("_adb_connect error: %s", error->c_str()); } else if(fd == -2) { fprintf(stderr,"** daemon still not running\n"); } D("adb_connect: return fd %d\n", fd); D("adb_connect: return fd %d", fd); return fd; error: Loading @@ -277,7 +277,7 @@ bool adb_command(const std::string& service) { } bool adb_query(const std::string& service, std::string* result, std::string* error) { D("adb_query: %s\n", service.c_str()); D("adb_query: %s", service.c_str()); int fd = adb_connect(service, error); if (fd < 0) { return false; Loading