Method Name:
do_handshake
Method Signature:
do_handshake(block=False)
Parameters:
block – Default value is False. When specified True depends on the timeout value of socket for the duration of blocking before handshake is complete.
Return Value:
None
Overview:
- The method do_handshake() does the TLS handshaking with the peer.
- While the TLS handshaking can be done as part of connecting with the peer, it can also be opted for later by calling the do_handshake() explicitly.
- In the Python code example below, if the wrap_socket() method on the SSLContext instance is called with do_handshake_on_connect = True (which is the default behaviour), then the time taken for the connect() will be more as it includes the time for completing the TLS handshake.
TLS Handshake: The TLS handshake (also still called as SSL handshake) involves exchanging information and deciding on the following for the TLS communication being established:
|
Example:
# Example Python program that uses an SSLSocket instance to import socket # Context creation # Check for OS X platform # Load the CA certificates used for validating the peer's certificate # Only connect, no handshake retval = secureClientSocket.connect(("example.org", 443)); # Explicit handshake # Get the certificate of the server and print |
Output:
Time taken to establish the connection:0.331 |