blob: 7670bcb22383a9d4b9e60b52b2e99148b10cc096 [file] [log] [blame]
Ed Tanous724985f2024-06-05 09:19:06 -07001
2
Ed Tanous0fdddb12017-02-28 11:06:34 -08003#pragma once
4
Ed Tanous3112a142018-11-29 15:45:10 -08005#include <boost/asio/ssl/context.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05006
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007#include <optional>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include <string>
Ed Tanous1abe55e2018-09-05 08:30:59 -07009
10namespace ensuressl
11{
AppaRao Pulie38778a2022-06-27 23:09:03 +000012
Ed Tanous19bb3622024-07-05 10:07:40 -050013enum class VerifyCertificate
14{
15 Verify,
16 NoVerify
17};
18
Ed Tanous724985f2024-06-05 09:19:06 -070019constexpr const char* trustStorePath = "/etc/ssl/certs/authority";
20constexpr const char* x509Comment = "Generated from OpenBMC service";
Abhilash Rajud5fb5842024-06-03 11:40:17 -050021
Ed Tanous724985f2024-06-05 09:19:06 -070022bool isTrustChainError(int errnum);
AppaRao Pulie38778a2022-06-27 23:09:03 +000023
Ed Tanous724985f2024-06-05 09:19:06 -070024bool validateCertificate(X509* cert);
AppaRao Pulie38778a2022-06-27 23:09:03 +000025
Ed Tanous724985f2024-06-05 09:19:06 -070026std::string verifyOpensslKeyCert(const std::string& filepath);
AppaRao Pulie38778a2022-06-27 23:09:03 +000027
Ed Tanous724985f2024-06-05 09:19:06 -070028X509* loadCert(const std::string& filePath);
AppaRao Pulie38778a2022-06-27 23:09:03 +000029
Ed Tanous724985f2024-06-05 09:19:06 -070030int addExt(X509* cert, int nid, const char* value);
Ed Tanous19bb3622024-07-05 10:07:40 -050031
Ed Tanous724985f2024-06-05 09:19:06 -070032std::string generateSslCertificate(const std::string& cn);
AppaRao Pulie38778a2022-06-27 23:09:03 +000033
Ed Tanous724985f2024-06-05 09:19:06 -070034void writeCertificateToFile(const std::string& filepath,
35 const std::string& certificate);
AppaRao Pulie38778a2022-06-27 23:09:03 +000036
Ed Tanous724985f2024-06-05 09:19:06 -070037std::string ensureOpensslKeyPresentAndValid(const std::string& filepath);
38
39std::shared_ptr<boost::asio::ssl::context> getSslServerContext();
40
41std::optional<boost::asio::ssl::context>
42 getSSLClientContext(VerifyCertificate verifyCertificate);
AppaRao Pulie38778a2022-06-27 23:09:03 +000043
Ed Tanous1abe55e2018-09-05 08:30:59 -070044} // namespace ensuressl