12#ifndef OPENVPN_AUTH_AUTHCERT_H
13#define OPENVPN_AUTH_AUTHCERT_H
63 void add_fail(
const size_t depth,
const Type new_code, std::string reason)
67 while (
errors.size() <= depth)
69 std::string &err =
errors[depth];
71 err = std::move(reason);
72 else if (err.find(reason) == std::string::npos)
97 bool notfirst =
false;
98 for (
size_t i = 0; i <
errors.size(); ++i)
123 return "BAD_CERT_TYPE";
156#ifdef OPENVPN_JSON_INTERNAL
157 Serial(
const Json::Value &jsn)
162 case Json::uintValue:
165 case Json::stringValue:
168 case Json::nullValue:
169 throw serial_number_error(
"JSON serial is missing");
172 throw serial_number_error(
"JSON serial is of incorrect type (must be integer or string)");
179 for (
size_t i = 0; i < 5; ++i)
193 const std::int64_t
ret = std::int64_t((std::uint64_t(ntohl(
serial_number32[3])) << 32)
218 bool leading0 =
true;
219 for (
size_t i = 0; i <
size(); ++i)
222 const bool last = (i ==
size() - 1);
223 if (!
byte && leading0 && !last)
255 throw Exception(std::string(
"'") + c +
"' is not a hex char");
256 return std::uint8_t(h);
288 for (
auto ci = sn_str.crbegin(); ci != sn_str.crend(); ++ci)
304 throw Exception(
"serial number too large (C2)");
316 throw Exception(
"serial number too large (C1)");
325 throw Exception(
"expected leading serial number hex digit");
327 catch (
const std::exception &e)
329 throw serial_number_error(e.what());
346 AuthCert(std::string cn_arg,
const std::int64_t sn)
348 cn(std::move(cn_arg)),
356 const std::string &issuer_fp_arg,
357 const Serial &serial_arg)
362 parse_issuer_fp(issuer_fp_arg);
381 template <
typename T>
417 std::ostringstream os;
419 os <<
"SNI=" <<
sni <<
' ';
421 os <<
"SNI_CN=" <<
sni_metadata->sni_client_name(*
this) <<
' ';
446 return cn.substr(0,
cn.length() - 10);
485 fail->add_fail(depth, new_code, std::move(reason));
501 return fail->to_string(
true);
511 void parse_issuer_fp(
const std::string &issuer_fp_hex)
516 throw Exception(
"bad length in issuer_fp hex string");
std::string to_string(const bool use_prefix) const
static std::string render_code(const Type code)
void add_fail(const size_t depth, const Type new_code, std::string reason)
std::vector< std::string > errors
static std::string to_string(const std::uint8_t *serial_number)
Serial(const std::string &sn_str)
bool operator==(const Serial &other) const
const std::uint8_t * number() const
bool operator!=(const Serial &other) const
void init_from_string(const std::string &sn_str)
OPENVPN_EXCEPTION(serial_number_error)
std::int64_t as_int64() const
static constexpr size_t size()
Serial(const std::int64_t sn)
std::string to_string() const
std::uint32_t serial_number32[5]
std::uint8_t parse_hex(const char c)
void init_from_int64(const std::int64_t sn)
std::uint8_t serial_number[20]
AuthCert(std::string cn_arg, const std::int64_t sn)
const Fail * get_fail() const
SNI::Metadata::UPtr sni_metadata
std::string serial_number_str() const
std::string to_string() const
std::string issuer_fp_str(const bool openssl_fmt) const
std::unique_ptr< Fail > fail
bool operator==(const AuthCert &other) const
std::string fail_str() const
std::string sni_client_name() const
std::unique_ptr< X509Track::Set > x509_track_take_ownership()
bool operator!=(const AuthCert &other) const
std::uint8_t issuer_fp[20]
const Serial & get_serial() const
const std::string & get_cn() const
std::string normalize_cn() const
std::int64_t serial_number_as_int64() const
const X509Track::Set * x509_track_get() const
const std::string & get_sni() const
std::unique_ptr< X509Track::Set > x509_track
void add_fail(const size_t depth, const Fail::Type new_code, std::string reason)
T issuer_fp_prefix() const
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
bool ends_with(const STRING &str, const std::string &suffix)
Support deferred server-side state creation when client connects.
std::string to_string(T value)
void parse_hex(V &dest, const std::string &str)
int parse_hex_char(const int c)
std::string render_hex(const unsigned char *data, size_t size, const bool caps=false)
std::string render_hex_sep(const unsigned char *data, size_t size, const char sep, const bool caps=false)