Implementing a Secure Socket
The following procedure outlines how to establish a secure socket connection.
To implement a secure socket
- Create a socket with socket.
- Set the socket in secure mode with setsockopt. Set the level parameter to SO_SOCKET, optname to SO_SECURE, and set optval to a DWORD set to SO_SEC_SSL.
- Specify the certificate validation callback function by invoking WSAIoctl with the SO_SSL_SET_VALIDATE_CERT_HOOK control code.
- To specify a particular security protocol, invoke WSAIoctl with the SO_SSL_GET_PROTOCOLS control code to determine the default protocols. Then call WSAIoctl with the SO_SSL_SET_PROTOCOLS control code to select the protocols to be enabled. Otherwise, Windows CE will select the protocol to be used.
- Make a connection with connect.
The certificate callback function is automatically invoked. The connection can be completed only if the callback function verifies the acceptability of the certificate by returning SSL_ERR_OKAY.
- Transmit and send as usual.
The send and recv functions automatically encrypt and decrypt the data.
- When finished, close the socket with closesocket.