38 std::shared_ptr<CA> peer_ca_,
39 std::optional<ccf::crypto::Pem> own_cert_ = std::nullopt,
40 std::optional<ccf::crypto::Pem> own_pkey_ = std::nullopt,
41 std::optional<std::string> peer_hostname_ = std::nullopt,
42 bool auth_required_ =
true) :
43 peer_ca(
std::move(peer_ca_)),
44 peer_hostname(
std::move(peer_hostname_)),
45 auth_required(auth_required_)
47 if (own_cert_.has_value() && own_pkey_.has_value())
57 std::make_shared<ccf::crypto::ECKeyPair_OpenSSL>(*own_pkey_);
62 for (
auto it = certs.begin() + 1; it != certs.end(); ++it)
67 CHECK1(sk_X509_push(chain, cert));
76 void use(SSL* ssl, SSL_CTX* ssl_ctx)
78 if (peer_hostname.has_value())
81 SSL_set_tlsext_host_name(ssl, peer_hostname->c_str());
86 peer_ca->use(ssl_ctx);
91 int opts = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
92 auto cb = [](
int ok, x509_store_ctx_st*) {
96 SSL_CTX_set_verify(ssl_ctx, opts, cb);
97 SSL_set_verify(ssl, opts, cb);
107 auto cb = [](int, x509_store_ctx_st*) {
return 1; };
108 SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, cb);
109 SSL_set_verify(ssl, SSL_VERIFY_PEER, cb);
115 SSL_CTX_use_cert_and_key(ssl_ctx, own_cert, *own_pkey, chain, 1));
116 CHECK1(SSL_use_cert_and_key(ssl, own_cert, *own_pkey, chain, 1));