AuroraRuntime/Source/IO/TLS/TLSContext.hpp
Reece Wilson d9dd1182b9 [+] TLS pinning
[*] ISocket::Shutdown(*bool bNow*), allowing for flush of the send channel when false
[*] Fix StartRead and StartWrite after shutdown (NT)
[*] Amended dead-lock
2022-11-18 04:44:47 +00:00

99 lines
2.6 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: TLSContext.hpp
Date: 2022-8-24
Author: Reece
***/
#pragma once
#include "TLS.hpp"
#include "TLSProtocolRecv.hpp"
#include "TLSProtocolSend.hpp"
namespace Aurora::IO::Protocol
{
struct ProtocolStack;
}
namespace Aurora::IO::TLS
{
void TLSInit();
struct TLSContext : ITLSContext, AuEnableSharedFromThis<TLSContext>
{
TLSContext(const TLSMeta &meta);
TLSContext(const AuSPtr<Protocol::IProtocolStack> &pSendStack,
const AuSPtr<Protocol::IProtocolStack> &pRecvStack,
const TLSMeta &meta);
~TLSContext();
bool Init();
virtual void Destroy() override;
virtual AuSPtr<Protocol::IProtocolStack> ToReadStack() override;
virtual AuSPtr<Protocol::IProtocolStack> ToWriteStack() override;
virtual AuSPtr<Protocol::IProtocolInterceptorEx> GetRecvInterceptor() override;
virtual AuSPtr<Protocol::IProtocolInterceptorEx> GetSendInterceptor() override;
virtual void Attach(const AuSPtr<Net::ISocket> &pSocket) override;
virtual void StartHandshake() override;
virtual void StartClose() override;
virtual AuUInt16 GetCurrentCipherSuite() override;
virtual bool HasCompletedHandshake() override;
virtual bool HasEnded() override;
virtual bool HasFailed() override;
int GetFatalErrorCode() override;
AuString GetFatalErrorCodeAsString() override;
void OnClose();
void OnFatal();
bool bIsDead {};
bool bIsFatal {};
bool bIsAlive {};
bool bPinLock_ {};
int iFatalError {};
mbedtls_ssl_context ssl {};
mbedtls_ssl_config conf {};
int Read(void *pOut, AuUInt length);
int Write(const void *pIn, AuUInt length);
bool CheckCertificate(mbedtls_x509_crt const *child, const AuMemoryViewRead &read);
private:
mbedtls_timing_delay_context timer_ {};
#if defined(MBEDTLS_SSL_COOKIE_C)
mbedtls_ssl_cookie_ctx cookieCtx_ {};
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
mbedtls_ssl_ticket_context ticketCtx_ {};
#endif
#if defined(MBEDTLS_SSL_CACHE_C)
mbedtls_ssl_cache_context cache_ {};
#endif
AuList<int> cipherSuites_;
TLSMeta meta_;
AuWPtr<Net::ISocket> wpSocket_;
TLSProtocolRecv channelRecv_;
TLSProtocolSend channelSend_;
AuSPtr<Protocol::ProtocolStack> pSendStack_;
AuSPtr<Protocol::ProtocolStack> pRecvStack_;
AuWPtr<Protocol::IProtocolPiece> pPiece_;
};
}