Exemplo n.º 1
0
    def __init__(self, loglevel='WARNING', ifcName='wlan0'):
        QObject.__init__(self)

        self.logger = Logger(name='ratt.networker')
        self.logger.setLogLevelStr(loglevel)
        self.debug = self.logger.isDebug()

        self.mgr = QNetworkAccessManager()
        self.sslConfig = QSslConfiguration()
        self.sslSupported = QSslSocket.supportsSsl()

        self.setAuth()
        self.setSSLCertConfig()

        self.mgr.authenticationRequired.connect(
            self.handleAuthenticationRequired)

        self.ifcName = ifcName
        self.ifcAddr = QHostAddress()

        self.statusTimer = QTimer()
        self.statusTimer.setSingleShot(False)
        self.statusTimer.timeout.connect(self.slotStatusTimer)
        self.statusTimer.start(5000)

        self.essid = ''
        self.freq = ''
        self.quality = 0
        self.level = 0
Exemplo n.º 2
0
    def __init__(self, parent):
        super().__init__(parent)
        self.client = QWebSocket("", QWebSocketProtocol.Version13, None)        
        self.client.error.connect(self.onError)
        self.client.connected.connect(self.onConnected)
        self.client.disconnected.connect(self.onDisconnected)
        self.ssl_config = QSslConfiguration()
        self.ssl_cert_file = QFile(":certs/server.pem")
        self.ssl_cert_file.open(QIODevice.ReadOnly)
        self.ssl_cert = QSslCertificate(self.ssl_cert_file)
        self.ssl_config.setCaCertificates([self.ssl_cert])
        self.client.setSslConfiguration(self.ssl_config)
        self.message_queue = []
        self.is_connected = False
        self.telemetry_connected = False
        self.websocket_url = "wss://localhost:8081"
        self.websocket_token = "aVerySecureToken"
        
        self.timer_connection_watchdog = QTimer(parent)
        self.timer_connection_watchdog.start(5000)
        self.timer_connection_watchdog.timeout.connect(self.connection_watchdog)

        self.timer_reconnect = QTimer(parent)
        self.timer_reconnect.start(500)
        self.timer_reconnect.timeout.connect(self.send_message)
Exemplo n.º 3
0
    def createRequest(self, operation, request, device=None):
        if not self.control.job():
            return super().createRequest(operation, request, device)

        url = request.url()
        url_str = url.toString()

        if self.rule_list:
            for r in self.rule_list:
                if r.rule.search(url_str):
                    if r.rule_type == self._reject:
                        logger.debug(self.control.prepend_id('Blocking {}'.format(url_str)))
                        return super().createRequest(operation, QNetworkRequest(QUrl()), device)
                    else:
                        break

        if self.proxy and self.control.job() and self.control.job().is_crawlera:
            scheme = url.scheme()
            if scheme == 'https':
                url.setScheme('http')
                request.setRawHeader(b'X-Crawlera-Use-HTTPS', b'1')
                # TODO Check if this is needed
                request.setSslConfiguration(QSslConfiguration())
                request.setUrl(url)
            elif scheme == 'http':
                pass
            else:
                # We fail any request that is not http or https
                logger.warning(self.control.prepend_id('Unsupported Schema {}'.format(url_str)))
                return super().createRequest(operation, QNetworkRequest(QUrl()), device)

            key = bytes('{}:{}'.format(self.proxy.user(), self.proxy.password()), HTTP_HEADER_CHARSET)
            proxy_auth_value = b'Basic ' + base64.urlsafe_b64encode(key)
            request.setRawHeader(b'Proxy-Authorization', proxy_auth_value)
            request.setRawHeader(b'Proxy-Connection', b'Keep-Alive')
            request.setRawHeader(b'X-Crawlera-Cookies', b'disable')
            request.setRawHeader(b'X-Crawlera-UA', b'desktop')

        network_reply = super().createRequest(operation, request, device)
        network_reply.finished.connect(lambda: self.request_finished(network_reply))
        return network_reply
Exemplo n.º 4
0
    def __init__(
        self,
        protocol=None,
        key=None,
        options=None,
    ):
        super(SSLConfig, self).__init__(
            protocol=protocol,
            key=key,
            options=options,
        )

        # Set up implementation-specific state...

        # QSslConfiguration is a bag of data we need to talk to Qt. Its
        # attributes must be set using its various setWhatever methods.
        self._q_ssl_config = QSslConfiguration()

        # Get a protocol constant Qt understands, or cry to the user.
        q_ssl_protocol = _PROTOCOL_CHOICES.get(self.protocol)
        if q_ssl_protocol is None:
            raise InvalidSSLConfig("unknown protocol for Qt: {0!r}".format(
                self.protocol))
        # Hang on to it just in case we possibly need it, e.g. debugger
        self._q_ssl_protocol = q_ssl_protocol

        # Otherwise, tell Qt about the protocol.
        # n.b.: setting this after connection starts has no effect, so we
        # definitely want to do it here instead of deferring this.
        self._q_ssl_config.setProtocol(q_ssl_protocol)

        # If we have an SSLKey, have it make a QSslKey and tell Qt about it.
        if self.key:
            q_ssl_key = self.key.to_q_ssl_key()
            self._q_ssl_config.setPrivateKey(q_ssl_key)
        else:
            q_ssl_key = None
        self._q_ssl_key = q_ssl_key

        # Process self.options
        self._set_options()
