The EnableSecurity method enables a secure communications
session with the remote host, automatically negotiating the encryption
algorithm and validating the certificate specified by a previous call
to the SetCertificate method. This method will cause the
calling thread to block and wait
for the client to initiate the TLS handshake.
This method is typically used to implement support for explicit TLS
connections, where the client establishes a standard, non-secure
connection to the server and then negotiates a secure connection at a
later point. Usually this is done by the client sending a specific
command to the server, and the server calls EnableSecurity from
within the OnRead event handler that processes the command. If the method succeeds, all
subsequent calls to Read and Write to receive and send
data will be encrypted.
This method is only used to enable a secure connection for a
specific client session. If all client connections should be secure,
then call the SetOptions method to specify the
INET_OPTION_SECURE option prior to starting the server and call the
SetCertificate method to specify the server certificate that
should be used.