E5Network/E5SslCertificatesInfoWidget.py

changeset 2990
583beaf0b4b8
parent 2578
f181c1420148
child 3057
10516539f238
child 3160
209a07d7e401
equal deleted inserted replaced
2989:7efa8b8b6903 2990:583beaf0b4b8
33 33
34 def showCertificateChain(self, certificateChain): 34 def showCertificateChain(self, certificateChain):
35 """ 35 """
36 Public method to show the SSL certificates of a certificate chain. 36 Public method to show the SSL certificates of a certificate chain.
37 37
38 @param certificateChain list od SSL certificates (list of QSslCertificate) 38 @param certificateChain list od SSL certificates
39 (list of QSslCertificate)
39 """ 40 """
40 self.chainLabel.show() 41 self.chainLabel.show()
41 self.chainComboBox.show() 42 self.chainComboBox.show()
42 self.chainComboBox.clear() 43 self.chainComboBox.clear()
43 44
48 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName)) 49 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName))
49 else: 50 else:
50 name = cert.subjectInfo(QSslCertificate.CommonName) 51 name = cert.subjectInfo(QSslCertificate.CommonName)
51 if not name: 52 if not name:
52 if qVersion() >= "5.0.0": 53 if qVersion() >= "5.0.0":
53 name = ", ".join(cert.subjectInfo(QSslCertificate.Organization)) 54 name = ", ".join(
55 cert.subjectInfo(QSslCertificate.Organization))
54 else: 56 else:
55 name = cert.subjectInfo(QSslCertificate.Organization) 57 name = cert.subjectInfo(QSslCertificate.Organization)
56 if not name: 58 if not name:
57 name = cert.serialNumber() 59 name = cert.serialNumber()
58 self.chainComboBox.addItem(name) 60 self.chainComboBox.addItem(name)
86 self.expiredLabel.setStyleSheet( 88 self.expiredLabel.setStyleSheet(
87 "QLabel { color : white; background-color : red; }") 89 "QLabel { color : white; background-color : red; }")
88 90
89 if qVersion() >= "5.0.0": 91 if qVersion() >= "5.0.0":
90 self.subjectCommonNameLabel.setText(self.__certificateString( 92 self.subjectCommonNameLabel.setText(self.__certificateString(
91 ", ".join(certificate.subjectInfo(QSslCertificate.CommonName)))) 93 ", ".join(certificate.subjectInfo(
94 QSslCertificate.CommonName))))
92 self.subjectOrganizationLabel.setText(self.__certificateString( 95 self.subjectOrganizationLabel.setText(self.__certificateString(
93 ", ".join(certificate.subjectInfo(QSslCertificate.Organization)))) 96 ", ".join(certificate.subjectInfo(
94 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( 97 QSslCertificate.Organization))))
95 ", ".join( 98 self.subjectOrganizationalUnitLabel.setText(
96 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName)))) 99 self.__certificateString(", ".join(
100 certificate.subjectInfo(
101 QSslCertificate.OrganizationalUnitName))))
97 self.issuerCommonNameLabel.setText(self.__certificateString( 102 self.issuerCommonNameLabel.setText(self.__certificateString(
98 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName)))) 103 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
99 self.issuerOrganizationLabel.setText(self.__certificateString( 104 self.issuerOrganizationLabel.setText(self.__certificateString(
100 ", ".join(certificate.issuerInfo(QSslCertificate.Organization)))) 105 ", ".join(certificate.issuerInfo(
101 self.issuerOrganizationalUnitLabel.setText(self.__certificateString( 106 QSslCertificate.Organization))))
102 ", ".join(certificate.issuerInfo(QSslCertificate.OrganizationalUnitName)))) 107 self.issuerOrganizationalUnitLabel.setText(
108 self.__certificateString(", ".join(
109 certificate.issuerInfo(
110 QSslCertificate.OrganizationalUnitName))))
103 else: 111 else:
104 self.subjectCommonNameLabel.setText(self.__certificateString( 112 self.subjectCommonNameLabel.setText(self.__certificateString(
105 certificate.subjectInfo(QSslCertificate.CommonName))) 113 certificate.subjectInfo(QSslCertificate.CommonName)))
106 self.subjectOrganizationLabel.setText(self.__certificateString( 114 self.subjectOrganizationLabel.setText(self.__certificateString(
107 certificate.subjectInfo(QSslCertificate.Organization))) 115 certificate.subjectInfo(QSslCertificate.Organization)))
108 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( 116 self.subjectOrganizationalUnitLabel.setText(
109 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName))) 117 self.__certificateString(certificate.subjectInfo(
118 QSslCertificate.OrganizationalUnitName)))
110 self.issuerCommonNameLabel.setText(self.__certificateString( 119 self.issuerCommonNameLabel.setText(self.__certificateString(
111 certificate.issuerInfo(QSslCertificate.CommonName))) 120 certificate.issuerInfo(QSslCertificate.CommonName)))
112 self.issuerOrganizationLabel.setText(self.__certificateString( 121 self.issuerOrganizationLabel.setText(self.__certificateString(
113 certificate.issuerInfo(QSslCertificate.Organization))) 122 certificate.issuerInfo(QSslCertificate.Organization)))
114 self.issuerOrganizationalUnitLabel.setText(self.__certificateString( 123 self.issuerOrganizationalUnitLabel.setText(
115 certificate.issuerInfo(QSslCertificate.OrganizationalUnitName))) 124 self.__certificateString(certificate.issuerInfo(
125 QSslCertificate.OrganizationalUnitName)))
116 self.serialNumberLabel.setText(self.__serialNumber(certificate)) 126 self.serialNumberLabel.setText(self.__serialNumber(certificate))
117 self.effectiveLabel.setText( 127 self.effectiveLabel.setText(
118 certificate.effectiveDate().toString("yyyy-MM-dd")) 128 certificate.effectiveDate().toString("yyyy-MM-dd"))
119 self.expiresLabel.setText( 129 self.expiresLabel.setText(
120 certificate.expiryDate().toString("yyyy-MM-dd")) 130 certificate.expiryDate().toString("yyyy-MM-dd"))
121 self.sha1Label.setText(self.__formatHexString( 131 self.sha1Label.setText(self.__formatHexString(
122 str(certificate.digest(QCryptographicHash.Sha1).toHex(), encoding="ascii"))) 132 str(certificate.digest(QCryptographicHash.Sha1).toHex(),
133 encoding="ascii")))
123 self.md5Label.setText(self.__formatHexString( 134 self.md5Label.setText(self.__formatHexString(
124 str(certificate.digest(QCryptographicHash.Md5).toHex(), encoding="ascii"))) 135 str(certificate.digest(QCryptographicHash.Md5).toHex(),
136 encoding="ascii")))
125 137
126 if (qVersion() >= "5.0.0" and certificate.isBlacklisted()) or \ 138 if (qVersion() >= "5.0.0" and certificate.isBlacklisted()) or \
127 (qVersion() < "5.0.0" and not certificate.isValid()): 139 (qVersion() < "5.0.0" and not certificate.isValid()):
128 # something is wrong; indicate it to the user 140 # something is wrong; indicate it to the user
129 if self.__hasExpired(certificate.effectiveDate(), certificate.expiryDate()): 141 if self.__hasExpired(certificate.effectiveDate(),
142 certificate.expiryDate()):
130 self.expiredLabel.setVisible(True) 143 self.expiredLabel.setVisible(True)
131 else: 144 else:
132 self.blacklistedLabel.setVisible(True) 145 self.blacklistedLabel.setVisible(True)
133 146
134 def __certificateString(self, txt): 147 def __certificateString(self, txt):
194 @pyqtSlot(int) 207 @pyqtSlot(int)
195 def on_chainComboBox_activated(self, index): 208 def on_chainComboBox_activated(self, index):
196 """ 209 """
197 Private slot to show the certificate info for the selected entry. 210 Private slot to show the certificate info for the selected entry.
198 211
199 @param index number of the certificate in the certificate chain (integer) 212 @param index number of the certificate in the certificate chain
213 (integer)
200 """ 214 """
201 self.__showCertificate(self.__chain[index]) 215 self.__showCertificate(self.__chain[index])

eric ide

mercurial