From defcf5394a035e8606359c8d6b6a8abc60014cd6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 28 Sep 2017 08:11:26 +0200 Subject: [PATCH] Move SSL backend checking to backendproblem.py --- qutebrowser/config/configinit.py | 1 - qutebrowser/misc/backendproblem.py | 31 +++++++++++++++++++++++++++++- qutebrowser/misc/earlyinit.py | 28 --------------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/qutebrowser/config/configinit.py b/qutebrowser/config/configinit.py index aa622850c..1b36fd675 100644 --- a/qutebrowser/config/configinit.py +++ b/qutebrowser/config/configinit.py @@ -69,7 +69,6 @@ def early_init(args): configfiles.init() objects.backend = get_backend(args) - earlyinit.init_with_backend(objects.backend) def get_backend(args): diff --git a/qutebrowser/misc/backendproblem.py b/qutebrowser/misc/backendproblem.py index caa21f97d..fdd13346c 100644 --- a/qutebrowser/misc/backendproblem.py +++ b/qutebrowser/misc/backendproblem.py @@ -28,9 +28,10 @@ import attr from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QApplication, QDialog, QPushButton, QHBoxLayout, QVBoxLayout, QLabel, QMessageBox) +from PyQt5.QtNetwork import QSslSocket from qutebrowser.config import config -from qutebrowser.utils import usertypes, objreg, version, qtutils +from qutebrowser.utils import usertypes, objreg, version, qtutils, log from qutebrowser.misc import objects, msgbox @@ -225,6 +226,32 @@ def _try_import_backends(): return results +def _handle_ssl_support(fatal=False): + """Check for full SSL availability. + + If "fatal" is given, show an error and exit. + """ + text = ("Could not initialize QtNetwork SSL support. If you use " + "OpenSSL 1.1 with a PyQt package from PyPI (e.g. on Archlinux " + "or Debian Stretch), you need to set LD_LIBRARY_PATH to the path " + "of OpenSSL 1.0. This only affects downloads.") + + if QSslSocket.supportsSsl(): + return + + if fatal: + errbox = msgbox.msgbox(parent=None, + title="SSL error", + text="Could not initialize SSL support.", + icon=QMessageBox.Critical, + plain_text=False) + errbox.exec_() + sys.exit(usertypes.Exit.err_init) + + assert not fatal + log.init.warning(text) + + def _check_backend_modules(): """Check for the modules needed for QtWebKit/QtWebEngine.""" imports = _try_import_backends() @@ -275,7 +302,9 @@ def _check_backend_modules(): def init(): _check_backend_modules() if objects.backend == usertypes.Backend.QtWebEngine: + _handle_ssl_support() _handle_wayland() _handle_nouveau_graphics() else: assert objects.backend == usertypes.Backend.QtWebKit, objects.backend + _handle_ssl_support(fatal=True) diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index f481f4dba..ca12cd901 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -187,23 +187,6 @@ def check_ssl_support(): _die("Fatal error: Your Qt is built without SSL support.") -def check_backend_ssl_support(backend): - """Check for full SSL availability when we know the backend.""" - from PyQt5.QtNetwork import QSslSocket - from qutebrowser.utils import log, usertypes - text = ("Could not initialize QtNetwork SSL support. If you use " - "OpenSSL 1.1 with a PyQt package from PyPI (e.g. on Archlinux " - "or Debian Stretch), you need to set LD_LIBRARY_PATH to the path " - "of OpenSSL 1.0. This only affects downloads.") - - if not QSslSocket.supportsSsl(): - if backend == usertypes.Backend.QtWebKit: - _die("Could not initialize SSL support.") - else: - assert backend == usertypes.Backend.QtWebEngine - log.init.warning(text) - - def _check_modules(modules): """Make sure the given modules are available.""" from qutebrowser.utils import log @@ -299,14 +282,3 @@ def early_init(args): remove_inputhook() check_ssl_support() check_optimize_flag() - - -def init_with_backend(backend): - """Do later stages of init when we know the backend. - - Args: - backend: The backend as usertypes.Backend member. - """ - assert not isinstance(backend, str), backend - assert backend is not None - check_backend_ssl_support(backend)