blob: dbc2720b2accbeca3fb0fb724faaa4cab7b6e7f9 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous724985f2024-06-05 09:19:06 -07003
Ed Tanous0fdddb12017-02-28 11:06:34 -08004#pragma once
5
Ed Tanous3112a142018-11-29 15:45:10 -08006#include <boost/asio/ssl/context.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05007
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include <optional>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08009#include <string>
Ed Tanous1abe55e2018-09-05 08:30:59 -070010
11namespace ensuressl
12{
AppaRao Pulie38778a2022-06-27 23:09:03 +000013
Ed Tanous19bb3622024-07-05 10:07:40 -050014enum class VerifyCertificate
15{
16 Verify,
17 NoVerify
18};
19
Ed Tanous724985f2024-06-05 09:19:06 -070020constexpr const char* trustStorePath = "/etc/ssl/certs/authority";
21constexpr const char* x509Comment = "Generated from OpenBMC service";
Abhilash Rajud5fb5842024-06-03 11:40:17 -050022
Ed Tanous724985f2024-06-05 09:19:06 -070023bool isTrustChainError(int errnum);
AppaRao Pulie38778a2022-06-27 23:09:03 +000024
Ed Tanous724985f2024-06-05 09:19:06 -070025bool validateCertificate(X509* cert);
AppaRao Pulie38778a2022-06-27 23:09:03 +000026
Ed Tanous724985f2024-06-05 09:19:06 -070027std::string verifyOpensslKeyCert(const std::string& filepath);
AppaRao Pulie38778a2022-06-27 23:09:03 +000028
Ed Tanous724985f2024-06-05 09:19:06 -070029X509* loadCert(const std::string& filePath);
AppaRao Pulie38778a2022-06-27 23:09:03 +000030
Ed Tanous724985f2024-06-05 09:19:06 -070031int addExt(X509* cert, int nid, const char* value);
Ed Tanous19bb3622024-07-05 10:07:40 -050032
Ed Tanous724985f2024-06-05 09:19:06 -070033std::string generateSslCertificate(const std::string& cn);
AppaRao Pulie38778a2022-06-27 23:09:03 +000034
Ed Tanous724985f2024-06-05 09:19:06 -070035void writeCertificateToFile(const std::string& filepath,
36 const std::string& certificate);
AppaRao Pulie38778a2022-06-27 23:09:03 +000037
Ed Tanous724985f2024-06-05 09:19:06 -070038std::string ensureOpensslKeyPresentAndValid(const std::string& filepath);
39
40std::shared_ptr<boost::asio::ssl::context> getSslServerContext();
41
42std::optional<boost::asio::ssl::context>
43 getSSLClientContext(VerifyCertificate verifyCertificate);
AppaRao Pulie38778a2022-06-27 23:09:03 +000044
Ed Tanous1abe55e2018-09-05 08:30:59 -070045} // namespace ensuressl