automagically check certificate fingerprint if CERTHASH class attribute is set

This commit is contained in:
Romain Bignon 2012-09-01 13:36:30 +02:00
commit 56797a7d0c

View file

@ -406,7 +406,7 @@ class StandardBrowser(mechanize.Browser):
if certhash != hash:
raise ssl.SSLError()
class BaseBrowser(StandardBrowser):
"""
Base browser class to navigate on a website.
@ -441,6 +441,10 @@ class BaseBrowser(StandardBrowser):
PROTOCOL = 'http'
PAGES = {}
# SHA-256 hash of server certificate. If set, it will automatically check it,
# and raise a SSLError exception if it doesn't match.
CERTHASH = None
# ------ Abstract methods --------------------------------------
def home(self):
@ -479,6 +483,9 @@ class BaseBrowser(StandardBrowser):
self.username = username
self.password = password
if self.CERTHASH is not None and self.DOMAIN is not None:
self.lowsslcheck(self.DOMAIN, self.CERTHASH)
if self.password and get_home:
try:
self.home()