| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Albert | 3313426 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 20 | #include "adb.h" | 
|  | 21 |  | 
| Elliott Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame] | 22 | #include <deque> | 
| Josh Gao | 2e67120 | 2016-08-18 22:00:12 -0700 | [diff] [blame] | 23 | #include <memory> | 
| Elliott Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | #include <openssl/rsa.h> | 
|  | 26 |  | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 27 | /* 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 Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame] | 36 | void adb_auth_init(); | 
| Josh Gao | 3bd2879 | 2016-10-05 19:02:29 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | int adb_auth_keygen(const char* filename); | 
| Josh Gao | 2dc4cab | 2018-11-15 17:45:46 -0800 | [diff] [blame] | 39 | int adb_auth_pubkey(const char* filename); | 
| Elliott Hughes | e8b663f | 2016-05-26 22:43:19 -0700 | [diff] [blame] | 40 | std::string adb_auth_get_userkey(); | 
| Joshua Duong | d85f5c0 | 2019-11-20 14:18:43 -0800 | [diff] [blame] | 41 | bssl::UniquePtr<EVP_PKEY> adb_auth_get_user_privkey(); | 
| Josh Gao | 2e67120 | 2016-08-18 22:00:12 -0700 | [diff] [blame] | 42 | std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys(); | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 43 |  | 
| Josh Gao | 06d61d4 | 2016-10-06 13:31:44 -0700 | [diff] [blame] | 44 | void send_auth_response(const char* token, size_t token_size, atransport* t); | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 45 |  | 
| Joshua Duong | 5cf7868 | 2020-01-21 13:19:42 -0800 | [diff] [blame] | 46 | int adb_tls_set_certificate(SSL* ssl); | 
|  | 47 | void adb_auth_tls_handshake(atransport* t); | 
|  | 48 |  | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 49 | #else // !ADB_HOST | 
|  | 50 |  | 
| Josh Gao | 3bd2879 | 2016-10-05 19:02:29 -0700 | [diff] [blame] | 51 | extern bool auth_required; | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 52 |  | 
| Pavel Labath | 64d9adc | 2015-03-17 11:03:36 -0700 | [diff] [blame] | 53 | void adbd_auth_init(void); | 
| Josh Gao | 3bd2879 | 2016-10-05 19:02:29 -0700 | [diff] [blame] | 54 | void adbd_auth_verified(atransport *t); | 
|  | 55 |  | 
| Pavel Labath | 64d9adc | 2015-03-17 11:03:36 -0700 | [diff] [blame] | 56 | void adbd_cloexec_auth_socket(); | 
| Michael Groover | 7eeda6b | 2019-04-25 18:33:35 -0700 | [diff] [blame] | 57 | bool adbd_auth_verify(const char* token, size_t token_size, const std::string& sig, | 
|  | 58 | std::string* auth_key); | 
|  | 59 | void adbd_auth_confirm_key(atransport* t); | 
|  | 60 | void adbd_notify_framework_connected_key(atransport* t); | 
| Josh Gao | 3bd2879 | 2016-10-05 19:02:29 -0700 | [diff] [blame] | 61 |  | 
|  | 62 | void send_auth_request(atransport *t); | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 63 |  | 
| Joshua Duong | 5cf7868 | 2020-01-21 13:19:42 -0800 | [diff] [blame] | 64 | void adbd_auth_tls_handshake(atransport* t); | 
|  | 65 | int adbd_tls_verify_cert(X509_STORE_CTX* ctx, std::string* auth_key); | 
|  | 66 | bssl::UniquePtr<STACK_OF(X509_NAME)> adbd_tls_client_ca_list(); | 
|  | 67 |  | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 68 | #endif // ADB_HOST | 
|  | 69 |  | 
| Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 70 | #endif // __ADB_AUTH_H |