blob: 00cf46912bd5bf4db85bb384c86392bd04c48c7f [file] [log] [blame]
Dan Albertba3a2512015-02-18 17:47:33 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define TRACE_TAG TRACE_ADB
18
19#include <errno.h>
20#include <stdio.h>
21#include <string.h>
22#include <sys/types.h>
23#include <unistd.h>
24
25#include "adb.h"
26#include "adb_auth.h"
27#include "sysdeps.h"
28
29void send_auth_request(atransport *t)
30{
31 D("Calling send_auth_request\n");
32 apacket *p;
33 int ret;
34
35 ret = adb_auth_generate_token(t->token, sizeof(t->token));
36 if (ret != sizeof(t->token)) {
37 D("Error generating token ret=%d\n", ret);
38 return;
39 }
40
41 p = get_apacket();
42 memcpy(p->data, t->token, ret);
43 p->msg.command = A_AUTH;
44 p->msg.arg0 = ADB_AUTH_TOKEN;
45 p->msg.data_length = ret;
46 send_packet(p, t);
47}
48
49void send_auth_response(uint8_t *token, size_t token_size, atransport *t)
50{
51 D("Calling send_auth_response\n");
52 apacket *p = get_apacket();
53 int ret;
54
55 ret = adb_auth_sign(t->key, token, token_size, p->data);
56 if (!ret) {
57 D("Error signing the token\n");
58 put_apacket(p);
59 return;
60 }
61
62 p->msg.command = A_AUTH;
63 p->msg.arg0 = ADB_AUTH_SIGNATURE;
64 p->msg.data_length = ret;
65 send_packet(p, t);
66}
67
68void send_auth_publickey(atransport *t)
69{
70 D("Calling send_auth_publickey\n");
71 apacket *p = get_apacket();
72 int ret;
73
74 ret = adb_auth_get_userkey(p->data, sizeof(p->data));
75 if (!ret) {
76 D("Failed to get user public key\n");
77 put_apacket(p);
78 return;
79 }
80
81 p->msg.command = A_AUTH;
82 p->msg.arg0 = ADB_AUTH_RSAPUBLICKEY;
83 p->msg.data_length = ret;
84 send_packet(p, t);
85}
86
87void adb_auth_verified(atransport *t)
88{
89 handle_online(t);
90 send_connect(t);
91}