E5Network/E5SslCertificatesInfoWidget.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2677
3d4277929fb3
parent 2990
583beaf0b4b8
child 3145
a9de05d4a22f
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
39 39
40 def showCertificateChain(self, certificateChain): 40 def showCertificateChain(self, certificateChain):
41 """ 41 """
42 Public method to show the SSL certificates of a certificate chain. 42 Public method to show the SSL certificates of a certificate chain.
43 43
44 @param certificateChain list od SSL certificates (list of QSslCertificate) 44 @param certificateChain list od SSL certificates
45 (list of QSslCertificate)
45 """ 46 """
46 self.chainLabel.show() 47 self.chainLabel.show()
47 self.chainComboBox.show() 48 self.chainComboBox.show()
48 self.chainComboBox.clear() 49 self.chainComboBox.clear()
49 50
54 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName)) 55 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName))
55 else: 56 else:
56 name = cert.subjectInfo(QSslCertificate.CommonName) 57 name = cert.subjectInfo(QSslCertificate.CommonName)
57 if not name: 58 if not name:
58 if qVersion() >= "5.0.0": 59 if qVersion() >= "5.0.0":
59 name = ", ".join(cert.subjectInfo(QSslCertificate.Organization)) 60 name = ", ".join(
61 cert.subjectInfo(QSslCertificate.Organization))
60 else: 62 else:
61 name = cert.subjectInfo(QSslCertificate.Organization) 63 name = cert.subjectInfo(QSslCertificate.Organization)
62 if not name: 64 if not name:
63 name = cert.serialNumber() 65 name = cert.serialNumber()
64 self.chainComboBox.addItem(name) 66 self.chainComboBox.addItem(name)
92 self.expiredLabel.setStyleSheet( 94 self.expiredLabel.setStyleSheet(
93 "QLabel { color : white; background-color : red; }") 95 "QLabel { color : white; background-color : red; }")
94 96
95 if qVersion() >= "5.0.0": 97 if qVersion() >= "5.0.0":
96 self.subjectCommonNameLabel.setText(self.__certificateString( 98 self.subjectCommonNameLabel.setText(self.__certificateString(
97 ", ".join(certificate.subjectInfo(QSslCertificate.CommonName)))) 99 ", ".join(certificate.subjectInfo(
100 QSslCertificate.CommonName))))
98 self.subjectOrganizationLabel.setText(self.__certificateString( 101 self.subjectOrganizationLabel.setText(self.__certificateString(
99 ", ".join(certificate.subjectInfo(QSslCertificate.Organization)))) 102 ", ".join(certificate.subjectInfo(
100 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( 103 QSslCertificate.Organization))))
101 ", ".join( 104 self.subjectOrganizationalUnitLabel.setText(
102 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName)))) 105 self.__certificateString(", ".join(
106 certificate.subjectInfo(
107 QSslCertificate.OrganizationalUnitName))))
103 self.issuerCommonNameLabel.setText(self.__certificateString( 108 self.issuerCommonNameLabel.setText(self.__certificateString(
104 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName)))) 109 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
105 self.issuerOrganizationLabel.setText(self.__certificateString( 110 self.issuerOrganizationLabel.setText(self.__certificateString(
106 ", ".join(certificate.issuerInfo(QSslCertificate.Organization)))) 111 ", ".join(certificate.issuerInfo(
107 self.issuerOrganizationalUnitLabel.setText(self.__certificateString( 112 QSslCertificate.Organization))))
108 ", ".join(certificate.issuerInfo(QSslCertificate.OrganizationalUnitName)))) 113 self.issuerOrganizationalUnitLabel.setText(
114 self.__certificateString(", ".join(
115 certificate.issuerInfo(
116 QSslCertificate.OrganizationalUnitName))))
109 else: 117 else:
110 self.subjectCommonNameLabel.setText(self.__certificateString( 118 self.subjectCommonNameLabel.setText(self.__certificateString(
111 certificate.subjectInfo(QSslCertificate.CommonName))) 119 certificate.subjectInfo(QSslCertificate.CommonName)))
112 self.subjectOrganizationLabel.setText(self.__certificateString( 120 self.subjectOrganizationLabel.setText(self.__certificateString(
113 certificate.subjectInfo(QSslCertificate.Organization))) 121 certificate.subjectInfo(QSslCertificate.Organization)))
114 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( 122 self.subjectOrganizationalUnitLabel.setText(
115 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName))) 123 self.__certificateString(certificate.subjectInfo(
124 QSslCertificate.OrganizationalUnitName)))
116 self.issuerCommonNameLabel.setText(self.__certificateString( 125 self.issuerCommonNameLabel.setText(self.__certificateString(
117 certificate.issuerInfo(QSslCertificate.CommonName))) 126 certificate.issuerInfo(QSslCertificate.CommonName)))
118 self.issuerOrganizationLabel.setText(self.__certificateString( 127 self.issuerOrganizationLabel.setText(self.__certificateString(
119 certificate.issuerInfo(QSslCertificate.Organization))) 128 certificate.issuerInfo(QSslCertificate.Organization)))
120 self.issuerOrganizationalUnitLabel.setText(self.__certificateString( 129 self.issuerOrganizationalUnitLabel.setText(
121 certificate.issuerInfo(QSslCertificate.OrganizationalUnitName))) 130 self.__certificateString(certificate.issuerInfo(
131 QSslCertificate.OrganizationalUnitName)))
122 self.serialNumberLabel.setText(self.__serialNumber(certificate)) 132 self.serialNumberLabel.setText(self.__serialNumber(certificate))
123 self.effectiveLabel.setText( 133 self.effectiveLabel.setText(
124 certificate.effectiveDate().toString("yyyy-MM-dd")) 134 certificate.effectiveDate().toString("yyyy-MM-dd"))
125 self.expiresLabel.setText( 135 self.expiresLabel.setText(
126 certificate.expiryDate().toString("yyyy-MM-dd")) 136 certificate.expiryDate().toString("yyyy-MM-dd"))
127 self.sha1Label.setText(self.__formatHexString( 137 self.sha1Label.setText(self.__formatHexString(
128 str(certificate.digest(QCryptographicHash.Sha1).toHex(), encoding="ascii"))) 138 str(certificate.digest(QCryptographicHash.Sha1).toHex(),
139 encoding="ascii")))
129 self.md5Label.setText(self.__formatHexString( 140 self.md5Label.setText(self.__formatHexString(
130 str(certificate.digest(QCryptographicHash.Md5).toHex(), encoding="ascii"))) 141 str(certificate.digest(QCryptographicHash.Md5).toHex(),
142 encoding="ascii")))
131 143
132 if (qVersion() >= "5.0.0" and certificate.isBlacklisted()) or \ 144 if (qVersion() >= "5.0.0" and certificate.isBlacklisted()) or \
133 (qVersion() < "5.0.0" and not certificate.isValid()): 145 (qVersion() < "5.0.0" and not certificate.isValid()):
134 # something is wrong; indicate it to the user 146 # something is wrong; indicate it to the user
135 if self.__hasExpired(certificate.effectiveDate(), certificate.expiryDate()): 147 if self.__hasExpired(certificate.effectiveDate(),
148 certificate.expiryDate()):
136 self.expiredLabel.setVisible(True) 149 self.expiredLabel.setVisible(True)
137 else: 150 else:
138 self.blacklistedLabel.setVisible(True) 151 self.blacklistedLabel.setVisible(True)
139 152
140 def __certificateString(self, txt): 153 def __certificateString(self, txt):
200 @pyqtSlot(int) 213 @pyqtSlot(int)
201 def on_chainComboBox_activated(self, index): 214 def on_chainComboBox_activated(self, index):
202 """ 215 """
203 Private slot to show the certificate info for the selected entry. 216 Private slot to show the certificate info for the selected entry.
204 217
205 @param index number of the certificate in the certificate chain (integer) 218 @param index number of the certificate in the certificate chain
219 (integer)
206 """ 220 """
207 self.__showCertificate(self.__chain[index]) 221 self.__showCertificate(self.__chain[index])

eric ide

mercurial