Yifan Hong | ffdaf95 | 2021-09-17 18:08:38 -0700 | [diff] [blame] | 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 <binder/RpcAuth.h> |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | constexpr const uint32_t kCertValidSeconds = 30 * (60 * 60 * 24); // 30 days |
| 24 | bssl::UniquePtr<EVP_PKEY> makeKeyPairForSelfSignedCert(); |
| 25 | bssl::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. |
| 29 | class RpcAuthSelfSigned : public RpcAuth { |
| 30 | public: |
| 31 | RpcAuthSelfSigned(uint32_t validSeconds = kCertValidSeconds) : mValidSeconds(validSeconds) {} |
| 32 | status_t configure(SSL_CTX* ctx) override; |
| 33 | |
| 34 | private: |
| 35 | const uint32_t mValidSeconds; |
| 36 | }; |
| 37 | |
Yifan Hong | b1ce80c | 2021-09-17 22:10:58 -0700 | [diff] [blame] | 38 | class RpcAuthPreSigned : public RpcAuth { |
| 39 | public: |
| 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 | |
| 44 | private: |
| 45 | bssl::UniquePtr<EVP_PKEY> mPkey; |
| 46 | bssl::UniquePtr<X509> mCert; |
| 47 | }; |
| 48 | |
Yifan Hong | ffdaf95 | 2021-09-17 18:08:38 -0700 | [diff] [blame] | 49 | } // namespace android |