Numpty
Numpty

Reputation: 1481

Specifying the IP address + SNI with SSLContext

How can one specify the IP address of the server you wish to connect to along with the SNI using Python's SSLContext?

I can specify the SNI alone easily, but haven't been able to determine how to point the request a specific IP address

E.g This will result in 'mywebsite' being sent within the 'Client Hello'

 hostname = "mywebsite"
 context.wrap_socket(sock, server_hostname=hostname)

How do you control the IP you connect to?

Thank you!

Upvotes: 1

Views: 898

Answers (1)

Patrick Mevzek
Patrick Mevzek

Reputation: 12515

How was your sock variable created?

It is a socket, hence it is where the destination IP and ports are specified, before calling wrap_socket.

Like:

sock = socket.create_connection((HOST, PORT))

At the TLS level it is "too late": TLS handshake happens after the TCP/IP connection is established, so at the time you send the SNI extension, you are already connected to a specific IP address (and port).

Upvotes: 1

Related Questions