Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/lib/request/pkihandler.py
2989 views
1
#!/usr/bin/env python
2
3
"""
4
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
5
See the file 'LICENSE' for copying permission
6
"""
7
8
from lib.core.data import conf
9
from lib.core.common import getSafeExString
10
from lib.core.exception import SqlmapConnectionException
11
from thirdparty.six.moves import http_client as _http_client
12
from thirdparty.six.moves import urllib as _urllib
13
14
class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler):
15
def __init__(self, auth_file):
16
_urllib.request.HTTPSHandler.__init__(self)
17
self.auth_file = auth_file
18
19
def https_open(self, req):
20
return self.do_open(self.getConnection, req)
21
22
def getConnection(self, host, timeout=None):
23
try:
24
# Reference: https://docs.python.org/2/library/ssl.html#ssl.SSLContext.load_cert_chain
25
return _http_client.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=conf.timeout)
26
except IOError as ex:
27
errMsg = "error occurred while using key "
28
errMsg += "file '%s' ('%s')" % (self.auth_file, getSafeExString(ex))
29
raise SqlmapConnectionException(errMsg)
30
31