Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSL Verification Errors #791

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions bbot/core/helpers/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ class WebHelper:
def __init__(self, parent_helper):
self.parent_helper = parent_helper
self.http_debug = self.parent_helper.config.get("http_debug", False)
self._ssl_context_noverify = None
self.ssl_verify = self.parent_helper.config.get("ssl_verify", False)
if self.ssl_verify is False:
self.ssl_verify = self.ssl_context_noverify()
self.web_client = self.AsyncClient(persist_cookies=False)

def AsyncClient(self, *args, **kwargs):
Expand Down Expand Up @@ -453,7 +456,7 @@ async def curl(self, *args, **kwargs):
curl_command.append("--path-as-is")

# respect global ssl verify settings
if self.ssl_verify == False:
if self.ssl_verify is not True:
curl_command.append("-k")

headers = kwargs.get("headers", {})
Expand Down Expand Up @@ -563,13 +566,15 @@ def is_spider_danger(self, source_event, url):
return False

def ssl_context_noverify(self):
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
ssl_context.options &= ~ssl.OP_NO_SSLv2 & ~ssl.OP_NO_SSLv3
ssl_context.set_ciphers("ALL:@SECLEVEL=0")
ssl_context.options |= 0x4 # Add the OP_LEGACY_SERVER_CONNECT option
return ssl_context
if self._ssl_context_noverify is None:
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
ssl_context.options &= ~ssl.OP_NO_SSLv2 & ~ssl.OP_NO_SSLv3
ssl_context.set_ciphers("ALL:@SECLEVEL=0")
ssl_context.options |= 0x4 # Add the OP_LEGACY_SERVER_CONNECT option
self._ssl_context_noverify = ssl_context
return self._ssl_context_noverify

@asynccontextmanager
async def _acatch(self, url, raise_error):
Expand Down