automagically check certificate fingerprint if CERTHASH class attribute is set
This commit is contained in:
parent
702b56d594
commit
56797a7d0c
1 changed files with 8 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue