eric6/E5Network/E5SslCertificatesInfoWidget.py

changeset 7766
0af772bc14c4
parent 7360
9190402e4505
child 7780
41420f82c0ac
equal deleted inserted replaced
7765:72ea8b7452a4 7766:0af772bc14c4
8 """ 8 """
9 9
10 10
11 from PyQt5.QtCore import pyqtSlot, QCryptographicHash, QDateTime 11 from PyQt5.QtCore import pyqtSlot, QCryptographicHash, QDateTime
12 from PyQt5.QtWidgets import QWidget 12 from PyQt5.QtWidgets import QWidget
13 from PyQt5.QtNetwork import QSslCertificate 13 try:
14 from PyQt5.QtNetwork import QSslCertificate
15 except ImportError:
16 QSslCertificate = None
14 17
15 from .Ui_E5SslCertificatesInfoWidget import Ui_E5SslCertificatesInfoWidget 18 from .Ui_E5SslCertificatesInfoWidget import Ui_E5SslCertificatesInfoWidget
16 19
17 import Utilities 20 import Utilities
18 21
37 Public method to show the SSL certificates of a certificate chain. 40 Public method to show the SSL certificates of a certificate chain.
38 41
39 @param certificateChain list od SSL certificates 42 @param certificateChain list od SSL certificates
40 (list of QSslCertificate) 43 (list of QSslCertificate)
41 """ 44 """
42 self.chainLabel.show() 45 if QSslCertificate:
43 self.chainComboBox.show() 46 self.chainLabel.show()
44 self.chainComboBox.clear() 47 self.chainComboBox.show()
45 48 self.chainComboBox.clear()
46 self.__chain = certificateChain[:] 49
47 50 self.__chain = certificateChain[:]
48 for cert in self.__chain: 51
49 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName)) 52 for cert in self.__chain:
50 if not name: 53 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName))
51 name = ", ".join( 54 if not name:
52 cert.subjectInfo(QSslCertificate.Organization)) 55 name = ", ".join(
53 if not name: 56 cert.subjectInfo(QSslCertificate.Organization))
54 name = cert.serialNumber() 57 if not name:
55 self.chainComboBox.addItem(name) 58 name = cert.serialNumber()
56 59 self.chainComboBox.addItem(name)
57 self.on_chainComboBox_activated(0) 60
61 self.on_chainComboBox_activated(0)
58 62
59 def showCertificate(self, certificate): 63 def showCertificate(self, certificate):
60 """ 64 """
61 Public method to show the SSL certificate information. 65 Public method to show the SSL certificate information.
62 66
66 self.chainComboBox.hide() 70 self.chainComboBox.hide()
67 self.chainComboBox.clear() 71 self.chainComboBox.clear()
68 72
69 self.__chain = [] 73 self.__chain = []
70 74
71 self.__showCertificate(certificate) 75 if QSslCertificate:
76 self.__showCertificate(certificate)
72 77
73 def __showCertificate(self, certificate): 78 def __showCertificate(self, certificate):
74 """ 79 """
75 Private method to show the SSL certificate information. 80 Private method to show the SSL certificate information.
76 81
77 @param certificate reference to the SSL certificate (QSslCertificate) 82 @param certificate reference to the SSL certificate (QSslCertificate)
78 """ 83 """
79 self.blacklistedLabel.setVisible(False) 84 if QSslCertificate:
80 self.blacklistedLabel.setStyleSheet( 85 self.blacklistedLabel.setVisible(False)
81 "QLabel { color : white; background-color : red; }") 86 self.blacklistedLabel.setStyleSheet(
82 self.expiredLabel.setVisible(False) 87 "QLabel { color : white; background-color : red; }")
83 self.expiredLabel.setStyleSheet( 88 self.expiredLabel.setVisible(False)
84 "QLabel { color : white; background-color : red; }") 89 self.expiredLabel.setStyleSheet(
85 90 "QLabel { color : white; background-color : red; }")
86 self.subjectCommonNameLabel.setText(self.__certificateString( 91
87 ", ".join(certificate.subjectInfo( 92 self.subjectCommonNameLabel.setText(self.__certificateString(
88 QSslCertificate.CommonName)))) 93 ", ".join(certificate.subjectInfo(
89 self.subjectOrganizationLabel.setText(self.__certificateString( 94 QSslCertificate.CommonName))))
90 ", ".join(certificate.subjectInfo( 95 self.subjectOrganizationLabel.setText(self.__certificateString(
91 QSslCertificate.Organization)))) 96 ", ".join(certificate.subjectInfo(
92 self.subjectOrganizationalUnitLabel.setText( 97 QSslCertificate.Organization))))
93 self.__certificateString(", ".join( 98 self.subjectOrganizationalUnitLabel.setText(
94 certificate.subjectInfo( 99 self.__certificateString(", ".join(
95 QSslCertificate.OrganizationalUnitName)))) 100 certificate.subjectInfo(
96 self.issuerCommonNameLabel.setText(self.__certificateString( 101 QSslCertificate.OrganizationalUnitName))))
97 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName)))) 102 self.issuerCommonNameLabel.setText(self.__certificateString(
98 self.issuerOrganizationLabel.setText(self.__certificateString( 103 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
99 ", ".join(certificate.issuerInfo( 104 self.issuerOrganizationLabel.setText(self.__certificateString(
100 QSslCertificate.Organization)))) 105 ", ".join(certificate.issuerInfo(
101 self.issuerOrganizationalUnitLabel.setText( 106 QSslCertificate.Organization))))
102 self.__certificateString(", ".join( 107 self.issuerOrganizationalUnitLabel.setText(
103 certificate.issuerInfo( 108 self.__certificateString(", ".join(
104 QSslCertificate.OrganizationalUnitName)))) 109 certificate.issuerInfo(
105 self.serialNumberLabel.setText(self.__serialNumber(certificate)) 110 QSslCertificate.OrganizationalUnitName))))
106 self.effectiveLabel.setText( 111 self.serialNumberLabel.setText(self.__serialNumber(certificate))
107 certificate.effectiveDate().toString("yyyy-MM-dd")) 112 self.effectiveLabel.setText(
108 self.expiresLabel.setText( 113 certificate.effectiveDate().toString("yyyy-MM-dd"))
109 certificate.expiryDate().toString("yyyy-MM-dd")) 114 self.expiresLabel.setText(
110 self.sha1Label.setText(self.__formatHexString( 115 certificate.expiryDate().toString("yyyy-MM-dd"))
111 str(certificate.digest(QCryptographicHash.Sha1).toHex(), 116 self.sha1Label.setText(self.__formatHexString(
112 encoding="ascii"))) 117 str(certificate.digest(QCryptographicHash.Sha1).toHex(),
113 self.md5Label.setText(self.__formatHexString( 118 encoding="ascii")))
114 str(certificate.digest(QCryptographicHash.Md5).toHex(), 119 self.md5Label.setText(self.__formatHexString(
115 encoding="ascii"))) 120 str(certificate.digest(QCryptographicHash.Md5).toHex(),
116 121 encoding="ascii")))
117 if certificate.isBlacklisted(): 122
118 # something is wrong; indicate it to the user 123 if certificate.isBlacklisted():
119 if self.__hasExpired(certificate.effectiveDate(), 124 # something is wrong; indicate it to the user
120 certificate.expiryDate()): 125 if self.__hasExpired(certificate.effectiveDate(),
121 self.expiredLabel.setVisible(True) 126 certificate.expiryDate()):
122 else: 127 self.expiredLabel.setVisible(True)
123 self.blacklistedLabel.setVisible(True) 128 else:
129 self.blacklistedLabel.setVisible(True)
124 130
125 def __certificateString(self, txt): 131 def __certificateString(self, txt):
126 """ 132 """
127 Private method to prepare some text for display. 133 Private method to prepare some text for display.
128 134

eric ide

mercurial