2022-08-28 19:02:06 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: TLSContext.hpp
|
|
|
|
Date: 2022-8-24
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
2022-08-31 17:46:50 +00:00
|
|
|
#include "TLS.hpp"
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
#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();
|
|
|
|
|
2022-08-30 21:18:15 +00:00
|
|
|
bool Init();
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-08-31 17:46:50 +00:00
|
|
|
virtual AuUInt16 GetCurrentCipherSuite() override;
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
virtual bool HasCompletedHandshake() override;
|
|
|
|
virtual bool HasEnded() override;
|
|
|
|
virtual bool HasFailed() override;
|
|
|
|
|
|
|
|
int GetFatalErrorCode() override;
|
|
|
|
|
2022-08-30 21:18:15 +00:00
|
|
|
AuString GetFatalErrorCodeAsString() override;
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
void OnClose();
|
|
|
|
void OnFatal();
|
|
|
|
|
|
|
|
bool bIsDead {};
|
|
|
|
bool bIsFatal {};
|
|
|
|
bool bIsAlive {};
|
|
|
|
|
2022-11-18 04:15:05 +00:00
|
|
|
bool bPinLock_ {};
|
2022-08-28 19:02:06 +00:00
|
|
|
int iFatalError {};
|
|
|
|
|
2022-08-31 17:46:50 +00:00
|
|
|
mbedtls_ssl_context ssl {};
|
|
|
|
mbedtls_ssl_config conf {};
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
int Read(void *pOut, AuUInt length);
|
|
|
|
int Write(const void *pIn, AuUInt length);
|
2022-11-18 04:15:05 +00:00
|
|
|
bool CheckCertificate(mbedtls_x509_crt const *child, const AuMemoryViewRead &read);
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
private:
|
2022-08-31 17:46:50 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-08-29 18:57:24 +00:00
|
|
|
AuList<int> cipherSuites_;
|
2022-08-28 19:02:06 +00:00
|
|
|
TLSMeta meta_;
|
|
|
|
AuWPtr<Net::ISocket> wpSocket_;
|
|
|
|
TLSProtocolRecv channelRecv_;
|
|
|
|
TLSProtocolSend channelSend_;
|
2022-08-30 21:18:15 +00:00
|
|
|
AuSPtr<Protocol::ProtocolStack> pSendStack_;
|
|
|
|
AuSPtr<Protocol::ProtocolStack> pRecvStack_;
|
2022-10-01 00:07:26 +00:00
|
|
|
AuWPtr<Protocol::IProtocolPiece> pPiece_;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|