14#ifndef OPENVPN_MBEDTLS_PKI_X509CERT_H
15#define OPENVPN_MBEDTLS_PKI_X509CERT_H
22#include <mbedtls/x509.h>
23#include <mbedtls/pem.h>
24#include <mbedtls/base64.h>
58 void parse(
const std::string &
cert_txt,
const std::string &title,
const bool strict)
67 const int status = mbedtls_x509_crt_parse(
chain,
68 (
const unsigned char *)
cert_txt.c_str(),
76 std::ostringstream
os;
77 os << status <<
" certificate(s) in " << title <<
" bundle failed to parse";
85 static std::string
der_to_pem(
const unsigned char *der,
size_t der_size)
97 if (
ret != MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL)
112 return std::string((
const char *)buff.
data());
122 std::vector<std::string> extra_certs;
125 for (mbedtls_x509_crt *cert =
chain->next; cert; cert = cert->next)
127 extra_certs.push_back(
der_to_pem(cert->raw.p, cert->raw.len));
132 mbedtls_x509_crt *
get()
const
147 chain =
new mbedtls_x509_crt;
148 mbedtls_x509_crt_init(
chain);
159 mbedtls_x509_crt_free(
chain);
165 constexpr static const char *
begin_cert =
"-----BEGIN CERTIFICATE-----\n";
166 constexpr static const char *
end_cert =
"-----END CERTIFICATE-----\n";
size_t max_size() const
Return the maximum allowable size value in T objects given the current offset (without considering re...
T * data()
Get a mutable pointer to the start of the array.
std::vector< std::string > extract_extra_certs() const
void parse(const std::string &cert_txt, const std::string &title, const bool strict)
mbedtls_x509_crt * get() const
X509Cert(const std::string &cert_txt, const std::string &title, const bool strict)
static constexpr const char * end_cert
std::string extract() const
static std::string der_to_pem(const unsigned char *der, size_t der_size)
static constexpr const char * begin_cert
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
#define OPENVPN_LOG(args)
const std::string cert_txt