2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2010-01-02 05:07:28 +03:00
|
|
|
|
|
|
|
"""
|
2019-01-05 23:38:52 +03:00
|
|
|
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2010-01-02 05:07:28 +03:00
|
|
|
"""
|
|
|
|
|
2010-01-07 15:59:09 +03:00
|
|
|
from lib.core.data import conf
|
2018-08-22 11:20:26 +03:00
|
|
|
from lib.core.common import getSafeExString
|
|
|
|
from lib.core.exception import SqlmapConnectionException
|
2019-03-27 15:33:46 +03:00
|
|
|
from thirdparty.six.moves import http_client as _http_client
|
|
|
|
from thirdparty.six.moves import urllib as _urllib
|
2010-01-07 15:59:09 +03:00
|
|
|
|
2019-03-27 15:33:46 +03:00
|
|
|
class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler):
|
2015-09-27 16:59:17 +03:00
|
|
|
def __init__(self, auth_file):
|
2019-03-27 15:33:46 +03:00
|
|
|
_urllib.request.HTTPSHandler.__init__(self)
|
2015-09-27 16:59:17 +03:00
|
|
|
self.auth_file = auth_file
|
2010-01-02 05:07:28 +03:00
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
def https_open(self, req):
|
|
|
|
return self.do_open(self.getConnection, req)
|
2010-01-02 05:07:28 +03:00
|
|
|
|
2013-02-05 15:16:06 +04:00
|
|
|
def getConnection(self, host, timeout=None):
|
2018-08-22 11:20:26 +03:00
|
|
|
try:
|
|
|
|
# Reference: https://docs.python.org/2/library/ssl.html#ssl.SSLContext.load_cert_chain
|
2019-03-27 15:33:46 +03:00
|
|
|
return _http_client.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=conf.timeout)
|
2019-01-22 02:40:48 +03:00
|
|
|
except IOError as ex:
|
2018-08-22 11:20:26 +03:00
|
|
|
errMsg = "error occurred while using key "
|
|
|
|
errMsg += "file '%s' ('%s')" % (self.auth_file, getSafeExString(ex))
|
|
|
|
raise SqlmapConnectionException(errMsg)
|