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;
488 SocketError HandleSslResult(
int result,
int* sslErrorOut =
nullptr);
489 int GetFileDescriptor(
void);
490 void ClearOpenSslErrors(
void);
492 SocketError UpdateSessionKeysTls13(
bool requestUpdate =
true);
494 bool IsKeyUpdateScheduled()
const;
499 SSL* sslConnection =
nullptr;
500 TlsContextPtr pContext;
502 Ptr currentAcceptSocket;
506 bool socketIsConnected;
509 bool tlsConnectIsPending;
510 bool pendingTlsConnectNeedsRead;
520 return this->pSocket->GetSocketType();
525 return this->pSocket->GetSocketDomain();
530 return this->pSocket->IsBlocking();
535 return this->pSocket->GetRemoteIpAddress();
540 return this->pSocket->GetRemotePort();
545 return (!this->hasSslError) && (this->tlsIsConnected || this->socketIsConnected);
550 return (!this->hasSslError) && (this->tlsIsConnected);
555 return pSocket->Bind(ip4Address, port);
560 return pSocket->Bind2(ip4Address, port);
566 return pSocket->Listen(backlog);
571 return this->pSocket->SetSocketOption(optionName, optionValue, optionLength);
576 return this->pSocket->GetSocketOption(optionName, optionValue, optionLength);
581 return this->pSocket->SetOptionReuseAddress(enabled);
586 return this->pSocket->GetOptionReuseAddress(enabled);
591 return this->pSocket->SetOptionKeepAlive(enabled);
596 return this->pSocket->GetOptionKeepAlive(enabled);
601 return this->pSocket->SetOptionBroadcast(enabled);
606 return this->pSocket->GetOptionBroadcast(enabled);
611 return this->pSocket->SetOptionNoDelay(enabled);
616 return this->pSocket->GetOptionNoDelay(enabled);
621 return this->pSocket->SetOptionLinger(enable, timeout);
626 return this->pSocket->GetOptionLinger(enable, timeout);
631 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.
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:594
SocketError SetOptionReuseAddress(bool enabled)
Enables/Disables the reuse-address option for this socket.
Definition: TlsSocket.hpp:579
SocketDomain GetSocketDomain(void)
Returns the type of the socket.
Definition: TlsSocket.hpp:523
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:609
TlsSocket & operator=(const TlsSocket &arg)=delete
Assignment operator.
SocketError SetOptionBlocking(bool enable)
Enables/disables the blocking mode of this socket..
Definition: TlsSocket.hpp:629
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:574
SocketError SetSocketOption(SocketOptionName optionName, const void *optionValue, size_t optionLength)
Sets a single option on the socket.
Definition: TlsSocket.hpp:569
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:558
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:624
SocketError Bind(const IpAddress &ip4Address, int port)
Binds the socket to a specific address and port combination.
Definition: TlsSocket.hpp:553
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)
int GetRemotePort(void)
If this socket is connected this method returns the port of the connection.
Definition: TlsSocket.hpp:538
SocketError RenegotiateSession()
SocketError InitServer(const String &identityStoreName, const String &trustStoreName="")
bool IsBlocking(void)
Checks if the socket is in blocking mode.
Definition: TlsSocket.hpp:528
Arp::System::Ve::ISocketService ISocketService
Injection of SocketService-Interface in class context.
Definition: TlsSocket.hpp:51
bool IsTlsConnected(void)
Checks if a TLS connection is established with a remote peer.
Definition: TlsSocket.hpp:548
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:589
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:619
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:533
bool IsConnected(void)
Checks if the socket is in blocking mode.
Definition: TlsSocket.hpp:543
TlsSocket(const TlsSocket &arg)=delete
Copy contructor.
SocketError SetOptionBroadcast(bool enabled)
Enables/Disables broadcast for this socket.
Definition: TlsSocket.hpp:599
SocketError GetOptionBroadcast(bool &enabled)
Checks if broadcast is enabled.
Definition: TlsSocket.hpp:604
SocketError UpdateSessionKeys(bool requestUpdate=true)
SocketType GetSocketType(void)
Returns the type of the socket.
Definition: TlsSocket.hpp:518
void SetCipherList(String cipherList)
SocketError Listen(size_t backlog)
Marks this socket as a passive socket that accepts incoming connection requests.
Definition: TlsSocket.hpp:564
SocketError GetOptionReuseAddress(bool &enabled)
Checks if reuse-address is enabled.
Definition: TlsSocket.hpp:584
SocketError GetOptionNoDelay(bool &enabled)
Checks if no-delay is enabled.
Definition: TlsSocket.hpp:614
Class to handle x.509 certificates
Definition: Certificate.hpp:25
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