blob: 4db83a44081bda376fe58112439c100ee518ebde [file] [log] [blame]
Benoit Goby2cc19e42012-04-12 12:23:49 -07001/*
2 * Copyright (C) 2012 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#ifndef __ADB_AUTH_H
18#define __ADB_AUTH_H
19
Dan Albertdb6fe642015-03-19 15:21:08 -070020#include "adb.h"
21
Elliott Hughes801066a2016-06-29 17:42:01 -070022#include <deque>
Josh Gao22cb70b2016-08-18 22:00:12 -070023#include <memory>
Elliott Hughes801066a2016-06-29 17:42:01 -070024
25#include <openssl/rsa.h>
26
Benoit Goby2cc19e42012-04-12 12:23:49 -070027/* AUTH packets first argument */
28/* Request */
29#define ADB_AUTH_TOKEN 1
30/* Response */
31#define ADB_AUTH_SIGNATURE 2
32#define ADB_AUTH_RSAPUBLICKEY 3
33
34#if ADB_HOST
35
Elliott Hughes801066a2016-06-29 17:42:01 -070036void adb_auth_init();
Josh Gaoeac20582016-10-05 19:02:29 -070037
38int adb_auth_keygen(const char* filename);
Elliott Hughes801066a2016-06-29 17:42:01 -070039int adb_auth_sign(RSA* key, const unsigned char* token, size_t token_size, unsigned char* sig);
Elliott Hughese0a6e2a2016-05-26 22:43:19 -070040std::string adb_auth_get_userkey();
Josh Gao22cb70b2016-08-18 22:00:12 -070041std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys();
Benoit Goby2cc19e42012-04-12 12:23:49 -070042
Josh Gaoeac20582016-10-05 19:02:29 -070043void send_auth_response(uint8_t *token, size_t token_size, atransport *t);
Benoit Goby2cc19e42012-04-12 12:23:49 -070044
45#else // !ADB_HOST
46
Josh Gaoeac20582016-10-05 19:02:29 -070047extern bool auth_required;
Benoit Goby2cc19e42012-04-12 12:23:49 -070048
Pavel Labath0bdb8672015-03-17 11:03:36 -070049void adbd_auth_init(void);
Josh Gaoeac20582016-10-05 19:02:29 -070050void adbd_auth_verified(atransport *t);
51
Pavel Labath0bdb8672015-03-17 11:03:36 -070052void adbd_cloexec_auth_socket();
Josh Gaoeac20582016-10-05 19:02:29 -070053bool adbd_auth_verify(uint8_t* token, size_t token_size, uint8_t* sig, int sig_len);
54void adbd_auth_confirm_key(unsigned char *data, size_t len, atransport *t);
55
56void send_auth_request(atransport *t);
Benoit Goby2cc19e42012-04-12 12:23:49 -070057
58#endif // ADB_HOST
59
Benoit Goby2cc19e42012-04-12 12:23:49 -070060#endif // __ADB_AUTH_H