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"
13#include "Arp/System/Core/PimplPtr.hxx"
14#include "Arp/System/Commons/Net/TlsOptions.hpp"
19typedef struct ssl_st SSL;
20typedef struct ssl_ctx_st SSL_CTX;
23namespace Arp {
namespace System {
namespace Commons {
namespace Net
36using TlsContextPtr = std::shared_ptr<TlsContext>;
43 friend class TlsContext;
48 typedef std::shared_ptr<TlsSocket>
Ptr;
576 SocketError HandleSslResult(
int result,
int* sslErrorOut =
nullptr);
577 int GetFileDescriptor(
void);
578 void ClearOpenSslErrors(
void);
580 SocketError UpdateSessionKeysTls13(
bool requestUpdate =
true);
582 bool IsKeyUpdateScheduled()
const;
587 SSL* sslConnection =
nullptr;
588 TlsContextPtr pContext;
590 Ptr currentAcceptSocket;
594 bool socketIsConnected;
597 bool tlsConnectIsPending;
598 bool pendingTlsConnectNeedsRead;
608 return this->pSocket->GetSocketType();
613 return this->pSocket->GetSocketDomain();
618 return this->pSocket->IsBlocking();
623 return this->pSocket->GetRemoteIpAddress();
628 return this->pSocket->GetRemotePort();
633 return (!this->hasSslError) && (this->tlsIsConnected || this->socketIsConnected);
638 return (!this->hasSslError) && (this->tlsIsConnected);
643 return pSocket->Bind(ip4Address, port);
648 return pSocket->Bind2(ip4Address, port);
654 return pSocket->Listen(backlog);
659 return this->pSocket->SetSocketOption(optionName, optionValue, optionLength);
664 return this->pSocket->GetSocketOption(optionName, optionValue, optionLength);
669 return this->pSocket->SetOptionReuseAddress(enabled);
674 return this->pSocket->GetOptionReuseAddress(enabled);
679 return this->pSocket->SetOptionKeepAlive(enabled);
684 return this->pSocket->GetOptionKeepAlive(enabled);
689 return this->pSocket->SetOptionBroadcast(enabled);
694 return this->pSocket->GetOptionBroadcast(enabled);
699 return this->pSocket->SetOptionNoDelay(enabled);
704 return this->pSocket->GetOptionNoDelay(enabled);
709 return this->pSocket->SetOptionLinger(enable, timeout);
714 return this->pSocket->GetOptionLinger(enable, timeout);
719 return this->pSocket->SetOptionUserTimeout(timeout_ms);
724 return this->pSocket->GetOptionUserTimeout(timeout_ms);
729 return this->pSocket->SetOptionKeepAliveIdleTime(seconds);
734 return this->pSocket->GetOptionKeepAliveIdleTime(seconds);
739 return this->pSocket->SetOptionKeepAliveProbeInterval(seconds);
744 return this->pSocket->GetOptionKeepAliveProbeInterval(seconds);
749 return this->pSocket->SetOptionKeepAliveProbeCount(probeCount);
754 return this->pSocket->GetOptionKeepAliveProbeCount(probeCount);
759 return this->pSocket->SetOptionBlocking(enable);
Definition: Loggable.hxx:20
Unified representation for ip address schemes.
Definition: IpAddress.hpp:14
std::shared_ptr< Socket > Ptr
Contextual definition of pointer type.
Definition: Socket.hpp:122
Definition: TlsSocket.hpp:40
SocketError Close(void)
Closes the socket. This ends all communication on the socket.
SocketError SetOptionUserTimeout(size_t timeout_ms)
Sets the retransmission timeout of a socket. This only works on Linux.
Definition: TlsSocket.hpp:717
Ptr Accept(IpAddress &ip4address, int &port, SocketError &error)
Accepts a pending connection request.
SocketError GetOptionKeepAlive(bool &enabled)
Checks if keep-alive is enabled.
Definition: TlsSocket.hpp:682
SocketError SetOptionReuseAddress(bool enabled)
Enables/Disables the reuse-address option for this socket.
Definition: TlsSocket.hpp:667
SocketDomain GetSocketDomain(void)
Returns the type of the socket.
Definition: TlsSocket.hpp:611
std::shared_ptr< TlsSocket > Ptr
Contextual definition of pointer type.
Definition: TlsSocket.hpp:48
SocketError SetOptionNoDelay(bool enabled)
Enables/Disables no-delay for this socket.
Definition: TlsSocket.hpp:697
TlsSocket & operator=(const TlsSocket &arg)=delete
Assignment operator.
SocketError SetOptionBlocking(bool enable)
Enables/disables the blocking mode of this socket..
Definition: TlsSocket.hpp:757
bool Select(SelectMode mode, Microseconds timeout, SocketError &error)
Checks if an i/o operation can be performed without blocking the calling thread.
SocketError GetSocketOption(SocketOptionName optionName, void *optionValue, size_t *optionLength)
Returns current value of queried socket option.
Definition: TlsSocket.hpp:662
SocketError SetSocketOption(SocketOptionName optionName, const void *optionValue, size_t optionLength)
Sets a single option on the socket.
Definition: TlsSocket.hpp:657
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 Bind2(const IpAddress &ip4Address, int &port)
Binds the socket to a specific address and port combination.
Definition: TlsSocket.hpp:646
SocketError SetOptionKeepAliveProbeCount(int probeCount)
Sets the amount of probes to be sent, if the KeepAlive SocketOption is set to true.
Definition: TlsSocket.hpp:747
TlsSocket(SocketType type, SocketDomain domain, SocketBlockingMode blockingMode, TlsOptions options)
Constructs an TlsSocket instance.
SocketError GetOptionLinger(bool &enable, size_t &timeout)
Returns the current linger options. For more information see Arp::System::Commons::Net::Socket::SetOp...
Definition: TlsSocket.hpp:712
SocketError Bind(const IpAddress &ip4Address, int port)
Binds the socket to a specific address and port combination.
Definition: TlsSocket.hpp:641
SocketError Shutdown(void)
Shuts down a full-duplex connection.
int Receive(void *pBuffer, size_t length, SocketError &error)
Reads data from connected socket.
SocketError GetOptionKeepAliveProbeCount(int &probeCount)
Gets the amount of probes to be sent, if the KeepAlive SocketOption is set to true....
Definition: TlsSocket.hpp:752
SocketError GetOptionKeepAliveProbeInterval(int &seconds)
Gets the interval time in between each Keep Alive probe, if the KeepAlive SocketOption is set to true...
Definition: TlsSocket.hpp:742
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 GetOptionUserTimeout(size_t &timeout_ms)
Gets the retransmission timeout of a socket. This only works on Linux. For more information see Arp::...
Definition: TlsSocket.hpp:722
SocketError SetOptionKeepAliveIdleTime(int seconds)
Sets the time that the socket needs to be idle for, before the Keep Alive mechanism can start if the ...
Definition: TlsSocket.hpp:727
int GetRemotePort(void)
If this socket is connected this method returns the port of the connection.
Definition: TlsSocket.hpp:626
SocketError RenegotiateSession()
SocketError InitServer(const String &identityStoreName, const String &trustStoreName="")
bool IsBlocking(void)
Checks if the socket is in blocking mode.
Definition: TlsSocket.hpp:616
bool IsTlsConnected(void)
Checks if a TLS connection is established with a remote peer.
Definition: TlsSocket.hpp:636
SocketError GetOptionKeepAliveIdleTime(int &seconds)
Gets the time that the socket needs to be idle for, before the Keep Alive mechanism can start if the ...
Definition: TlsSocket.hpp:732
int Poll(PollMode mode, Milliseconds timeout, SocketError &error)
Checks if an i/o operation can be processed without blocking.
SocketError SetOptionKeepAlive(bool enabled)
Enables/Disables the keep-alive option for this socket.
Definition: TlsSocket.hpp:677
SocketError SetOptionLinger(bool enable, size_t timeout)
Sets the amount of time a socket resides in TIME_WAIT state after active close.
Definition: TlsSocket.hpp:707
SocketError Connect(const IpAddress &ip4Address, int port)
Tries to connect with a remote socket.
IpAddress GetRemoteIpAddress(void)
Checks if this socket is connected with a remote peer.
Definition: TlsSocket.hpp:621
bool IsConnected(void)
Checks if the socket is in blocking mode.
Definition: TlsSocket.hpp:631
TlsSocket(const TlsSocket &arg)=delete
Copy contructor.
SocketError SetOptionBroadcast(bool enabled)
Enables/Disables broadcast for this socket.
Definition: TlsSocket.hpp:687
SocketError GetOptionBroadcast(bool &enabled)
Checks if broadcast is enabled.
Definition: TlsSocket.hpp:692
SocketError UpdateSessionKeys(bool requestUpdate=true)
SocketError SetOptionKeepAliveProbeInterval(int seconds)
Sets the interval time in between each Keep Alive probe, if the KeepAlive SocketOption is set to true...
Definition: TlsSocket.hpp:737
SocketType GetSocketType(void)
Returns the type of the socket.
Definition: TlsSocket.hpp:606
void SetCipherList(String cipherList)
SocketError Listen(size_t backlog)
Marks this socket as a passive socket that accepts incoming connection requests.
Definition: TlsSocket.hpp:652
SocketError GetOptionReuseAddress(bool &enabled)
Checks if reuse-address is enabled.
Definition: TlsSocket.hpp:672
SocketError GetOptionNoDelay(bool &enabled)
Checks if no-delay is enabled.
Definition: TlsSocket.hpp:702
Class to handle x.509 certificates
Definition: Certificate.hpp:25
Definition: ISocketService.hpp:13
std::chrono::milliseconds Milliseconds
The Arp Milliseconds unit class.
Definition: TypeSystem.h:52
std::chrono::microseconds Microseconds
The Arp Microseconds unit class.
Definition: TypeSystem.h:49
@ 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
TlsOptions
This enum is used to select different options for the TlsSocket class
Definition: TlsOptions.hpp:25
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: Asn1Time.hpp:18
Root namespace for the PLCnext API