blob: 8a6b156dfe0e35ee0a4bd2f352534e02797e1f90 [file] [log] [blame]
Dan Albert056ad0e2015-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
Dan Albertdb6fe642015-03-19 15:21:08 -070017#define TRACE_TAG TRACE_ADB
18
19#include "sysdeps.h"
20#include "adb_auth.h"
Dan Albert056ad0e2015-02-18 17:47:33 -080021
22#include <errno.h>
23#include <stdio.h>
24#include <string.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "adb.h"
Dan Albertb302d122015-02-24 15:51:19 -080029#include "transport.h"
Dan Albert056ad0e2015-02-18 17:47:33 -080030
Elliott Hughesd7eb8542015-06-17 15:23:42 -070031bool auth_required = true;
Dan Albert432ffe22015-02-18 18:22:45 -080032
Dan Albert056ad0e2015-02-18 17:47:33 -080033void send_auth_request(atransport *t)
34{
35 D("Calling send_auth_request\n");
36 apacket *p;
37 int ret;
38
39 ret = adb_auth_generate_token(t->token, sizeof(t->token));
40 if (ret != sizeof(t->token)) {
41 D("Error generating token ret=%d\n", ret);
42 return;
43 }
44
45 p = get_apacket();
46 memcpy(p->data, t->token, ret);
47 p->msg.command = A_AUTH;
48 p->msg.arg0 = ADB_AUTH_TOKEN;
49 p->msg.data_length = ret;
50 send_packet(p, t);
51}
52
53void send_auth_response(uint8_t *token, size_t token_size, atransport *t)
54{
55 D("Calling send_auth_response\n");
56 apacket *p = get_apacket();
57 int ret;
58
59 ret = adb_auth_sign(t->key, token, token_size, p->data);
60 if (!ret) {
61 D("Error signing the token\n");
62 put_apacket(p);
63 return;
64 }
65
66 p->msg.command = A_AUTH;
67 p->msg.arg0 = ADB_AUTH_SIGNATURE;
68 p->msg.data_length = ret;
69 send_packet(p, t);
70}
71
72void send_auth_publickey(atransport *t)
73{
74 D("Calling send_auth_publickey\n");
75 apacket *p = get_apacket();
76 int ret;
77
Tamas Berghammera1c60c02015-07-13 19:12:28 +010078 ret = adb_auth_get_userkey(p->data, MAX_PAYLOAD_V1);
Dan Albert056ad0e2015-02-18 17:47:33 -080079 if (!ret) {
80 D("Failed to get user public key\n");
81 put_apacket(p);
82 return;
83 }
84
85 p->msg.command = A_AUTH;
86 p->msg.arg0 = ADB_AUTH_RSAPUBLICKEY;
87 p->msg.data_length = ret;
88 send_packet(p, t);
89}
90
91void adb_auth_verified(atransport *t)
92{
93 handle_online(t);
94 send_connect(t);
95}