Implementing a Secure Socket

The following procedure outlines how to establish a secure socket connection.

    To implement a secure socket
  1. Create a socket with socket.
  2. 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.
  3. Specify the certificate validation callback function by invoking WSAIoctl with the SO_SSL_SET_VALIDATE_CERT_HOOK control code.
  4. 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.
  5. 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.

  6. Transmit and send as usual.

    The send and recv functions automatically encrypt and decrypt the data.

  7. When finished, close the socket with closesocket.