blob: 59b80d8febbed08a6c5ac59f5f10d9871fb606da [file] [log] [blame]
Benoit Goby2cc19e42012-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 Albertdb6fe642015-03-19 15:21:08 -070020#include "adb.h"
21
Elliott Hughes801066a2016-06-29 17:42:01 -070022#include <deque>
Josh Gao22cb70b2016-08-18 22:00:12 -070023#include <memory>
Elliott Hughes801066a2016-06-29 17:42:01 -070024
25#include <openssl/rsa.h>
26
Elliott Hughesd7eb8542015-06-17 15:23:42 -070027extern bool auth_required;
Dan Albert432ffe22015-02-18 18:22:45 -080028
Nick Kralevich6183c962014-11-13 15:17:29 -080029int adb_auth_keygen(const char* filename);
Benoit Goby2cc19e42012-04-12 12:23:49 -070030void adb_auth_verified(atransport *t);
31
Benoit Gobyd592d6c2013-01-15 19:59:14 -080032void send_auth_request(atransport *t);
Dan Albert056ad0e2015-02-18 17:47:33 -080033void send_auth_response(uint8_t *token, size_t token_size, atransport *t);
Benoit Gobyd592d6c2013-01-15 19:59:14 -080034
Benoit Goby2cc19e42012-04-12 12:23:49 -070035/* AUTH packets first argument */
36/* Request */
37#define ADB_AUTH_TOKEN 1
38/* Response */
39#define ADB_AUTH_SIGNATURE 2
40#define ADB_AUTH_RSAPUBLICKEY 3
41
42#if ADB_HOST
43
Elliott Hughes801066a2016-06-29 17:42:01 -070044void adb_auth_init();
45int adb_auth_sign(RSA* key, const unsigned char* token, size_t token_size, unsigned char* sig);
Elliott Hughese0a6e2a2016-05-26 22:43:19 -070046std::string adb_auth_get_userkey();
Josh Gao22cb70b2016-08-18 22:00:12 -070047std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys();
Benoit Goby2cc19e42012-04-12 12:23:49 -070048
Elliott Hughes801066a2016-06-29 17:42:01 -070049static inline bool adb_auth_generate_token(void*, size_t) { abort(); }
50static inline bool adb_auth_verify(void*, size_t, void*, int) { abort(); }
51static inline void adb_auth_confirm_key(unsigned char*, size_t, atransport*) { abort(); }
Benoit Goby2cc19e42012-04-12 12:23:49 -070052
53#else // !ADB_HOST
54
Elliott Hughes801066a2016-06-29 17:42:01 -070055static inline int adb_auth_sign(void*, const unsigned char*, size_t, unsigned char*) { abort(); }
56static inline std::string adb_auth_get_userkey() { abort(); }
Josh Gao22cb70b2016-08-18 22:00:12 -070057static inline std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys() { abort(); }
Benoit Goby2cc19e42012-04-12 12:23:49 -070058
Pavel Labath0bdb8672015-03-17 11:03:36 -070059void adbd_auth_init(void);
60void adbd_cloexec_auth_socket();
Elliott Hughes801066a2016-06-29 17:42:01 -070061bool adb_auth_generate_token(void* token, size_t token_size);
62bool adb_auth_verify(uint8_t* token, size_t token_size, uint8_t* sig, int sig_len);
Benoit Goby2cc19e42012-04-12 12:23:49 -070063void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t);
Benoit Goby2cc19e42012-04-12 12:23:49 -070064
65#endif // ADB_HOST
66
Benoit Goby2cc19e42012-04-12 12:23:49 -070067#endif // __ADB_AUTH_H