Tools to easily get the CERTHASH

This commit is contained in:
Laurent Bachelier 2013-07-23 13:38:26 +02:00
commit db9f2d6d73
2 changed files with 11 additions and 2 deletions

5
tools/certhash.py Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
import sys
from weboob.tools.browser import StandardBrowser
print StandardBrowser()._certhash(sys.argv[1])

View file

@ -123,6 +123,7 @@ class NoHistory(object):
class BrokenPageError(Exception):
pass
class FormFieldConversionWarning(UserWarning):
"""
A value has been set to a form's field and has been implicitly converted.
@ -438,8 +439,7 @@ class StandardBrowser(mechanize.Browser):
return
def lowsslcheck(self, domain, hsh):
certs = ssl.get_server_certificate((domain, 443))
certhash = hashlib.sha256(certs).hexdigest()
certhash = self._certhash(domain)
if self.logger:
self.logger.debug('Found %s as certificate hash' % certhash)
if isinstance(hsh, basestring):
@ -447,6 +447,10 @@ class StandardBrowser(mechanize.Browser):
if certhash not in hsh:
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):
if isinstance(value, unicode):
value = value.encode(self.ENCODING or 'utf-8')