blob: 723ded5e1fc22f28af771acc84c6fae96c8ccdcf [file] [log] [blame]
Benoit Gobyd5fcafa2012-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 Albert33134262015-03-19 15:21:08 -070020#include "adb.h"
21
Elliott Hughes0aeb5052016-06-29 17:42:01 -070022#include <deque>
23
24#include <openssl/rsa.h>
25
Elliott Hughes5cba5042015-06-17 15:23:42 -070026extern bool auth_required;
Dan Albertbd0b7502015-02-18 18:22:45 -080027
Nick Kralevichbea3f9c2014-11-13 15:17:29 -080028int adb_auth_keygen(const char* filename);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070029void adb_auth_verified(atransport *t);
30
Benoit Goby045a4a92013-01-15 19:59:14 -080031void send_auth_request(atransport *t);
Dan Albertba3a2512015-02-18 17:47:33 -080032void send_auth_response(uint8_t *token, size_t token_size, atransport *t);
Benoit Goby045a4a92013-01-15 19:59:14 -080033
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070034/* AUTH packets first argument */
35/* Request */
36#define ADB_AUTH_TOKEN 1
37/* Response */
38#define ADB_AUTH_SIGNATURE 2
39#define ADB_AUTH_RSAPUBLICKEY 3
40
41#if ADB_HOST
42
Elliott Hughes0aeb5052016-06-29 17:42:01 -070043void adb_auth_init();
44int adb_auth_sign(RSA* key, const unsigned char* token, size_t token_size, unsigned char* sig);
Elliott Hughese8b663f2016-05-26 22:43:19 -070045std::string adb_auth_get_userkey();
Elliott Hughes0aeb5052016-06-29 17:42:01 -070046std::deque<RSA*> adb_auth_get_private_keys();
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070047
Elliott Hughes0aeb5052016-06-29 17:42:01 -070048static inline bool adb_auth_generate_token(void*, size_t) { abort(); }
49static inline bool adb_auth_verify(void*, size_t, void*, int) { abort(); }
50static inline void adb_auth_confirm_key(unsigned char*, size_t, atransport*) { abort(); }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070051
52#else // !ADB_HOST
53
Elliott Hughes0aeb5052016-06-29 17:42:01 -070054static inline int adb_auth_sign(void*, const unsigned char*, size_t, unsigned char*) { abort(); }
55static inline std::string adb_auth_get_userkey() { abort(); }
56static inline std::deque<RSA*> adb_auth_get_private_keys() { abort(); }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070057
Pavel Labath64d9adc2015-03-17 11:03:36 -070058void adbd_auth_init(void);
59void adbd_cloexec_auth_socket();
Elliott Hughes0aeb5052016-06-29 17:42:01 -070060bool adb_auth_generate_token(void* token, size_t token_size);
61bool adb_auth_verify(uint8_t* token, size_t token_size, uint8_t* sig, int sig_len);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070062void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070063
64#endif // ADB_HOST
65
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070066#endif // __ADB_AUTH_H