Benoit Goby | 2cc19e4 | 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 | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 20 | #include "adb.h" |
| 21 | |
Elliott Hughes | d7eb854 | 2015-06-17 15:23:42 -0700 | [diff] [blame] | 22 | extern bool auth_required; |
Dan Albert | 432ffe2 | 2015-02-18 18:22:45 -0800 | [diff] [blame] | 23 | |
Nick Kralevich | 6183c96 | 2014-11-13 15:17:29 -0800 | [diff] [blame] | 24 | int adb_auth_keygen(const char* filename); |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 25 | void adb_auth_verified(atransport *t); |
| 26 | |
Benoit Goby | d592d6c | 2013-01-15 19:59:14 -0800 | [diff] [blame] | 27 | void send_auth_request(atransport *t); |
Dan Albert | 056ad0e | 2015-02-18 17:47:33 -0800 | [diff] [blame] | 28 | void send_auth_response(uint8_t *token, size_t token_size, atransport *t); |
| 29 | void send_auth_publickey(atransport *t); |
Benoit Goby | d592d6c | 2013-01-15 19:59:14 -0800 | [diff] [blame] | 30 | |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 31 | /* AUTH packets first argument */ |
| 32 | /* Request */ |
| 33 | #define ADB_AUTH_TOKEN 1 |
| 34 | /* Response */ |
| 35 | #define ADB_AUTH_SIGNATURE 2 |
| 36 | #define ADB_AUTH_RSAPUBLICKEY 3 |
| 37 | |
| 38 | #if ADB_HOST |
| 39 | |
Pavel Labath | 0bdb867 | 2015-03-17 11:03:36 -0700 | [diff] [blame] | 40 | void adb_auth_init(void); |
Dan Albert | f30d73c | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 41 | int adb_auth_sign(void *key, const unsigned char* token, size_t token_size, |
| 42 | unsigned char* sig); |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 43 | void *adb_auth_nextkey(void *current); |
Elliott Hughes | e0a6e2a | 2016-05-26 22:43:19 -0700 | [diff] [blame^] | 44 | std::string adb_auth_get_userkey(); |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 45 | |
Mattias Nissler | a947b49 | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 46 | static inline int adb_auth_generate_token(void *token, size_t token_size) { |
| 47 | return 0; |
| 48 | } |
| 49 | static inline int adb_auth_verify(void *token, size_t token_size, |
| 50 | void *sig, int siglen) { |
| 51 | return 0; |
| 52 | } |
| 53 | static inline void adb_auth_confirm_key(unsigned char *data, size_t len, |
| 54 | atransport *t) {} |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 55 | |
| 56 | #else // !ADB_HOST |
| 57 | |
Dan Albert | f30d73c | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 58 | static inline int adb_auth_sign(void* key, const unsigned char* token, |
| 59 | size_t token_size, unsigned char* sig) { |
| 60 | return 0; |
| 61 | } |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 62 | static inline void *adb_auth_nextkey(void *current) { return NULL; } |
Elliott Hughes | e0a6e2a | 2016-05-26 22:43:19 -0700 | [diff] [blame^] | 63 | static inline std::string adb_auth_get_userkey() { return ""; } |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 64 | |
Pavel Labath | 0bdb867 | 2015-03-17 11:03:36 -0700 | [diff] [blame] | 65 | void adbd_auth_init(void); |
| 66 | void adbd_cloexec_auth_socket(); |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 67 | int adb_auth_generate_token(void *token, size_t token_size); |
Mattias Nissler | a947b49 | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 68 | int adb_auth_verify(uint8_t* token, size_t token_size, |
| 69 | uint8_t* sig, int siglen); |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 70 | void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t); |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 71 | |
| 72 | #endif // ADB_HOST |
| 73 | |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 74 | #endif // __ADB_AUTH_H |