diff options
author | Dan Albert <danalbert@google.com> | 2015-02-18 17:47:33 -0800 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2015-02-18 18:22:52 -0800 |
commit | ba3a251749c88210949008ae26f8bc04812084c1 (patch) | |
tree | 07537954fcfba6c69a6ea9fbb5e882d7e15fb5a6 /adb | |
parent | 1403aa36b2d9d0c295402a935bb07ea661536fcb (diff) | |
download | system_core-ba3a251749c88210949008ae26f8bc04812084c1.zip system_core-ba3a251749c88210949008ae26f8bc04812084c1.tar.gz system_core-ba3a251749c88210949008ae26f8bc04812084c1.tar.bz2 |
Move the adb auth code into its own file.
Change-Id: I84cf0bd7777f0147119e7c6afc4096c2e93156a2
Diffstat (limited to 'adb')
-rw-r--r-- | adb/Android.mk | 11 | ||||
-rw-r--r-- | adb/adb.c | 66 | ||||
-rw-r--r-- | adb/adb.h | 5 | ||||
-rw-r--r-- | adb/adb_auth.c | 91 | ||||
-rw-r--r-- | adb/adb_auth.h | 2 |
5 files changed, 108 insertions, 67 deletions
diff --git a/adb/Android.mk b/adb/Android.mk index 83d168b..51318ef 100644 --- a/adb/Android.mk +++ b/adb/Android.mk @@ -14,8 +14,15 @@ LOCAL_PATH:= $(call my-dir) # divergence makes this difficult to do all at once. For now, we will start # small by moving common files into a static library. Hopefully some day we can # get enough of adb in here that we no longer need minadb. https://b/17626262 -LIBADB_SRC_FILES := transport.c transport_usb.c -LIBADB_C_FLAGS := -Wall -Werror -D_XOPEN_SOURCE -D_GNU_SOURCE +LIBADB_SRC_FILES := \ + adb_auth.c \ + transport.c \ + transport_usb.c \ + +LIBADB_C_FLAGS := \ + -Wall -Werror \ + -D_XOPEN_SOURCE -D_GNU_SOURCE \ + -fvisibility=hidden \ LIBADB_LINUX_SRC_FILES := fdevent.cpp LIBADB_WINDOWS_SRC_FILES := sysdeps_win32.c @@ -286,7 +286,7 @@ static void send_msg_with_okay(int fd, const char* msg, size_t msglen) { } #endif // ADB_HOST -static void send_connect(atransport *t) +void send_connect(atransport *t) { D("Calling send_connect \n"); apacket *cp = get_apacket(); @@ -298,70 +298,6 @@ static void send_connect(atransport *t) send_packet(cp, t); } -void send_auth_request(atransport *t) -{ - D("Calling send_auth_request\n"); - 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); - return; - } - - p = get_apacket(); - memcpy(p->data, t->token, ret); - p->msg.command = A_AUTH; - p->msg.arg0 = ADB_AUTH_TOKEN; - p->msg.data_length = ret; - send_packet(p, t); -} - -static void send_auth_response(uint8_t *token, size_t token_size, atransport *t) -{ - D("Calling send_auth_response\n"); - 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"); - put_apacket(p); - return; - } - - p->msg.command = A_AUTH; - p->msg.arg0 = ADB_AUTH_SIGNATURE; - p->msg.data_length = ret; - send_packet(p, t); -} - -static void send_auth_publickey(atransport *t) -{ - D("Calling send_auth_publickey\n"); - apacket *p = get_apacket(); - int ret; - - ret = adb_auth_get_userkey(p->data, sizeof(p->data)); - if (!ret) { - D("Failed to get user public key\n"); - put_apacket(p); - return; - } - - p->msg.command = A_AUTH; - p->msg.arg0 = ADB_AUTH_RSAPUBLICKEY; - p->msg.data_length = ret; - send_packet(p, t); -} - -void adb_auth_verified(atransport *t) -{ - handle_online(t); - send_connect(t); -} - #if ADB_HOST static char *connection_state_name(atransport *t) { @@ -424,6 +424,11 @@ typedef enum { int sendfailmsg(int fd, const char *reason); int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s); +void handle_online(atransport *t); +void handle_offline(atransport *t); + +void send_connect(atransport *t); + #ifdef __cplusplus } #endif diff --git a/adb/adb_auth.c b/adb/adb_auth.c new file mode 100644 index 0000000..00cf469 --- /dev/null +++ b/adb/adb_auth.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2015 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. + */ + +#define TRACE_TAG TRACE_ADB + +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "adb.h" +#include "adb_auth.h" +#include "sysdeps.h" + +void send_auth_request(atransport *t) +{ + D("Calling send_auth_request\n"); + 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); + return; + } + + p = get_apacket(); + memcpy(p->data, t->token, ret); + p->msg.command = A_AUTH; + p->msg.arg0 = ADB_AUTH_TOKEN; + p->msg.data_length = ret; + send_packet(p, t); +} + +void send_auth_response(uint8_t *token, size_t token_size, atransport *t) +{ + D("Calling send_auth_response\n"); + 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"); + put_apacket(p); + return; + } + + p->msg.command = A_AUTH; + p->msg.arg0 = ADB_AUTH_SIGNATURE; + p->msg.data_length = ret; + send_packet(p, t); +} + +void send_auth_publickey(atransport *t) +{ + D("Calling send_auth_publickey\n"); + apacket *p = get_apacket(); + int ret; + + ret = adb_auth_get_userkey(p->data, sizeof(p->data)); + if (!ret) { + D("Failed to get user public key\n"); + put_apacket(p); + return; + } + + p->msg.command = A_AUTH; + p->msg.arg0 = ADB_AUTH_RSAPUBLICKEY; + p->msg.data_length = ret; + send_packet(p, t); +} + +void adb_auth_verified(atransport *t) +{ + handle_online(t); + send_connect(t); +} diff --git a/adb/adb_auth.h b/adb/adb_auth.h index b718b42..4431b5b 100644 --- a/adb/adb_auth.h +++ b/adb/adb_auth.h @@ -26,6 +26,8 @@ int adb_auth_keygen(const char* filename); void adb_auth_verified(atransport *t); void send_auth_request(atransport *t); +void send_auth_response(uint8_t *token, size_t token_size, atransport *t); +void send_auth_publickey(atransport *t); /* AUTH packets first argument */ /* Request */ |