blob: c3c2df4c293771cdb1f86a955d5af3ccc5c287fe [file] [log] [blame]
Yifan Hongffdaf952021-09-17 18:08:38 -07001/*
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 <binder/RpcAuth.h>
20
21namespace android {
22
23constexpr const uint32_t kCertValidSeconds = 30 * (60 * 60 * 24); // 30 days
24bssl::UniquePtr<EVP_PKEY> makeKeyPairForSelfSignedCert();
25bssl::UniquePtr<X509> makeSelfSignedCert(EVP_PKEY* pKey, uint32_t validSeconds);
26
27// An implementation of RpcAuth that generates a key pair and a self-signed
28// certificate every time configure() is called.
29class RpcAuthSelfSigned : public RpcAuth {
30public:
31 RpcAuthSelfSigned(uint32_t validSeconds = kCertValidSeconds) : mValidSeconds(validSeconds) {}
32 status_t configure(SSL_CTX* ctx) override;
33
34private:
35 const uint32_t mValidSeconds;
36};
37
Yifan Hongb1ce80c2021-09-17 22:10:58 -070038class RpcAuthPreSigned : public RpcAuth {
39public:
40 RpcAuthPreSigned(bssl::UniquePtr<EVP_PKEY> pkey, bssl::UniquePtr<X509> cert)
41 : mPkey(std::move(pkey)), mCert(std::move(cert)) {}
42 status_t configure(SSL_CTX* ctx) override;
43
44private:
45 bssl::UniquePtr<EVP_PKEY> mPkey;
46 bssl::UniquePtr<X509> mCert;
47};
48
Yifan Hongffdaf952021-09-17 18:08:38 -070049} // namespace android