4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_HasComponent_OpenSSL
7#include <openssl/evp.h>
8#include <openssl/ssl.h>
11#include "Stroika/Foundation/Cryptography/Providers/OpenSSL/Certificate.h"
13#include "Stroika/Foundation/Cryptography/Providers/OpenSSL/PrivateKey.h"
15#include "Stroika/Foundation/Execution/Exceptions.h"
17#include "ClientContext.h"
21using namespace Stroika::Foundation::Cryptography;
22using namespace Stroika::Foundation::Cryptography::Providers;
23using namespace Stroika::Foundation::Cryptography::Providers::OpenSSL;
24using namespace Stroika::Foundation::Debug;
29#if qStroika_HasComponent_OpenSSL
31 using OpenSSL::ClientContext::Options;
32 struct Rep_ : OpenSSL::ClientContext::IRep {
33 OpenSSL::ClientContext::LibRepType fCtx_;
35 Rep_ (
const Options& o)
36 : fCtx_{::SSL_CTX_new (::TLS_client_method ())}
38 if (o.fClientCertificate) {
39 Cryptography::PKI::Certificate::Ptr clientCert = get<PKI::Certificate::Ptr> (*o.fClientCertificate);
40 OpenSSL::Exception::ThrowLastErrorIfFailed (::SSL_CTX_use_certificate (fCtx_.get (), OpenSSL::Certificate::Ptr{clientCert}.Get_X509 ()));
41 PKI::PrivateKey::Ptr pkey = get<PKI::PrivateKey::Ptr> (*o.fClientCertificate);
42 OpenSSL::Exception::ThrowLastErrorIfFailed (::SSL_CTX_use_PrivateKey (fCtx_.get (), OpenSSL::PrivateKey::Ptr{pkey}.Get_EVP_PKEY ()));
45 SSL_CTX* Get_SSL_CTX ()
const override
53#if qStroika_HasComponent_OpenSSL
54auto OpenSSL::ClientContext::New (
const Options& o) -> Ptr
56 return make_shared<Rep_> (o);