28 @param parent reference to the parent widget (QWidget) |
24 @param parent reference to the parent widget (QWidget) |
29 """ |
25 """ |
30 super().__init__(parent) |
26 super().__init__(parent) |
31 self.setupUi(self) |
27 self.setupUi(self) |
32 |
28 |
33 self.blacklistedLabel.setVisible(False) |
29 self.sslWidget.showCertificate(certificate) |
34 self.blacklistedLabel.setStyleSheet( |
|
35 "QLabel { color : white; background-color : red; }") |
|
36 self.expiredLabel.setVisible(False) |
|
37 self.expiredLabel.setStyleSheet( |
|
38 "QLabel { color : white; background-color : red; }") |
|
39 |
|
40 self.subjectCommonNameLabel.setText(self.__certificateString( |
|
41 certificate.subjectInfo(QSslCertificate.CommonName))) |
|
42 self.subjectOrganizationLabel.setText(self.__certificateString( |
|
43 certificate.subjectInfo(QSslCertificate.Organization))) |
|
44 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( |
|
45 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName))) |
|
46 self.serialNumberLabel.setText(self.__serialNumber(certificate)) |
|
47 self.issuerCommonNameLabel.setText(self.__certificateString( |
|
48 certificate.issuerInfo(QSslCertificate.CommonName))) |
|
49 self.issuerOrganizationLabel.setText(self.__certificateString( |
|
50 certificate.issuerInfo(QSslCertificate.Organization))) |
|
51 self.issuerOrganizationalUnitLabel.setText(self.__certificateString( |
|
52 certificate.issuerInfo(QSslCertificate.OrganizationalUnitName))) |
|
53 self.effectiveLabel.setText(Qt.escape( |
|
54 certificate.effectiveDate().toString("yyyy-MM-dd"))) |
|
55 self.expiresLabel.setText(Qt.escape( |
|
56 certificate.expiryDate().toString("yyyy-MM-dd"))) |
|
57 self.sha1Label.setText(self.__formatHexString( |
|
58 str(certificate.digest(QCryptographicHash.Sha1).toHex(), encoding="ascii"))) |
|
59 self.md5Label.setText(self.__formatHexString( |
|
60 str(certificate.digest(QCryptographicHash.Md5).toHex(), encoding="ascii"))) |
|
61 |
|
62 if not certificate.isValid(): |
|
63 # something is wrong; indicate it to the user |
|
64 if self.__hasExpired(certificate.effectiveDate(), certificate.expiryDate()): |
|
65 self.expiredLabel.setVisible(True) |
|
66 else: |
|
67 self.blacklistedLabel.setVisible(True) |
|
68 |
|
69 def __certificateString(self, txt): |
|
70 """ |
|
71 Private method to prepare some text for display. |
|
72 |
|
73 @param txt text to be displayed (string) |
|
74 @return prepared text (string) |
|
75 """ |
|
76 if txt is None or txt == "": |
|
77 return self.trUtf8("<not part of the certificate>") |
|
78 |
|
79 return Qt.escape(Utilities.decodeString(txt)) |
|
80 |
|
81 def __serialNumber(self, cert): |
|
82 """ |
|
83 Private slot to format the certificate serial number. |
|
84 |
|
85 @param cert reference to the SSL certificate (QSslCertificate) |
|
86 @return formated serial number (string) |
|
87 """ |
|
88 serial = cert.serialNumber() |
|
89 if serial == "": |
|
90 return self.trUtf8("<not part of the certificate>") |
|
91 |
|
92 if ':' in serial: |
|
93 return str(serial, encoding="ascii").upper() |
|
94 else: |
|
95 hexString = hex(int(serial))[2:] |
|
96 return self.__formatHexString(hexString) |
|
97 |
|
98 def __formatHexString(self, hexString): |
|
99 """ |
|
100 Private method to format a hex string for display. |
|
101 |
|
102 @param hexString hex string to be formatted (string) |
|
103 @return formatted string (string) |
|
104 """ |
|
105 hexString = hexString.upper() |
|
106 |
|
107 if len(hexString) % 2 == 1: |
|
108 hexString = '0' + hexString |
|
109 |
|
110 hexList = [] |
|
111 while hexString: |
|
112 hexList.append(hexString[:2]) |
|
113 hexString = hexString[2:] |
|
114 |
|
115 return Qt.escape(':'.join(hexList)) |
|
116 |
|
117 def __hasExpired(self, effectiveDate, expiryDate): |
|
118 """ |
|
119 Private method to check for a certificate expiration. |
|
120 |
|
121 @param effectiveDate date the certificate becomes effective (QDateTime) |
|
122 @param expiryDate date the certificate expires (QDateTime) |
|
123 @return flag indicating the expiration status (boolean) |
|
124 """ |
|
125 now = QDateTime.currentDateTime() |
|
126 |
|
127 return now < effectiveDate or now >= expiryDate |
|