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"
18#include "ClientContext.h"
22using namespace Stroika::Foundation::Cryptography;
23using namespace Stroika::Foundation::Cryptography::Providers;
24using namespace Stroika::Foundation::Cryptography::Providers::OpenSSL;
25using namespace Stroika::Foundation::Debug;
27using Memory::MakeSharedPtr;
32#if qStroika_HasComponent_OpenSSL
34 using OpenSSL::ClientContext::Options;
35 struct Rep_ : OpenSSL::ClientContext::IRep {
36 OpenSSL::ClientContext::LibRepType fCtx_;
38 Rep_ (
const Options& o)
39 : fCtx_{::SSL_CTX_new (::TLS_client_method ())}
41 if (o.fClientCertificate) {
42 Cryptography::PKI::Certificate::Ptr clientCert = get<PKI::Certificate::Ptr> (*o.fClientCertificate);
43 OpenSSL::Exception::ThrowLastErrorIfFailed (::SSL_CTX_use_certificate (fCtx_.get (), OpenSSL::Certificate::Ptr{clientCert}.Get_X509 ()));
44 PKI::PrivateKey::Ptr pkey = get<PKI::PrivateKey::Ptr> (*o.fClientCertificate);
45 OpenSSL::Exception::ThrowLastErrorIfFailed (::SSL_CTX_use_PrivateKey (fCtx_.get (), OpenSSL::PrivateKey::Ptr{pkey}.Get_EVP_PKEY ()));
48 SSL_CTX* Get_SSL_CTX ()
const override
56#if qStroika_HasComponent_OpenSSL
57auto OpenSSL::ClientContext::New (
const Options& o) -> Ptr
59 return MakeSharedPtr<Rep_> (o);