sqlmap/lib/request/pkihandler.py

30 lines
1.1 KiB
Python
Raw Normal View History

2019-05-08 13:47:52 +03:00
#!/usr/bin/env python
"""
2024-01-04 01:11:52 +03:00
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
2017-10-11 15:50:46 +03:00
See the file 'LICENSE' for copying permission
"""
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
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
class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler):
2015-09-27 16:59:17 +03:00
def __init__(self, auth_file):
_urllib.request.HTTPSHandler.__init__(self)
2015-09-27 16:59:17 +03:00
self.auth_file = auth_file
def https_open(self, req):
return self.do_open(self.getConnection, req)
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
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)