I use python 2.6 and request Facebook API (https). I guess my service could be target of Man In The Middle attacks. I discovered this morning reading again urllib module documentation that : Citation:
Warning : When opening HTTPS URLs, it is not attempted to validate the server certificate. Use at your own risk!
Do you have hints / url / examples to complete a full certificate validation ?
Thanks for your help
If you have a trusted Certificate Authority (CA) file, you can use Python 2.6 and later's
ssl
library to validate the certificate. Here's some code:Some dangers with this code:
get_ca_path
with one that returns your local CA file, which will vary from host to host.You could create a urllib2 opener which can do the validation for you using a custom handler. The following code is an example that works with Python 2.7.3 . It assumes you have downloaded http://curl.haxx.se/ca/cacert.pem to the same folder where the script is saved.
Running this script you should see something a output like this: