1# Copyright (C) 2011, Thomas Leonard 2# See the README file for details, or visit http://0install.net. 3 4importsys,os,socket,ssl 5 6fromzeroinstallimport_ 7fromzeroinstall.injectorimportdownload 8fromzeroinstall.supportimportssl_match_hostname 9 10ifsys.version_info[0]>2: 11fromurllibimportrequestasurllib2 12fromhttp.clientimportHTTPSConnection,HTTPException 13else: 14importurllib2 15fromhttplibimportHTTPSConnection,HTTPException 16 17try: 18# http://pypi.python.org/pypi/certifi 19importcertifi 20_fallback_ca_bundle=certifi.where() 21except: 22# Final fallback (last known signer of keylookup) 23_fallback_ca_bundle=os.path.join(os.path.dirname(__file__),"EquifaxSecureCA.crt") 24 25# Note: on MacOS X at least, it will also look in the system keychain provided that you supply *some* CAs. 26# (if you don't specify any trusted CAs, Python trusts everything!) 27# So, the "fallback" option doesn't necessarily mean that other sites won't work. 28forca_bundlein[ 29"/etc/ssl/certs/ca-certificates.crt",# Debian/Ubuntu/Arch Linux 30"/etc/pki/tls/certs/ca-bundle.crt",# Fedora/RHEL 31"/etc/ssl/ca-bundle.pem",# openSUSE/SLE (claimed) 32"/var/lib/ca-certificates/ca-bundle.pem.new",# openSUSE (actual) 33_fallback_ca_bundle]: 34ifos.path.exists(ca_bundle):
52MyHTTPSHandler=ValidatingHTTPSHandler 53break 54else: 55raiseException("No root CA's found (not even the built-in one!); security of HTTPS connections cannot be verified") 56
63"""Throw an exception on redirects instead of continuing. The redirect will be handled in the main thread 64 so it can work with connection pooling."""