/*** 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(const TLSMeta &meta); TLSContext(const AuSPtr &pSendStack, const AuSPtr &pRecvStack, const TLSMeta &meta); ~TLSContext(); bool Init(); virtual void Destroy() override; virtual AuSPtr ToReadStack() override; virtual AuSPtr ToWriteStack() override; virtual AuSPtr GetRecvInterceptor() override; virtual AuSPtr GetSendInterceptor() override; virtual void Attach(const AuSPtr &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 {}; 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(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 cipherSuites_; TLSMeta meta_; AuWPtr wpSocket_; TLSProtocolRecv channelRecv_; TLSProtocolSend channelSend_; AuSPtr pSendStack_; AuSPtr pRecvStack_; AuWPtr pPiece_; }; }