CInternetServer::EnableSecurity Method  
 
BOOL EnableSecurity(
  SOCKET hSocket  
);
BOOL EnableSecurity();

Enable secure communication with the client.

Parameters

hSocket
An optional parameter that specifies the handle to the client socket. If this parameter is omitted, the socket handle for the active client session will be used. If this method is called outside of a server event handler, the socket handle must be specified.

Return Value

If the method succeeds, the return value is zero. If the method fails, the return value is INET_ERROR. To get extended error information, call GetLastError.

Remarks

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.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock11.h
Import Library: cswskv11.lib

See Also

DisableSecurity, SetCertificate, SetOptions