AuroraRuntime/Include/Aurora/IO/TLS/ITLSContext.hpp
Reece Wilson 67905a4192 [+] Network + Protocol + TLS - Initial Commit
=============================================================================
Network ]====================================================================
=============================================================================

[+] Added (very) early Aurora::IO::Net implementation
[+] AuNet::EHostnameType
[+] AuNet::EIPProtocol
[+] AuNet::ENetworkError
[+] AuNet::ETransportProtocol
[+] AuNet::INetInterface
[+] AuNet::INetSrvDatagram
[+] AuNet::INetSrvResolve
[+] AuNet::INetSrvSockets
[+] AuNet::INetSrvWorkers
[+] AuNet::INetWorker
[+] AuNet::IPAddress
[+] AuNet::IResolver
[+] AuNet::ISocket
[+] AuNet::IResolver
[+] AuNet::ISocketBase
[+] AuNet::ISocketChannel
[+] AuNet::ISocketDriver
[+] AuNet::ISocketDriverFactory
[+] AuNet::ISocketServer
[+] AuNet::ISocketServerDriver
[+] AuNet::NetEndpoint
[+] AuNet::NetError
[+] AuNet::NetHostname
(+implementation)

=============================================================================
Protocol ]===================================================================
=============================================================================

[+] IProtocolInterceptor
[+] IProtocolInterceptorEx
[+] IProtocolStack
(+implementation)

=============================================================================
TLS ]========================================================================
=============================================================================

[+] ITLSContext
[+] TLSProtocolRecv
[+] TLSProtocolSend
(+implementation)

=============================================================================
IO Bug Fixes ]===============================================================
=============================================================================

[*] IOProcessor::SubmitIOWorkItem should signal the CvEvent, forcing at least once future tick (wont optimize with if in tick & not yet dispatched work items)
[*] Split IOPipeWork in into IOPipeProcessor header
[+] IOPipeWork::GetBuffer (internal reallocation)
[*] Harden against IAsyncTransactions without a loop source
[*] Missing null `if (processor->listener)` in IOProcessor
[*] Solved some soft-lock conditions under Linux's LoopQueue (added deferred commits)
[*] Quick hack: IOProcessor::HasItems() should OR the early can-tick check function.

=============================================================================
Other ]======================================================================
=============================================================================

[+] Linux: LSSignalCatcher
[+] `static void AuResetMember(Aurora::Memory::ByteBuffer &ref)` for AuROXTL
[*] Attempt to enforce a normalization and don't overwrite-readptr-under-istreamwriters policy in ByteBuffer_ReadWrite (circular buffers)
[*] Bad ECC ctors

=============================================================================
Known issues ]===============================================================
=============================================================================

> Linux net is nowhere near done
> UDP socket emulation layer isn't implemented
> Ciphersuite API is a stub
> Private key API is a stub
> ...therefore no TLS servers
> Missing thread safety precautions under net
> Net implementation is still beri early
2022-08-28 20:02:06 +01:00

131 lines
3.6 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ITLSContext.hpp
Date: 2022-8-24
Author: Reece
***/
#pragma once
namespace Aurora::IO::Protocol
{
struct IProtocolStack;
}
namespace Aurora::IO::Net
{
struct ISocket;
}
#include <Aurora/IO/Net/ETransportProtocol.hpp>
namespace Aurora::IO::TLS
{
struct TLSMeta
{
AuUInt uOutPageSize {};
AuString sSNIServerName;
bool bIsClient { true };
AuNet::ETransportProtocol transportProtocol { AuNet::ETransportProtocol::eProtocolTCP };
AuSPtr<IPinCertificate> pCertPin;
TLSPrivateKey privateKey;
AuList<AuUInt16> cipherSuites;
};
struct ITLSContext
{
/**
* @brief Returns the protocol stack provided to NewTLSContextEx
* @return
*/
virtual AuSPtr<Protocol::IProtocolStack> ToReadStack() = 0;
/**
* @brief Returns the protocol stack provided to NewTLSContextEx
* @return
*/
virtual AuSPtr<Protocol::IProtocolStack> ToWriteStack() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<Protocol::IProtocolInterceptorEx> GetRecvInterceptor() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<Protocol::IProtocolInterceptorEx> GetSendInterceptor() = 0;
/**
* @brief Attaches the context to a socket such that
* 1) the sockets inbound protocol is specified as this->ToReadStack()
* 2) the sockets outbound protocol is specified as this->ToWriteStack()
* 3) a weak reference is attached internally for internal shutdown/error triggers
*
* This is optional. You could just use a buffered protocol stack
*
* @param pSocket
* @warning reminder: Creating a tls context is to merely add interceptors to a new protocol stack.
* This function is a hybrid utility that does one internal action and calls
* ISocketChannel::SpecifyRecvProtocol, ISocketChannel::SpecifySendProtocol to
* activate the protocol stack on the socket (if not already).
*/
virtual void Attach(const AuSPtr<Net::ISocket> &pSocket) = 0;
/**
* @brief
*/
virtual void StartHandshake() = 0;
/**
* @brief
*/
virtual void StartClose() = 0;
/**
* @brief
* @return
*/
virtual bool HasCompletedHandshake() = 0;
/**
* @brief
* @return
*/
virtual bool HasFailed() = 0;
/**
* @brief
* @return
*/
virtual bool HasEnded() = 0;
/**
* @brief
* @return
*/
virtual int GetFatalErrorCode() = 0;
/**
* @brief
*/
virtual void Destroy() = 0;
};
AUKN_SYM AuSPtr<ITLSContext> NewTLSContext(const TLSMeta &meta);
/**
* @brief
* @param pSendStack
* A buffered or socket protocol stack to add one extended TLS intercepter to
* @param pRecvStack
* A buffered or socket protocol stack to add one extended TLS intercepter to
* @param meta
* @return
*/
AUKN_SYM AuSPtr<ITLSContext> NewTLSContextEx(const AuSPtr<Protocol::IProtocolStack> &pSendStack,
const AuSPtr<Protocol::IProtocolStack> &pRecvStack,
const TLSMeta &meta);
}