Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors | ||||
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 3 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 4 | #pragma once |
5 | |||||
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 6 | #include <openssl/crypto.h> |
7 | |||||
Ed Tanous | 3112a14 | 2018-11-29 15:45:10 -0800 | [diff] [blame] | 8 | #include <boost/asio/ssl/context.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 9 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 10 | #include <memory> |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 11 | #include <optional> |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 12 | #include <string> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 13 | |
14 | namespace ensuressl | ||||
15 | { | ||||
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 16 | |
Ed Tanous | 19bb362 | 2024-07-05 10:07:40 -0500 | [diff] [blame] | 17 | enum class VerifyCertificate |
18 | { | ||||
19 | Verify, | ||||
20 | NoVerify | ||||
21 | }; | ||||
22 | |||||
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 23 | constexpr const char* trustStorePath = "/etc/ssl/certs/authority"; |
24 | constexpr const char* x509Comment = "Generated from OpenBMC service"; | ||||
Abhilash Raju | d5fb584 | 2024-06-03 11:40:17 -0500 | [diff] [blame] | 25 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 26 | bool isTrustChainError(int errnum); |
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 27 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 28 | bool validateCertificate(X509* cert); |
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 29 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 30 | std::string verifyOpensslKeyCert(const std::string& filepath); |
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 31 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 32 | X509* loadCert(const std::string& filePath); |
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 33 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 34 | int addExt(X509* cert, int nid, const char* value); |
Ed Tanous | 19bb362 | 2024-07-05 10:07:40 -0500 | [diff] [blame] | 35 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 36 | std::string generateSslCertificate(const std::string& cn); |
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 37 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 38 | void writeCertificateToFile(const std::string& filepath, |
39 | const std::string& certificate); | ||||
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 40 | |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 41 | std::string ensureOpensslKeyPresentAndValid(const std::string& filepath); |
42 | |||||
43 | std::shared_ptr<boost::asio::ssl::context> getSslServerContext(); | ||||
44 | |||||
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 45 | std::optional<boost::asio::ssl::context> getSSLClientContext( |
46 | VerifyCertificate verifyCertificate); | ||||
AppaRao Puli | e38778a | 2022-06-27 23:09:03 +0000 | [diff] [blame] | 47 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 48 | } // namespace ensuressl |