2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2010-01-02 05:07:28 +03:00
|
|
|
|
|
|
|
"""
|
2018-01-02 02:48:10 +03:00
|
|
|
Copyright (c) 2006-2018 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-02 05:02:12 +03:00
|
|
|
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
|
|
|
|
2013-09-12 01:17:18 +04:00
|
|
|
class HTTPSPKIAuthHandler(urllib2.HTTPSHandler):
|
2015-09-27 16:59:17 +03:00
|
|
|
def __init__(self, auth_file):
|
2010-01-02 05:02:12 +03:00
|
|
|
urllib2.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
|
|
|
|
return httplib.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=conf.timeout)
|
|
|
|
except IOError, ex:
|
|
|
|
errMsg = "error occurred while using key "
|
|
|
|
errMsg += "file '%s' ('%s')" % (self.auth_file, getSafeExString(ex))
|
|
|
|
raise SqlmapConnectionException(errMsg)
|