From the command line, I am able to successfully execute a command as follows:
curl --cacert <cacert> --cert <cert> --connect-to ::1.2.3.4: https://some-identity.com:443/endpoint
I am doing this so the request ends up going to the 1.2.3.4
address (from the routing perspective), but all of the SSL handshake occurs using the some-identity.com
address. I have to do this because unfortunately, the SSL certificates in use are being signed using the some-identity.com
address, but the private IP of the server is 1.2.3.4
.
I am trying to use either aiohttp
(preferably), or requests
, but I cannot find the respective utilities to do this.
In aiohttp
, I see that I can pass in an SSLContext
(in the ssl
package) object, but unfortunately, I can't seem to find any property within an SSLContext
object that can be set dynamically.
For the requests
library, it doesn't seem to have an option for me to override/change the host as I did using curl
.
Is there another way to go about this through Python libraries? The last ditch option would be to simply use the curl
command itself through Python, but that is not preferred.