blob: 7e858dce4fcbaea75ec0b6914ab2139a10f27148 [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>
Josh Gao2e671202016-08-18 22:00:12 -070023#include <memory>
Elliott Hughes0aeb5052016-06-29 17:42:01 -070024
25#include <openssl/rsa.h>
26
Benoit Gobyd5fcafa2012-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 Hughes0aeb5052016-06-29 17:42:01 -070036void adb_auth_init();
Josh Gao3bd28792016-10-05 19:02:29 -070037
38int adb_auth_keygen(const char* filename);
Josh Gao2dc4cab2018-11-15 17:45:46 -080039int adb_auth_pubkey(const char* filename);
Elliott Hughese8b663f2016-05-26 22:43:19 -070040std::string adb_auth_get_userkey();
Joshua Duongd85f5c02019-11-20 14:18:43 -080041bssl::UniquePtr<EVP_PKEY> adb_auth_get_user_privkey();
Josh Gao2e671202016-08-18 22:00:12 -070042std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys();
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070043
Josh Gao06d61d42016-10-06 13:31:44 -070044void send_auth_response(const char* token, size_t token_size, atransport* t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070045
Joshua Duong5cf78682020-01-21 13:19:42 -080046int adb_tls_set_certificate(SSL* ssl);
47void adb_auth_tls_handshake(atransport* t);
48
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070049#else // !ADB_HOST
50
Josh Gao3bd28792016-10-05 19:02:29 -070051extern bool auth_required;
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070052
Pavel Labath64d9adc2015-03-17 11:03:36 -070053void adbd_auth_init(void);
Josh Gao3bd28792016-10-05 19:02:29 -070054void adbd_auth_verified(atransport *t);
55
Pavel Labath64d9adc2015-03-17 11:03:36 -070056void adbd_cloexec_auth_socket();
Michael Groover7eeda6b2019-04-25 18:33:35 -070057bool adbd_auth_verify(const char* token, size_t token_size, const std::string& sig,
58 std::string* auth_key);
59void adbd_auth_confirm_key(atransport* t);
60void adbd_notify_framework_connected_key(atransport* t);
Josh Gao3bd28792016-10-05 19:02:29 -070061
62void send_auth_request(atransport *t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070063
Joshua Duong5cf78682020-01-21 13:19:42 -080064void adbd_auth_tls_handshake(atransport* t);
65int adbd_tls_verify_cert(X509_STORE_CTX* ctx, std::string* auth_key);
66bssl::UniquePtr<STACK_OF(X509_NAME)> adbd_tls_client_ca_list();
67
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070068#endif // ADB_HOST
69
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070070#endif // __ADB_AUTH_H