Tools to easily get the CERTHASH
This commit is contained in:
parent
8c549e65b2
commit
db9f2d6d73
2 changed files with 11 additions and 2 deletions
5
tools/certhash.py
Executable file
5
tools/certhash.py
Executable file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
|
from weboob.tools.browser import StandardBrowser
|
||||||
|
|
||||||
|
print StandardBrowser()._certhash(sys.argv[1])
|
||||||
|
|
@ -123,6 +123,7 @@ class NoHistory(object):
|
||||||
class BrokenPageError(Exception):
|
class BrokenPageError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FormFieldConversionWarning(UserWarning):
|
class FormFieldConversionWarning(UserWarning):
|
||||||
"""
|
"""
|
||||||
A value has been set to a form's field and has been implicitly converted.
|
A value has been set to a form's field and has been implicitly converted.
|
||||||
|
|
@ -438,8 +439,7 @@ class StandardBrowser(mechanize.Browser):
|
||||||
return
|
return
|
||||||
|
|
||||||
def lowsslcheck(self, domain, hsh):
|
def lowsslcheck(self, domain, hsh):
|
||||||
certs = ssl.get_server_certificate((domain, 443))
|
certhash = self._certhash(domain)
|
||||||
certhash = hashlib.sha256(certs).hexdigest()
|
|
||||||
if self.logger:
|
if self.logger:
|
||||||
self.logger.debug('Found %s as certificate hash' % certhash)
|
self.logger.debug('Found %s as certificate hash' % certhash)
|
||||||
if isinstance(hsh, basestring):
|
if isinstance(hsh, basestring):
|
||||||
|
|
@ -447,6 +447,10 @@ class StandardBrowser(mechanize.Browser):
|
||||||
if certhash not in hsh:
|
if certhash not in hsh:
|
||||||
raise ssl.SSLError()
|
raise ssl.SSLError()
|
||||||
|
|
||||||
|
def _certhash(self, domain, port=443):
|
||||||
|
certs = ssl.get_server_certificate((domain, port))
|
||||||
|
return hashlib.sha256(certs).hexdigest()
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if isinstance(value, unicode):
|
if isinstance(value, unicode):
|
||||||
value = value.encode(self.ENCODING or 'utf-8')
|
value = value.encode(self.ENCODING or 'utf-8')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue