sqlmap/lib/request/pkihandler.py

31 lines
1.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python
"""
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
"""
import httplib
import urllib2
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
2010-01-07 15:59:09 +03:00
class HTTPSPKIAuthHandler(urllib2.HTTPSHandler):
2015-09-27 16:59:17 +03:00
def __init__(self, auth_file):
urllib2.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 httplib.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)