-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Expand file tree
/
Copy pathpkihandler.py
More file actions
51 lines (40 loc) · 1.73 KB
/
Copy pathpkihandler.py
File metadata and controls
51 lines (40 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
See the file 'LICENSE' for copying permission
"""
ssl = None
try:
import ssl as _ssl
ssl = _ssl
except ImportError:
pass
from lib.core.data import conf
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
class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler):
def __init__(self, auth_file):
_urllib.request.HTTPSHandler.__init__(self)
self.auth_file = auth_file
def https_open(self, req):
return self.do_open(self.getConnection, req)
def getConnection(self, host, timeout=None):
if timeout is None:
timeout = conf.timeout
if not hasattr(_http_client, "HTTPSConnection"):
raise SqlmapConnectionException("HTTPS support is not available in this Python build")
try:
if ssl and hasattr(ssl, "SSLContext") and hasattr(ssl, "create_default_context"):
ctx = ssl.create_default_context()
ctx.load_cert_chain(certfile=self.auth_file, keyfile=self.auth_file)
try:
return _http_client.HTTPSConnection(host, timeout=timeout, context=ctx)
except TypeError:
pass
return _http_client.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=timeout)
except (IOError, OSError) as ex:
errMsg = "error occurred while using key "
errMsg += "file '%s' ('%s')" % (self.auth_file, getSafeExString(ex))
raise SqlmapConnectionException(errMsg)