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> |
| 23 | |
| 24 | #include <openssl/rsa.h> |
| 25 | |
Elliott Hughes | 5cba504 | 2015-06-17 15:23:42 -0700 | [diff] [blame] | 26 | extern bool auth_required; |
Dan Albert | bd0b750 | 2015-02-18 18:22:45 -0800 | [diff] [blame] | 27 | |
Nick Kralevich | bea3f9c | 2014-11-13 15:17:29 -0800 | [diff] [blame] | 28 | int adb_auth_keygen(const char* filename); |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 29 | void adb_auth_verified(atransport *t); |
| 30 | |
Benoit Goby | 045a4a9 | 2013-01-15 19:59:14 -0800 | [diff] [blame] | 31 | void send_auth_request(atransport *t); |
Dan Albert | ba3a251 | 2015-02-18 17:47:33 -0800 | [diff] [blame] | 32 | void send_auth_response(uint8_t *token, size_t token_size, atransport *t); |
Benoit Goby | 045a4a9 | 2013-01-15 19:59:14 -0800 | [diff] [blame] | 33 | |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 34 | /* 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 Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame^] | 43 | void adb_auth_init(); |
| 44 | int adb_auth_sign(RSA* key, const unsigned char* token, size_t token_size, unsigned char* sig); |
Elliott Hughes | e8b663f | 2016-05-26 22:43:19 -0700 | [diff] [blame] | 45 | std::string adb_auth_get_userkey(); |
Elliott Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame^] | 46 | std::deque<RSA*> adb_auth_get_private_keys(); |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 47 | |
Elliott Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame^] | 48 | static inline bool adb_auth_generate_token(void*, size_t) { abort(); } |
| 49 | static inline bool adb_auth_verify(void*, size_t, void*, int) { abort(); } |
| 50 | static inline void adb_auth_confirm_key(unsigned char*, size_t, atransport*) { abort(); } |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 51 | |
| 52 | #else // !ADB_HOST |
| 53 | |
Elliott Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame^] | 54 | static inline int adb_auth_sign(void*, const unsigned char*, size_t, unsigned char*) { abort(); } |
| 55 | static inline std::string adb_auth_get_userkey() { abort(); } |
| 56 | static inline std::deque<RSA*> adb_auth_get_private_keys() { abort(); } |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 57 | |
Pavel Labath | 64d9adc | 2015-03-17 11:03:36 -0700 | [diff] [blame] | 58 | void adbd_auth_init(void); |
| 59 | void adbd_cloexec_auth_socket(); |
Elliott Hughes | 0aeb505 | 2016-06-29 17:42:01 -0700 | [diff] [blame^] | 60 | bool adb_auth_generate_token(void* token, size_t token_size); |
| 61 | bool adb_auth_verify(uint8_t* token, size_t token_size, uint8_t* sig, int sig_len); |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 62 | void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t); |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 63 | |
| 64 | #endif // ADB_HOST |
| 65 | |
Benoit Goby | d5fcafa | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 66 | #endif // __ADB_AUTH_H |