![]() |
TSDuck v3.45-4686
MPEG Transport Stream Toolkit
|
Base class for a TLS session. More...
#include <tsTLSConnection.h>


Public Types | |
| using | SuperClass = TCPConnection |
| Reference to the superclass. | |
Public Member Functions | |
| TLSConnection (Report *report, const TLSArgs &args) | |
| Constructor with initial client arguments. | |
| TLSConnection (Report *report=nullptr, Object *owner=nullptr) | |
| Constructor. | |
| TLSConnection (ReporterBase *delegate, const TLSArgs &args) | |
| Constructor with initial client arguments. | |
| TLSConnection (ReporterBase *delegate, Object *owner=nullptr) | |
| Constructor. | |
| void | addSubscription (SocketHandlerInterface *handler) |
| Add a subscriber to open/close events. | |
| void | addVerifyServer (const UString &name) |
| For a client connection, add another accepted host name for the server's certificate verification during connect(). | |
| bool | bind (const IPSocketAddress &addr) |
| Bind to a local address and port. | |
| void | cancelSubscription (SocketHandlerInterface *handler) |
| Remove a subscriber to open/close events. | |
| virtual bool | close (bool silent=false) final |
| Close the socket. | |
| virtual bool | closeWriter (bool silent=false) override |
| Close the write direction of the connection. | |
| virtual bool | connect (const IPSocketAddress &, IOSB *=nullptr) override |
| Connect to a remote address and port. | |
| virtual bool | disconnect (bool silent=false) override |
| Disconnect from remote partner. | |
| IP | generation () const |
| Get the IP generation with which the socket was open. | |
| bool | getLocalAddress (IPSocketAddress &addr) const |
| Get local socket address. | |
| bool | getPeer (IPSocketAddress &addr) |
| Get the connected remote peer. | |
| SysSocketType | getSocket () const |
| Get the underlying socket device handle (use with care). | |
| bool | isConnected () const |
| Check if the socket is connected. | |
| bool | isNonBlocking () const |
| Check if the device is in non-blocking mode. | |
| bool | isOpen () const |
| Check if socket is open. | |
| bool | isOwned () |
| Check if the object is owned. | |
| template<class OBJECT > requires std::derived_from<OBJECT, ts::Object> | |
| bool | isOwned () |
| Check if the object is owned by an object of a given type. | |
| UString | localName () |
| Get the local address as a string. | |
| bool | muteReport (bool mute) |
| Temporarily mute the associated report. | |
| virtual bool | open (IP gen=IP::Any) final |
| Open the socket. | |
| Object * | owner () |
| Get the address of the optional "owner" object which was specified in the constructor. | |
| template<class OBJECT > requires std::derived_from<OBJECT, ts::Object> | |
| OBJECT * | owner () |
| Get the address of the "owner" object which was specified in the constructor. | |
| UString | peerName () |
| Get the connected remote peer as a string. | |
| virtual bool | receive (void *, size_t, const AbortInterface *=nullptr) override |
| Receive data until buffer is full. | |
| virtual bool | receive (void *, size_t, size_t &, const AbortInterface *=nullptr, IOSB *=nullptr) override |
| Receive data. | |
| Report & | report () const |
| Access the Report which is associated with this object. | |
| bool | reusePort (bool reuse_port) |
| Set the "reuse port" option. | |
| virtual bool | send (const void *, size_t, IOSB *=nullptr) override |
| Send data. | |
| void | setArgs (const TLSArgs &args) |
| Set command line arguments for the client. | |
| bool | setConnectStatus (IOSB *iosb, int error_code) |
| Update the status of an asynchronous connect(). | |
| bool | setKeepAlive (bool active) |
| Set the "keep alive" option. | |
| bool | setLingerTime (int seconds) |
| Set the linger time option. | |
| bool | setNoDelay (bool active) |
| Set the "no delay" option. | |
| bool | setNoLinger () |
| Remove the linger time option. | |
| bool | setNonBlocking (bool non_blocking) |
| Set the device in non-blocking mode. | |
| bool | setReceiveBufferSize (size_t size) |
| Set the receive buffer size. | |
| bool | setReceiveTimeout (cn::milliseconds timeout) |
| Set the receive timeout. | |
| Report * | setReport (Report *report) |
| Associate this object with another Report to log errors. | |
| ReporterBase * | setReport (ReporterBase *delegate) |
| Associate this object with another ReporterBase to log errors. | |
| bool | setSendBufferSize (size_t size) |
| Set the send buffer size. | |
| void | setServerName (const UString &server_name) |
| For a client connection, specify the server name to be used in SNI (Server Name Indication). | |
| bool | setTTL (int ttl) |
| Set the Time To Live (TTL) option. | |
| void | setVerifyPeer (bool on) |
| Check if the peer's certificate shall be verified. | |
Static Public Member Functions | |
| static UString | GetLibraryVersion () |
| Get the version of the underlying SSL/TLS library. | |
| static bool | IsPendingStatus (int error_code) |
| This static method checks if a system error code means "I/O in progress" (asynchronous I/O) or "I/O would block" (non-blocking I/O). | |
| static int | SilentLevel (bool silent) |
| Compute a log severity level from a "silent" parameter. | |
Protected Member Functions | |
| virtual bool | allowSetNonBlocking () const override |
| Check that the non-blocking mode can be set. | |
| template<typename F > | |
| void | callSubscribers (F &&func) |
| Call a handler on all subscribers, using a lambda expression. | |
| bool | checkNonBlocking (bool non_blocking, const UChar *opname) |
| Check the blocking mode of a device. | |
| bool | checkNonBlocking (IOSB *iosb, const UChar *opname) |
| Check the blocking mode of a device. | |
| bool | convert (IPAddress &addr) const |
| Convert an IP address to make it compatible with the socket IP generation. | |
| bool | createSocket (IP gen, int type, int protocol) |
| Create the socket. | |
| virtual void | declareOpened (SysSocketType sock) override |
| Set an open socket descriptor from a subclass. | |
| virtual bool | openImplementation (IP gen) override |
| Open the socket, actual implementation which must be overriden by subclasses. | |
| bool | setSystemNonBlocking (SysSocketType fd, bool non_blocking) |
| Low-level method to set a system file or socket descriptor in non-blocking mode. | |
Protected Attributes | |
| std::recursive_mutex | _mutex {} |
| Mutex protecting this object. | |
Base class for a TLS session.
This class is used in two contexts:
Possible public servers to test various invalid certificates:
Constructor.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
| [in] | owner | Optional address of an "owner" object, typically an instance of class containing this object. |
|
explicit |
Constructor.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, log messages are discarded. |
| [in] | owner | Optional address of an "owner" object, typically an instance of class containing this object. |
Constructor with initial client arguments.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
| [in] | args | Initial TLS client arguments. |
|
inline |
Constructor with initial client arguments.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, log messages are discarded. |
| [in] | args | Initial TLS client arguments. |
| void ts::TLSConnection::setArgs | ( | const TLSArgs & | args | ) |
Set command line arguments for the client.
| [in] | args | TLS arguments. |
|
inline |
Check if the peer's certificate shall be verified.
| [in] | on | If true, the peer's certificate will be verified. |
| void ts::TLSConnection::setServerName | ( | const UString & | server_name | ) |
For a client connection, specify the server name to be used in SNI (Server Name Indication).
| [in] | server_name | Main server name, as specified in SNI (Server Name Indication). Also used to verify the server's certificate when setVerifyPeer() is true. |
| void ts::TLSConnection::addVerifyServer | ( | const UString & | name | ) |
For a client connection, add another accepted host name for the server's certificate verification during connect().
The list is reset by setVerifyServer().
| [in] | name | Additional accepted host name used to verify the server's certificate. |
|
overridevirtual |
Connect to a remote address and port.
Use this method when acting as TCP client. Do not use on server side: the TCPConnection object is passed to TCPServer::accept() which establishes the connection.
| [in] | addr | IP address and port of the server to connect to. |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the socket must be in non-blocking mode. When null, the socket must be in blocking mode (the default). See the description of IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
Reimplemented from ts::TCPConnection.
|
overridevirtual |
Close the write direction of the connection.
The application shall call this routine after sending the last message but may still want to receive messages, waiting for the peer to voluntary disconnect.
| [in] | silent | If true, do not report errors through the logger. This is typically useful when the socket is in some error condition and closing it is necessary although it may generate additional meaningless errors. |
Reimplemented from ts::TCPConnection.
|
overridevirtual |
Disconnect from remote partner.
| [in] | silent | If true, do not report errors through the logger. This is typically useful when the socket is in some error condition and closing it is necessary although it may generate additional meaningless errors. |
Reimplemented from ts::TCPConnection.
|
overridevirtual |
Send data.
| [in] | data | Address of the data to send. |
| [in] | size | Size in bytes of the data to send. |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the socket must be in non-blocking mode. When null, the socket must be in blocking mode (the default). See the description of IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
Reimplemented from ts::TCPConnection.
|
overridevirtual |
Receive data.
This version of receiveMessage() returns when "some" data are received into the user buffer. The actual received data may be shorter than the user buffer size.
The version is typically useful when the application cannot predict how much data will be received and must respond even if the user buffer is not full.
| [out] | buffer | Address of the buffer for the received data. |
| [in] | max_size | Size in bytes of the reception buffer. |
| [out] | ret_size | Size in bytes of the received data. Will never be larger than max_size. |
| [in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the socket must be in non-blocking mode. When null, the socket must be in blocking mode (the default). See the description of IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor. |
Reimplemented from ts::TCPConnection.
|
overridevirtual |
Receive data until buffer is full.
This version of receive() returns only when sufficient data are received to completely fill the user buffer. The size of the actual received data is identical to the user buffer size. If some data, but not all, were received before the connection was closed, these data are ignored and the method returns false. The version is typically useful when the application knows that a certain amount of data is expected and must wait for them.
This method is only allowed when the socket is in blocking-mode (the default) because this method is blocking by definition. Therefore, there is no iosb parameter.
This base implementation uses the variable-length version of receive(). Therefore, a subclass may only override the variable-length version and not this one.
| [out] | buffer | Address of the buffer for the received data. |
| [in] | size | Size in bytes of the buffer. |
| [in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
Reimplemented from ts::TCPConnection.
|
static |
Get the version of the underlying SSL/TLS library.
|
inherited |
Update the status of an asynchronous connect().
| [in,out] | iosb | Address of the IOSB structure which was used when connect() was called. |
| [in] | error_code | Error code in the context of the connection. |
|
inlineinherited |
Check if the socket is connected.
|
inherited |
Get the connected remote peer.
| [out] | addr | IP address and port of the remote socket. |
|
inherited |
Get the connected remote peer as a string.
|
inherited |
Set the Time To Live (TTL) option.
| [in] | ttl | The TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped. |
|
inherited |
Remove the linger time option.
|
inherited |
Set the linger time option.
| [in] | seconds | Number of seconds to wait after shuting down the socket. |
|
inherited |
Set the "keep alive" option.
| [in] | active | If true, the socket periodically sends "keep alive" packets when the connection is idle. |
|
inherited |
Set the "no delay" option.
| [in] | active | If true, the socket immediately sends outgoing packets. By default, a TCP socket waits a small amount of time after a send() operation to get a chance to group outgoing data from successive send() operations into one single packet. |
|
overrideprotectedvirtualinherited |
Open the socket, actual implementation which must be overriden by subclasses.
Never called when the application tries to open a socket which is already open.
| [in] | gen | IP generation, IPv4 or IPv6. If set to IP::Any, open an IPv6 socket (IPv4 connections allowed). |
Implements ts::Socket.
|
overrideprotectedvirtualinherited |
Set an open socket descriptor from a subclass.
This method is used by a server to declare that a client socket has just become opened.
| [in] | sock | New socket descriptor. |
Reimplemented from ts::Socket.
Open the socket.
Subclasses are not permitted to override this one, they should implement openImplementation().
| [in] | gen | IP generation, IPv4 or IPv6. If set to IP::Any, open an IPv6 socket (IPv4 connections allowed). |
|
finalvirtualinherited |
Close the socket.
Subclasses are not permitted to override this one, they should implement closeImplementation().
| [in] | silent | If true, do not report errors through the logger. This is typically useful when the socket is in some error condition and closing it is necessary although it may generate additional meaningless errors. |
|
inlineinherited |
Check if socket is open.
|
inlineinherited |
Get the IP generation with which the socket was open.
|
inherited |
Set the send buffer size.
| [in] | size | Send buffer size in bytes. |
|
inherited |
Set the receive buffer size.
| [in] | size | Receive buffer size in bytes. |
|
inherited |
Set the receive timeout.
| [in] | timeout | Receive timeout in milliseconds. If negative or zero, receive timeout is not used, reception waits forever. |
|
inherited |
Set the "reuse port" option.
| [in] | reuse_port | If true, the socket is allowed to reuse a local UDP port which is already bound. |
|
inherited |
Bind to a local address and port.
The IP address part of the socket address must one of:
Special note for receiving multicast on most Unix systems (at least Linux and macOS): The IP address shall be either AnyAddress4 or the multicast group address. Do not specify a local address to receive multicast on Unix.
The port number part of the socket address must be one of:
| [in] | addr | Local socket address to bind to. |
|
inherited |
Get local socket address.
| [out] | addr | Local socket address of the connection. |
|
inherited |
Get the local address as a string.
|
inlineinherited |
Get the underlying socket device handle (use with care).
This method is reserved for low-level operations and should not be used by normal applications.
|
inherited |
|
inherited |
|
protectedinherited |
|
protectedinherited |
Convert an IP address to make it compatible with the socket IP generation.
| addr | [in,out] The address to convert. |
|
inlineprotectedinherited |
Call a handler on all subscribers, using a lambda expression.
| [in] | func | Function to call as lambda expression. |
|
overrideprotectedvirtualinherited |
Check that the non-blocking mode can be set.
Must be implemented by subclasses which do not support setting the non-blocking in certain states, such as after being opened. The default implementation always allows setting the non-blocking mode.
Reimplemented from ts::NonBlockingDevice.
|
inherited |
Set the device in non-blocking mode.
Important: Usually, this method must be called before opening the device, whatever it means. Otherwise it is ignored and the device blocking mode is unchanged.
| [in] | non_blocking | It true, the device is set in non-blocking mode. |
|
inlineinherited |
Check if the device is in non-blocking mode.
|
staticinherited |
This static method checks if a system error code means "I/O in progress" (asynchronous I/O) or "I/O would block" (non-blocking I/O).
| [in] | error_code | System error code. |
|
protectedinherited |
Check the blocking mode of a device.
Called by subclass methods which are explicitly called in blocking or non-blocking mode.
| [in] | non_blocking | The required non-blocking mode. |
| [in] | opname | Name of the operation, for the error message. |
|
protectedinherited |
Check the blocking mode of a device.
Called by subclass methods which are explicitly called in blocking or non-blocking mode.
| [in,out] | iosb | Address of an IOSB structure. If non-null, we are in non-blocking mode. When null, we are in blocking mode. When non-null, pending is reset to false and overlap is zeroed. |
| [in] | opname | Name of the operation, for the error message. |
|
protectedinherited |
Low-level method to set a system file or socket descriptor in non-blocking mode.
| [in] | fd | System file or socket descriptor. |
| [in] | non_blocking | It true, the device is set in non-blocking mode. |
Summary: Do not use this method unless you exactly know what you are doing.
UNIX: Depending on the way a file descriptor is created, it may be possible to specify the non-blocking mode from the beginning. Or it can be somehow inherited. However, this is not portable.
Examples:
In all cases, it is possible to set a file descriptor in non-blocking mode at any time using the method setSystemNonBlocking(). This method uses fcntl(F_SETFL) to alter the file descriptor's flags.
Windows: The natural way of not being blocked on I/O on Windows is asynchronous I/O. To increase the general confusion, there is some form of non-blocking mode on Windows sockets, and only sockets, not other forms of file handles. This mode is activated using "ioctlsocket(fd, FIONBIO, &mode)". When this mode is active, socket I/O become similar to UNIX: they immediately either succeed or fail, but never block. However, there is no way to get notified when the I/O becomes possible. There is no equivalent to epoll (Linux) or kqueue (macOS and BSD). The Windows I/O Completion Ports can only work on asynchronous I/O, using OVERLAPPED structures. Because this form of non-blocking mode is mostly useless in practice, we do not use it and the method setSystemNonBlocking() does nothing on Windows.
|
inherited |
Associate this object with another Report to log errors.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
|
inherited |
Associate this object with another ReporterBase to log errors.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, the previous explicit Report is used.. |
|
inherited |
Temporarily mute the associated report.
| [in] | mute | It true, report() will return a null report (log messages are discarded), until muteReport() is invoked again with mute set to false. |
|
inlinestaticinherited |
Compute a log severity level from a "silent" parameter.
Some subclass methods have a "silent" parameter to avoid reporting errors which may be insignificant, typically when closing a device after an error, in which case the close operation may produce other errors if the previous error left the device in an inconsistent state. While those errors should not be displayed as errors, we still display them at debug level.
| [in] | silent | If true, do not report errors, report debug messages instead. |
|
inlineinherited |
Get the address of the optional "owner" object which was specified in the constructor.
|
inherited |
Get the address of the "owner" object which was specified in the constructor.
This template version requires that the owner objet is set and of type OBJECT, or some subclass of it. If there is no owner object or if it is not compatible with the template class OBJECT, this is a fatal error and the application is terminated.
| OBJECT | A subclass of Object |
|
inlineinherited |
Check if the object is owned.
|
inlineinherited |
Check if the object is owned by an object of a given type.
| OBJECT | A subclass of Object |