def on_ssl_errors(self, reply, qt_errors):  # noqa: C901 pragma: no mccabe
        """Decide if SSL errors should be ignored or not.

        This slot is called on SSL/TLS errors by the self.sslErrors signal.

        Args:
            reply: The QNetworkReply that is encountering the errors.
            qt_errors: A list of errors.
        """
        errors = certificateerror.CertificateErrorWrapper(qt_errors)
        log.network.debug("Certificate errors: {!r}".format(errors))
        try:
            host_tpl: Optional[urlutils.HostTupleType] = urlutils.host_tuple(
                reply.url())
        except ValueError:
            host_tpl = None
            is_accepted = False
            is_rejected = False
        else:
            assert host_tpl is not None
            is_accepted = errors in self._accepted_ssl_errors[host_tpl]
            is_rejected = errors in self._rejected_ssl_errors[host_tpl]

        log.network.debug("Already accepted: {} / "
                          "rejected {}".format(is_accepted, is_rejected))

        if is_rejected:
            return
        elif is_accepted:
            reply.ignoreSslErrors()
            return

        abort_on = self._get_abort_signals(reply)

        tab = self._get_tab()
        first_party_url = QUrl(
        ) if tab is None else tab.data.last_navigation.url

        ignore = shared.ignore_certificate_error(
            request_url=reply.url(),
            first_party_url=first_party_url,
            error=errors,
            abort_on=abort_on,
        )
        if ignore:
            reply.ignoreSslErrors()
            if host_tpl is not None:
                self._accepted_ssl_errors[host_tpl].add(errors)
        elif host_tpl is not None:
            self._rejected_ssl_errors[host_tpl].add(errors)
Esempio n. 2
0
    def on_ssl_errors(self, reply, errors):  # noqa: C901 pragma: no mccabe
        """Decide if SSL errors should be ignored or not.

        This slot is called on SSL/TLS errors by the self.sslErrors signal.

        Args:
            reply: The QNetworkReply that is encountering the errors.
            errors: A list of errors.
        """
        errors = [certificateerror.CertificateErrorWrapper(e) for e in errors]
        log.webview.debug("Certificate errors: {!r}".format(' / '.join(
            str(err) for err in errors)))
        try:
            host_tpl = urlutils.host_tuple(
                reply.url())  # type: typing.Optional[urlutils.HostTupleType]
        except ValueError:
            host_tpl = None
            is_accepted = False
            is_rejected = False
        else:
            assert host_tpl is not None
            is_accepted = set(errors).issubset(
                self._accepted_ssl_errors[host_tpl])
            is_rejected = set(errors).issubset(
                self._rejected_ssl_errors[host_tpl])

        log.webview.debug("Already accepted: {} / "
                          "rejected {}".format(is_accepted, is_rejected))

        if is_rejected:
            return
        elif is_accepted:
            reply.ignoreSslErrors()
            return

        abort_on = self._get_abort_signals(reply)
        ignore = shared.ignore_certificate_errors(reply.url(),
                                                  errors,
                                                  abort_on=abort_on)
        if ignore:
            reply.ignoreSslErrors()
            err_dict = self._accepted_ssl_errors
        else:
            err_dict = self._rejected_ssl_errors
        if host_tpl is not None:
            err_dict[host_tpl] += errors
Esempio n. 3
0
def test_html(errors, expected):
    wrapper = certificateerror.CertificateErrorWrapper(errors)
    lines = [
        line.strip() for line in wrapper.html().splitlines() if line.strip()
    ]
    assert lines == expected