0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 19:58:53 +02:00

ircd::openssl: Add function to print subject of certificate.

This commit is contained in:
Jason Volk 2018-01-12 15:31:58 -08:00
parent 06cf9031b7
commit c1a3fabd5a
2 changed files with 23 additions and 0 deletions

View file

@ -109,6 +109,7 @@ namespace ircd::openssl
string_view genX509(const mutable_buffer &out, EVP_PKEY &, const json::object &opts);
string_view genX509_rsa(const mutable_buffer &out, const json::object &opts);
string_view genX509_ec(const mutable_buffer &out, const json::object &opts);
string_view print_subject(const mutable_buffer &buf, const X509 &, ulong flags = -1);
string_view subject_common_name(const mutable_buffer &out, const X509 &);
const X509 &peer_cert(const SSL &);
X509 &peer_cert(SSL &);

View file

@ -373,6 +373,28 @@ ircd::openssl::subject_common_name(const mutable_buffer &out,
return { data(out), size_t(len) };
}
ircd::string_view
ircd::openssl::print_subject(const mutable_buffer &buf,
const X509 &cert,
ulong flags)
{
if(flags == ulong(-1))
flags = XN_FLAG_ONELINE;
else
flags = 0;
const X509_NAME *const subject
{
X509_get_subject_name(const_cast<X509 *>(&cert))
};
return bio::write(buf, [&subject, &flags]
(BIO *const &bio)
{
X509_NAME_print_ex(bio, const_cast<X509_NAME *>(subject), 0, flags);
});
}
ircd::string_view
ircd::openssl::printX509(const mutable_buffer &buf,
const string_view &pem,