blob: e0425ad628e348d624564179a015bf7083a13d0a [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 Albert818fb4b2015-02-18 00:18:25 -080020#ifdef __cplusplus
21extern "C" {
22#endif
23
Dan Albertbd0b7502015-02-18 18:22:45 -080024extern int auth_enabled;
25
Nick Kralevichbea3f9c2014-11-13 15:17:29 -080026int adb_auth_keygen(const char* filename);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070027void adb_auth_verified(atransport *t);
28
Benoit Goby045a4a92013-01-15 19:59:14 -080029void send_auth_request(atransport *t);
Dan Albertba3a2512015-02-18 17:47:33 -080030void send_auth_response(uint8_t *token, size_t token_size, atransport *t);
31void send_auth_publickey(atransport *t);
Benoit Goby045a4a92013-01-15 19:59:14 -080032
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070033/* AUTH packets first argument */
34/* Request */
35#define ADB_AUTH_TOKEN 1
36/* Response */
37#define ADB_AUTH_SIGNATURE 2
38#define ADB_AUTH_RSAPUBLICKEY 3
39
40#if ADB_HOST
41
Pavel Labath64d9adc2015-03-17 11:03:36 -070042void adb_auth_init(void);
Dan Albertbac34742015-02-25 17:51:28 -080043int adb_auth_sign(void *key, const unsigned char* token, size_t token_size,
44 unsigned char* sig);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070045void *adb_auth_nextkey(void *current);
46int adb_auth_get_userkey(unsigned char *data, size_t len);
47
48static inline int adb_auth_generate_token(void *token, size_t token_size) { return 0; }
49static inline int adb_auth_verify(void *token, void *sig, int siglen) { return 0; }
50static inline void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t) { }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070051
52#else // !ADB_HOST
53
Dan Albertbac34742015-02-25 17:51:28 -080054static inline int adb_auth_sign(void* key, const unsigned char* token,
55 size_t token_size, unsigned char* sig) {
56 return 0;
57}
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070058static inline void *adb_auth_nextkey(void *current) { return NULL; }
59static inline int adb_auth_get_userkey(unsigned char *data, size_t len) { return 0; }
60
Pavel Labath64d9adc2015-03-17 11:03:36 -070061void adbd_auth_init(void);
62void adbd_cloexec_auth_socket();
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070063int adb_auth_generate_token(void *token, size_t token_size);
Dan Albertbac34742015-02-25 17:51:28 -080064int adb_auth_verify(uint8_t* token, uint8_t* sig, int siglen);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070065void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070066
67#endif // ADB_HOST
68
Dan Albert818fb4b2015-02-18 00:18:25 -080069#ifdef __cplusplus
70}
71#endif
72
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070073#endif // __ADB_AUTH_H