Using a Deferred Handshake (Windows CE 5.0)

Send Feedback

A deferred handshake enables an application to create an unsecured connection and then later convert it to a connection with a security infrastructure.

To implement secure sockets with a deferred handshake

  1. Create a socket with the socket function.

  2. Set the socket in secure mode with setsockopt.

  3. Set level to SOL_SOCKET, set optname to SO_SECURE, and set optval to a DWORD set to SO_SEC_SSL.

  4. Specify the certificate validation callback function by calling WSAIoctl with the SO_SSL_SET_VALIDATE_CERT_HOOK control code.

  5. To verify the server's identity during the handshake, call WSAIoctl with the SO_SSL_SET_PEERNAME control code.

    The server name is verified against the server certificate after a successful SSL handshake. The verification results are then indicated in the certificate validation callback. If the specified server name does not match the one indicated in the certificate chain of the SSL Handshake, SSL_CERT_FLAG_ISSUER_UNKNOWN is set in the dwFlags parameter of SslValidateCertHook.

    If you do not perform this step, no verification is performed.

  6. Set the socket in deferred handshake mode with WSAIoctl. The control code should be set to SO_SSL_SET_FLAGS and the flag set to SSL_FLAG_DEFER_HANDSHAKE.

  7. Establish a nonsecure connection with the remote party using connect.

  8. Transmit and receive unencoded data.

  9. To switch to secure mode, call WSAIoctl with the SO_SSL_PERFORM_HANDSHAKE control code passing in the target server name.

  10. The certificate callback function is automatically called. The handshake is successful only if the callback function verifies the acceptability of the certificate by returning SSL_ERR_OKAY.

  11. Transmit and receive.

  12. The send and recv functions encode and decode the data automatically.

  13. When you are finished, close the socket with closesocket.

See Also

Winsock Secure Sockets | Secure Socket Control Codes

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.