2015-02-19 02:47:33 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-09-23 00:52:57 +02:00
|
|
|
#define TRACE_TAG ADB
|
2015-03-19 23:21:08 +01:00
|
|
|
|
|
|
|
#include "sysdeps.h"
|
|
|
|
#include "adb_auth.h"
|
2015-02-19 02:47:33 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "adb.h"
|
2015-02-25 00:51:19 +01:00
|
|
|
#include "transport.h"
|
2015-02-19 02:47:33 +01:00
|
|
|
|
2015-06-18 00:23:42 +02:00
|
|
|
bool auth_required = true;
|
2015-02-19 03:22:45 +01:00
|
|
|
|
2015-02-19 02:47:33 +01:00
|
|
|
void send_auth_request(atransport *t)
|
|
|
|
{
|
2015-09-03 02:44:28 +02:00
|
|
|
D("Calling send_auth_request");
|
2015-02-19 02:47:33 +01:00
|
|
|
apacket *p;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = adb_auth_generate_token(t->token, sizeof(t->token));
|
|
|
|
if (ret != sizeof(t->token)) {
|
2015-09-03 02:44:28 +02:00
|
|
|
D("Error generating token ret=%d", ret);
|
2015-02-19 02:47:33 +01:00
|
|
|
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)
|
|
|
|
{
|
2015-09-03 02:44:28 +02:00
|
|
|
D("Calling send_auth_response");
|
2015-02-19 02:47:33 +01:00
|
|
|
apacket *p = get_apacket();
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = adb_auth_sign(t->key, token, token_size, p->data);
|
|
|
|
if (!ret) {
|
2015-09-03 02:44:28 +02:00
|
|
|
D("Error signing the token");
|
2015-02-19 02:47:33 +01:00
|
|
|
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)
|
|
|
|
{
|
2015-09-03 02:44:28 +02:00
|
|
|
D("Calling send_auth_publickey");
|
2015-02-19 02:47:33 +01:00
|
|
|
apacket *p = get_apacket();
|
|
|
|
int ret;
|
|
|
|
|
2015-07-13 20:12:28 +02:00
|
|
|
ret = adb_auth_get_userkey(p->data, MAX_PAYLOAD_V1);
|
2015-02-19 02:47:33 +01:00
|
|
|
if (!ret) {
|
2015-09-03 02:44:28 +02:00
|
|
|
D("Failed to get user public key");
|
2015-02-19 02:47:33 +01:00
|
|
|
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);
|
|
|
|
}
|