eric6/E5Network/E5SslCertificatesInfoWidget.py

changeset 7766
0af772bc14c4
parent 7360
9190402e4505
child 7780
41420f82c0ac
diff -r 72ea8b7452a4 -r 0af772bc14c4 eric6/E5Network/E5SslCertificatesInfoWidget.py
--- a/eric6/E5Network/E5SslCertificatesInfoWidget.py	Wed Oct 07 17:58:51 2020 +0200
+++ b/eric6/E5Network/E5SslCertificatesInfoWidget.py	Wed Oct 07 19:14:36 2020 +0200
@@ -10,7 +10,10 @@
 
 from PyQt5.QtCore import pyqtSlot, QCryptographicHash, QDateTime
 from PyQt5.QtWidgets import QWidget
-from PyQt5.QtNetwork import QSslCertificate
+try:
+    from PyQt5.QtNetwork import QSslCertificate
+except ImportError:
+    QSslCertificate = None
 
 from .Ui_E5SslCertificatesInfoWidget import Ui_E5SslCertificatesInfoWidget
 
@@ -39,22 +42,23 @@
         @param certificateChain list od SSL certificates
             (list of QSslCertificate)
         """
-        self.chainLabel.show()
-        self.chainComboBox.show()
-        self.chainComboBox.clear()
-        
-        self.__chain = certificateChain[:]
-        
-        for cert in self.__chain:
-            name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName))
-            if not name:
-                name = ", ".join(
-                    cert.subjectInfo(QSslCertificate.Organization))
-            if not name:
-                name = cert.serialNumber()
-            self.chainComboBox.addItem(name)
-        
-        self.on_chainComboBox_activated(0)
+        if QSslCertificate:
+            self.chainLabel.show()
+            self.chainComboBox.show()
+            self.chainComboBox.clear()
+            
+            self.__chain = certificateChain[:]
+            
+            for cert in self.__chain:
+                name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName))
+                if not name:
+                    name = ", ".join(
+                        cert.subjectInfo(QSslCertificate.Organization))
+                if not name:
+                    name = cert.serialNumber()
+                self.chainComboBox.addItem(name)
+            
+            self.on_chainComboBox_activated(0)
     
     def showCertificate(self, certificate):
         """
@@ -68,7 +72,8 @@
         
         self.__chain = []
         
-        self.__showCertificate(certificate)
+        if QSslCertificate:
+            self.__showCertificate(certificate)
     
     def __showCertificate(self, certificate):
         """
@@ -76,51 +81,52 @@
         
         @param certificate reference to the SSL certificate (QSslCertificate)
         """
-        self.blacklistedLabel.setVisible(False)
-        self.blacklistedLabel.setStyleSheet(
-            "QLabel { color : white; background-color : red; }")
-        self.expiredLabel.setVisible(False)
-        self.expiredLabel.setStyleSheet(
-            "QLabel { color : white; background-color : red; }")
-        
-        self.subjectCommonNameLabel.setText(self.__certificateString(
-            ", ".join(certificate.subjectInfo(
-                QSslCertificate.CommonName))))
-        self.subjectOrganizationLabel.setText(self.__certificateString(
-            ", ".join(certificate.subjectInfo(
-                QSslCertificate.Organization))))
-        self.subjectOrganizationalUnitLabel.setText(
-            self.__certificateString(", ".join(
-                certificate.subjectInfo(
-                    QSslCertificate.OrganizationalUnitName))))
-        self.issuerCommonNameLabel.setText(self.__certificateString(
-            ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
-        self.issuerOrganizationLabel.setText(self.__certificateString(
-            ", ".join(certificate.issuerInfo(
-                QSslCertificate.Organization))))
-        self.issuerOrganizationalUnitLabel.setText(
-            self.__certificateString(", ".join(
-                certificate.issuerInfo(
-                    QSslCertificate.OrganizationalUnitName))))
-        self.serialNumberLabel.setText(self.__serialNumber(certificate))
-        self.effectiveLabel.setText(
-            certificate.effectiveDate().toString("yyyy-MM-dd"))
-        self.expiresLabel.setText(
-            certificate.expiryDate().toString("yyyy-MM-dd"))
-        self.sha1Label.setText(self.__formatHexString(
-            str(certificate.digest(QCryptographicHash.Sha1).toHex(),
-                encoding="ascii")))
-        self.md5Label.setText(self.__formatHexString(
-            str(certificate.digest(QCryptographicHash.Md5).toHex(),
-                encoding="ascii")))
-        
-        if certificate.isBlacklisted():
-            # something is wrong; indicate it to the user
-            if self.__hasExpired(certificate.effectiveDate(),
-                                 certificate.expiryDate()):
-                self.expiredLabel.setVisible(True)
-            else:
-                self.blacklistedLabel.setVisible(True)
+        if QSslCertificate:
+            self.blacklistedLabel.setVisible(False)
+            self.blacklistedLabel.setStyleSheet(
+                "QLabel { color : white; background-color : red; }")
+            self.expiredLabel.setVisible(False)
+            self.expiredLabel.setStyleSheet(
+                "QLabel { color : white; background-color : red; }")
+            
+            self.subjectCommonNameLabel.setText(self.__certificateString(
+                ", ".join(certificate.subjectInfo(
+                    QSslCertificate.CommonName))))
+            self.subjectOrganizationLabel.setText(self.__certificateString(
+                ", ".join(certificate.subjectInfo(
+                    QSslCertificate.Organization))))
+            self.subjectOrganizationalUnitLabel.setText(
+                self.__certificateString(", ".join(
+                    certificate.subjectInfo(
+                        QSslCertificate.OrganizationalUnitName))))
+            self.issuerCommonNameLabel.setText(self.__certificateString(
+                ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
+            self.issuerOrganizationLabel.setText(self.__certificateString(
+                ", ".join(certificate.issuerInfo(
+                    QSslCertificate.Organization))))
+            self.issuerOrganizationalUnitLabel.setText(
+                self.__certificateString(", ".join(
+                    certificate.issuerInfo(
+                        QSslCertificate.OrganizationalUnitName))))
+            self.serialNumberLabel.setText(self.__serialNumber(certificate))
+            self.effectiveLabel.setText(
+                certificate.effectiveDate().toString("yyyy-MM-dd"))
+            self.expiresLabel.setText(
+                certificate.expiryDate().toString("yyyy-MM-dd"))
+            self.sha1Label.setText(self.__formatHexString(
+                str(certificate.digest(QCryptographicHash.Sha1).toHex(),
+                    encoding="ascii")))
+            self.md5Label.setText(self.__formatHexString(
+                str(certificate.digest(QCryptographicHash.Md5).toHex(),
+                    encoding="ascii")))
+            
+            if certificate.isBlacklisted():
+                # something is wrong; indicate it to the user
+                if self.__hasExpired(certificate.effectiveDate(),
+                                     certificate.expiryDate()):
+                    self.expiredLabel.setVisible(True)
+                else:
+                    self.blacklistedLabel.setVisible(True)
     
     def __certificateString(self, txt):
         """

eric ide

mercurial