• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include "adb.h"
21 
22 #include <deque>
23 #include <memory>
24 
25 #include <openssl/rsa.h>
26 
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 
36 void adb_auth_init();
37 
38 int adb_auth_keygen(const char* filename);
39 int adb_auth_pubkey(const char* filename);
40 std::string adb_auth_get_userkey();
41 bssl::UniquePtr<EVP_PKEY> adb_auth_get_user_privkey();
42 std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys();
43 
44 void send_auth_response(const char* token, size_t token_size, atransport* t);
45 
46 int adb_tls_set_certificate(SSL* ssl);
47 void adb_auth_tls_handshake(atransport* t);
48 
49 #else // !ADB_HOST
50 
51 extern bool auth_required;
52 
53 void adbd_auth_init(void);
54 void adbd_auth_verified(atransport *t);
55 
56 void adbd_cloexec_auth_socket();
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);
61 
62 void send_auth_request(atransport *t);
63 
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 
68 #endif // ADB_HOST
69 
70 #endif // __ADB_AUTH_H
71