blob: fad89fc2bc95be3a5574bd9510cb21dafe6bb7eb [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 Tanousd7857202025-01-28 15:32:26 -08006#include <openssl/crypto.h>
7
Ed Tanous3112a142018-11-29 15:45:10 -08008#include <boost/asio/ssl/context.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05009
Ed Tanousd7857202025-01-28 15:32:26 -080010#include <memory>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080011#include <optional>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080012#include <string>
Ed Tanous1abe55e2018-09-05 08:30:59 -070013
14namespace ensuressl
15{
AppaRao Pulie38778a2022-06-27 23:09:03 +000016
Ed Tanous19bb3622024-07-05 10:07:40 -050017enum class VerifyCertificate
18{
19 Verify,
20 NoVerify
21};
22
Ed Tanous724985f2024-06-05 09:19:06 -070023constexpr const char* trustStorePath = "/etc/ssl/certs/authority";
24constexpr const char* x509Comment = "Generated from OpenBMC service";
Abhilash Rajud5fb5842024-06-03 11:40:17 -050025
Ed Tanous724985f2024-06-05 09:19:06 -070026bool isTrustChainError(int errnum);
AppaRao Pulie38778a2022-06-27 23:09:03 +000027
Ed Tanous724985f2024-06-05 09:19:06 -070028bool validateCertificate(X509* cert);
AppaRao Pulie38778a2022-06-27 23:09:03 +000029
Ed Tanous724985f2024-06-05 09:19:06 -070030std::string verifyOpensslKeyCert(const std::string& filepath);
AppaRao Pulie38778a2022-06-27 23:09:03 +000031
Ed Tanous724985f2024-06-05 09:19:06 -070032X509* loadCert(const std::string& filePath);
AppaRao Pulie38778a2022-06-27 23:09:03 +000033
Ed Tanous724985f2024-06-05 09:19:06 -070034int addExt(X509* cert, int nid, const char* value);
Ed Tanous19bb3622024-07-05 10:07:40 -050035
Ed Tanous724985f2024-06-05 09:19:06 -070036std::string generateSslCertificate(const std::string& cn);
AppaRao Pulie38778a2022-06-27 23:09:03 +000037
Ed Tanous724985f2024-06-05 09:19:06 -070038void writeCertificateToFile(const std::string& filepath,
39 const std::string& certificate);
AppaRao Pulie38778a2022-06-27 23:09:03 +000040
Ed Tanous724985f2024-06-05 09:19:06 -070041std::string ensureOpensslKeyPresentAndValid(const std::string& filepath);
42
43std::shared_ptr<boost::asio::ssl::context> getSslServerContext();
44
Patrick Williams504af5a2025-02-03 14:29:03 -050045std::optional<boost::asio::ssl::context> getSSLClientContext(
46 VerifyCertificate verifyCertificate);
AppaRao Pulie38778a2022-06-27 23:09:03 +000047
Ed Tanous1abe55e2018-09-05 08:30:59 -070048} // namespace ensuressl