From: Chris Laplante <[email protected]>
On my system, ssl.create_default_context() takes between 100-200ms,
presumably because it has to load all the certs in /etc/ssl/.
Signed-off-by: Chris Laplante <[email protected]>
---
lib/bb/fetch2/wget.py | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 94a1ec973..0d2b7f5c8 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -54,12 +54,34 @@ class WgetProgressHandler(bb.progress.LineFilterProgressHandler):
class Wget(FetchMethod):
"""Class to fetch urls via 'wget'"""
+ def __init__(self):
+ super().__init__()
+ self._unverified_ssl_context = None
+ self._verified_ssl_context = None
+
def check_certs(self, d):
"""
Should certificates be checked?
"""
return (d.getVar("BB_CHECK_SSL_CERTS") or "1") != "0"
+ def ssl_context(self, d):
+ """
+ Get an SSL context, caching it to avoid creating every time.
+ """
+ if self.check_certs(d):
+ # Cache verified SSL context
+ if self._verified_ssl_context is None:
+ import ssl
+ self._verified_ssl_context = ssl.create_default_context()
+ return self._verified_ssl_context
+
+ # Cache unverified SSL context
+ if self._unverified_ssl_context is None:
+ import ssl
+ self._unverified_ssl_context = ssl._create_unverified_context()
+ return self._unverified_ssl_context
+
def supports(self, ud, d):
"""
Check to see if a given url can be fetched with wget.
@@ -412,13 +434,7 @@ class Wget(FetchMethod):
# to scope the changes to the build_opener request, which is when the
# environment lookups happen.
with bb.utils.environment(**newenv):
- import ssl
-
- if check_certs:
- context = ssl.create_default_context()
- else:
- context = ssl._create_unverified_context()
-
+ context = self.ssl_context(d)
handlers = [FixedHTTPRedirectHandler,
HTTPMethodFallback,
urllib.request.ProxyHandler(),
--
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.