8 #include "Arp/System/Commons/Net/IpAddress.hpp"
9 #include "Arp/System/Commons/Net/Socket.hpp"
10 #include "Arp/System/Commons/Logging.h"
11 #include "Arp/System/Commons/Exceptions/Exceptions.h"
12 #include "Arp/System/Commons/Security/IdentityStore.hpp"
17 typedef struct ssl_st SSL;
18 typedef struct ssl_ctx_st SSL_CTX;
20 namespace Arp {
namespace System {
namespace Commons {
namespace Net
37 using Ptr = std::shared_ptr<TlsContext>;
41 TlsContext(
const TlsContext& arg) =
delete;
45 TlsContext& operator=(
const TlsContext& arg) =
delete;
48 SSL_CTX* pTlsCtx =
nullptr;
54 friend class TlsContext;
59 typedef std::shared_ptr<TlsSocket>
Ptr;
106 bool IsBlocking(
void);
111 bool IsConnected(
void);
116 bool IsTlsConnected(
void);
128 int GetRemotePort(
void);
380 SocketError SetOptionLinger(
bool enable,
size_t timeout);
388 SocketError GetOptionLinger(
bool& enable,
size_t& timeout);
435 void SetCipherList(
String cipherList);
450 SocketError HandleSslResult(
int result,
int* sslErrorOut =
nullptr);
451 int GetFileDescriptor(
void);
452 void ClearOpenSslErrors(
void);
456 SSL* sslConnection =
nullptr;
457 TlsContext::Ptr pContext;
459 Ptr currentAcceptSocket;
463 bool socketIsConnected;
466 bool tlsConnectIsPending;
467 bool pendingTlsConnectNeedsRead;
477 return this->pSocket->GetSocketType();
482 return this->pSocket->GetSocketDomain();
485 inline bool TlsSocket::IsBlocking(
void)
487 return this->pSocket->IsBlocking();
492 return this->pSocket->GetRemoteIpAddress();
495 inline int TlsSocket::GetRemotePort(
void)
497 return this->pSocket->GetRemotePort();
500 inline bool TlsSocket::IsConnected(
void)
502 return (!this->hasSslError) && (this->tlsIsConnected || this->socketIsConnected);
505 inline bool TlsSocket::IsTlsConnected(
void)
507 return (!this->hasSslError) && (this->tlsIsConnected);
512 return pSocket->Bind(ip4Address, port);
517 return pSocket->Bind2(ip4Address, port);
523 return pSocket->Listen(backlog);
528 return this->pSocket->SetSocketOption(optionName, optionValue, optionLength);
533 return this->pSocket->GetSocketOption(optionName, optionValue, optionLength);
538 return this->pSocket->SetOptionReuseAddress(enabled);
541 inline SocketError TlsSocket::GetOptionReuseAddress(
bool& enabled)
543 return this->pSocket->GetOptionReuseAddress(enabled);
548 return this->pSocket->SetOptionKeepAlive(enabled);
553 return this->pSocket->GetOptionKeepAlive(enabled);
558 return this->pSocket->SetOptionBroadcast(enabled);
563 return this->pSocket->GetOptionBroadcast(enabled);
568 return this->pSocket->SetOptionNoDelay(enabled);
573 return this->pSocket->GetOptionNoDelay(enabled);
576 inline SocketError TlsSocket::SetOptionLinger(
bool enable,
size_t timeout)
578 return this->pSocket->SetOptionLinger(enable, timeout);
581 inline SocketError TlsSocket::GetOptionLinger(
bool& enable,
size_t& timeout)
583 return this->pSocket->GetOptionLinger(enable, timeout);
588 return this->pSocket->SetOptionBlocking(enable);
Definition: Loggable.hxx:19
Unified representation for ip address schemes.
Definition: IpAddress.hpp:14
std::shared_ptr< Socket > Ptr
Contextual definition of pointer type.
Definition: Socket.hpp:122
Interface to realize TLS Connection over TCP
Definition: TlsSocket.hpp:32
SocketError Close(void)
Closes the socket. This ends all communication on the socket.
Ptr Accept(IpAddress &ip4address, int &port, SocketError &error)
Accepts a pending connection request.
std::shared_ptr< TlsSocket > Ptr
Contextual definition of pointer type.
Definition: TlsSocket.hpp:59
bool Select(SelectMode mode, Microseconds timeout, SocketError &error)
Checks if an i/o operation can be performed without blocking the calling thread.
TlsSocket(SocketType type, SocketDomain domain, SocketBlockingMode blockingMode)
Constructs an TlsSocket instance.
int Send(const void *pBuffer, size_t length, SocketError &error)
Transmit data over the socket that is in a connected state.
SocketError Shutdown(void)
Shuts down a full-duplex connection.
int Receive(void *pBuffer, size_t length, SocketError &error)
Reads data from connected socket.
SocketError Shutdown(ShutdownMode mode)
Shuts down a full-duplex connection.
~TlsSocket(void)
Destructs this instance and frees all resouces.
SocketError InitClient(const String &trustStoreName, const String &identityStoreName, const String &hostName)
SocketError InitServer(const String &identityStoreName, const String &trustStoreName="")
Arp::System::Ve::ISocketService ISocketService
Injection of SocketService-Interface in class context.
Definition: TlsSocket.hpp:62
int Poll(PollMode mode, Milliseconds timeout, SocketError &error)
Checks if an i/o operation can be processed without blocking.
SocketError Connect(const IpAddress &ip4Address, int port)
Tries to connect with a remote socket.
TlsSocket(const TlsSocket &arg)=delete
Copy contructor.
TlsSocket & operator=(const TlsSocket &arg)=delete
Assignment operator.
std::chrono::milliseconds Milliseconds
The Arp Milliseconds unit class.
Definition: TypeSystem.h:36
std::chrono::microseconds Microseconds
The Arp Microseconds unit class.
Definition: TypeSystem.h:34
@ System
System components used by the System, Device, Plc or Io domains.
PollMode
This enum is used to specifiy the poll mode of the <cref name="Socket::Poll" > operation.
Definition: PollMode.hpp:15
SelectMode
Modes for Select call to check different data channels.
Definition: SelectMode.hpp:14
SocketDomain
Supported communication domains, selecting the protocol for communication.
Definition: SocketDomain.hpp:14
SocketType
Enumeration of supported socket types.
Definition: SocketType.hpp:14
ShutdownMode
This enum is used to specifiy the shutdown mode of the <cref name="Socket::Shutdown(ShutdownMode)" > ...
Definition: ShutdownMode.hpp:15
SocketError
Possible error codes for socket operation results.
Definition: SocketError.hpp:15
SocketOptionName
Specifies socket options to be set by the application. Copied from Eclr Socket Adaption
Definition: SocketOptionName.hpp:17
SocketBlockingMode
Supported blocking modes.
Definition: Socket.hpp:28
Namespace for classes dealing with certificates
Definition: ItemInfo.hpp:9
Root namespace for the PLCnext API