In this section, you will learn how we can implement secure sockets with TLS and the SSL module. We will demonstrate how simple TCP sockets can be wrapped with TLS and used to carry encrypted data.
HTTPS and securing sockets with TLS
Implementing the SSL client
You have probably come across the discussion around secure web communication using SSL, or more precisely TLS, which is adopted by many other high-level protocols. Let's see how we can wrap a plain sockets connection with SSL. Python has a built-in SSL module that serves this purpose.
In the following example, we would like to create a plain TCP socket and connect to an HTTPS-enabled web server. We can establish that connection using the SSL module and check the...