• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #pragma once
18 
19 #include <openssl/ssl.h>
20 #include <utils/Errors.h>
21 
22 namespace android {
23 
24 // An interface with a function that configures the SSL_CTX object with authentication information,
25 // including certificates and private keys.
26 class RpcAuth {
27 public:
28     virtual ~RpcAuth() = default;
29 
30     // The keys and certificates to provide is up to the implementation. Multiple calls to
31     // |configure()| may configure |ctx| with the same keys / certificates, or generate a
32     // different key / certificate every time |configure()| is called.
33     //
34     // It is guaranteed that, when a context object (RpcTransportCtx) is created,
35     // libbinder_tls calls |configure()| on server RpcAuth exactly once.
36     //
37     // The implementation may use the following function to set the private
38     // keys and certificates:
39     // - SSL_CTX_use_PrivateKey
40     // - SSL_CTX_use_certificate
41     // - SSL_CTX_set*_chain
42     // - SSL_CTX_add0_chain_cert
43     [[nodiscard]] virtual status_t configure(SSL_CTX* ctx) = 0;
44 };
45 
46 } // namespace android
47