Exemplo n.º 5
0
    def __init__(self, url, configuration, parent=None):
        """
        Constructor
        
        @param url URL to show SSL info for (QUrl)
        @param configuration SSL configuration (QSslConfiguration)
        @param parent reference to the parent widget (QWidget)
        """
        super(E5SslInfoWidget, self).__init__(parent)

        self.__url = QUrl(url)
        self.__configuration = QSslConfiguration(configuration)

        self.setMinimumWidth(400)

        certList = self.__configuration.peerCertificateChain()
        if certList:
            cert = certList[0]
        else:
            cert = QSslCertificate()

        layout = QGridLayout(self)
        rows = 0

        ##########################################
        ## Identity Information
        ##########################################
        imageLabel = QLabel(self)
        layout.addWidget(imageLabel, rows, 0, Qt.AlignCenter)

        label = QLabel(self)
        label.setWordWrap(True)
        label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        label.setText(self.tr("Identity"))
        font = label.font()
        font.setBold(True)
        label.setFont(font)
        layout.addWidget(label, rows, 1)
        rows += 1

        label = QLabel(self)
        label.setWordWrap(True)
        if cert.isNull():
            label.setText(
                self.tr("Warning: this site is NOT carrying a certificate."))
            imageLabel.setPixmap(UI.PixmapCache.getPixmap("securityLow32.png"))
        else:
            if qVersion() >= "5.0.0":
                valid = not cert.isBlacklisted()
            else:
                valid = cert.isValid()
            if valid:
                if qVersion() >= "5.0.0":
                    txt = ", ".join(cert.issuerInfo(
                        QSslCertificate.CommonName))
                else:
                    txt = cert.issuerInfo(QSslCertificate.CommonName)
                label.setText(
                    self.tr("The certificate for this site is valid"
                            " and has been verified by:\n{0}").format(
                                Utilities.decodeString(txt)))
                imageLabel.setPixmap(
                    UI.PixmapCache.getPixmap("securityHigh32.png"))
            else:
                label.setText(
                    self.tr("The certificate for this site is NOT valid."))
                imageLabel.setPixmap(
                    UI.PixmapCache.getPixmap("securityLow32.png"))
            layout.addWidget(label, rows, 1)
            rows += 1

            label = QLabel(self)
            label.setWordWrap(True)
            label.setText('<a href="moresslinfos">' +
                          self.tr("Certificate Information") + "</a>")
            label.linkActivated.connect(self.__showCertificateInfos)
            layout.addWidget(label, rows, 1)
            rows += 1

        ##########################################
        ## Identity Information
        ##########################################
        imageLabel = QLabel(self)
        layout.addWidget(imageLabel, rows, 0, Qt.AlignCenter)

        label = QLabel(self)
        label.setWordWrap(True)
        label.setText(self.tr("Encryption"))
        font = label.font()
        font.setBold(True)
        label.setFont(font)
        layout.addWidget(label, rows, 1)
        rows += 1

        cipher = self.__configuration.sessionCipher()
        if cipher.isNull():
            label = QLabel(self)
            label.setWordWrap(True)
            label.setText(
                self.tr('Your connection to "{0}" is NOT encrypted.\n').format(
                    self.__url.host()))
            layout.addWidget(label, rows, 1)
            imageLabel.setPixmap(UI.PixmapCache.getPixmap("securityLow32.png"))
            rows += 1
        else:
            label = QLabel(self)
            label.setWordWrap(True)
            label.setText(
                self.tr('Your connection to "{0}" is encrypted.').format(
                    self.__url.host()))
            layout.addWidget(label, rows, 1)

            proto = cipher.protocol()
            if proto == QSsl.SslV3:
                sslVersion = "SSL 3.0"
                imageLabel.setPixmap(
                    UI.PixmapCache.getPixmap("securityHigh32.png"))
            elif proto == QSsl.TlsV1SslV3:
                sslVersion = "TLS 1.0/SSL 3.0"
                imageLabel.setPixmap(
                    UI.PixmapCache.getPixmap("securityHigh32.png"))
            elif proto == QSsl.SslV2:
                sslVersion = "SSL 2.0"
                imageLabel.setPixmap(
                    UI.PixmapCache.getPixmap("securityLow32.png"))
            else:
                sslVersion = self.tr("unknown")
                imageLabel.setPixmap(
                    UI.PixmapCache.getPixmap("securityLow32.png"))
            if qVersion() >= "5.0.0":
                if proto == QSsl.TlsV1_0:
                    sslVersion = "TLS 1.0"
                    imageLabel.setPixmap(
                        UI.PixmapCache.getPixmap("securityHigh32.png"))
                elif proto == QSsl.TlsV1_1:
                    sslVersion = "TLS 1.1"
                    imageLabel.setPixmap(
                        UI.PixmapCache.getPixmap("securityHigh32.png"))
                elif proto == QSsl.TlsV1_2:
                    sslVersion = "TLS 1.2"
                    imageLabel.setPixmap(
                        UI.PixmapCache.getPixmap("securityHigh32.png"))
            else:
                if proto == QSsl.TlsV1:
                    sslVersion = "TLS 1.0"
                    imageLabel.setPixmap(
                        UI.PixmapCache.getPixmap("securityHigh32.png"))
            rows += 1

            label = QLabel(self)
            label.setWordWrap(True)
            label.setText(self.tr("It uses protocol: {0}").format(sslVersion))
            layout.addWidget(label, rows, 1)
            rows += 1

            label = QLabel(self)
            label.setWordWrap(True)
            label.setText(
                self.tr("It is encrypted using {0} at {1} bits, "
                        "with {2} for message authentication and "
                        "{3} as key exchange mechanism.\n\n").format(
                            cipher.encryptionMethod(), cipher.usedBits(),
                            cipher.authenticationMethod(),
                            cipher.keyExchangeMethod()))
            layout.addWidget(label, rows, 1)
            rows += 1