0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::openssl: Add X509_STORE_CTX suite.

This commit is contained in:
Jason Volk 2018-01-04 22:00:10 -08:00
parent 35ad641251
commit b878fd6ed0
2 changed files with 70 additions and 0 deletions

View file

@ -31,6 +31,7 @@
struct ssl_st;
struct rsa_st;
struct x509_st;
struct x509_store_ctx_st;
struct bignum_st;
struct bignum_ctx;
struct bio_st;
@ -52,6 +53,7 @@ namespace ircd::openssl
using SSL = ::ssl_st;
using RSA = ::rsa_st;
using X509 = ::x509_st;
using X509_STORE_CTX = ::x509_store_ctx_st;
using BIGNUM = ::bignum_st;
using BN_CTX = ::bignum_ctx;
using EVP_PKEY = ::evp_pkey_st;
@ -92,6 +94,13 @@ namespace ircd::openssl
string_view genX509(const mutable_buffer &out, const json::object &opts);
const X509 &peer_cert(const SSL &);
X509 &peer_cert(SSL &);
int get_error(const X509_STORE_CTX &);
const char *cert_error_string(const long &);
const char *get_error_string(const X509_STORE_CTX &);
uint get_error_depth(const X509_STORE_CTX &);
const X509 &current_cert(const X509_STORE_CTX &);
X509 &current_cert(X509_STORE_CTX &);
}
/// OpenSSL BIO convenience utils and wraps; also secure file IO closures

View file

@ -57,6 +57,67 @@ namespace ircd::openssl
void append_entries(X509 &cert, const json::object &opts);
}
X509 &
ircd::openssl::current_cert(X509_STORE_CTX &cx)
{
auto *const ret
{
X509_STORE_CTX_get_current_cert(&cx)
};
if(!ret)
throw std::out_of_range{"No current certificate"};
return *ret;
}
const X509 &
ircd::openssl::current_cert(const X509_STORE_CTX &cx)
{
auto &mcx{const_cast<X509_STORE_CTX &>(cx)};
const auto *const ret
{
X509_STORE_CTX_get_current_cert(&mcx)
};
if(!ret)
throw std::out_of_range{"No current certificate"};
return *ret;
}
uint
ircd::openssl::get_error_depth(const X509_STORE_CTX &cx)
{
auto &mcx{const_cast<X509_STORE_CTX &>(cx)};
const int ret
{
X509_STORE_CTX_get_error_depth(&mcx)
};
assert(ret >= 0);
return ret;
}
const char *
ircd::openssl::get_error_string(const X509_STORE_CTX &cx)
{
return cert_error_string(get_error(cx));
}
const char *
ircd::openssl::cert_error_string(const long &n)
{
return X509_verify_cert_error_string(n);
}
int
ircd::openssl::get_error(const X509_STORE_CTX &cx)
{
auto &mcx{const_cast<X509_STORE_CTX &>(cx)};
return X509_STORE_CTX_get_error(&mcx);
}
X509 &
ircd::openssl::peer_cert(SSL &ssl)
{