5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show SSL certificate infos. |
7 Module implementing a dialog to show SSL certificate infos. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import QCryptographicHash |
10 from PyQt4.QtCore import QCryptographicHash, QDateTime |
11 from PyQt4.QtGui import QDialog |
11 from PyQt4.QtGui import QDialog |
12 from PyQt4.QtNetwork import QSslCertificate |
12 from PyQt4.QtNetwork import QSslCertificate |
13 |
13 |
14 from .Ui_SslInfoDialog import Ui_SslInfoDialog |
14 from .Ui_SslInfoDialog import Ui_SslInfoDialog |
15 |
15 |
28 @param parent reference to the parent widget (QWidget) |
28 @param parent reference to the parent widget (QWidget) |
29 """ |
29 """ |
30 super().__init__(parent) |
30 super().__init__(parent) |
31 self.setupUi(self) |
31 self.setupUi(self) |
32 |
32 |
|
33 self.blacklistedLabel.setVisible(False) |
|
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 |
33 self.subjectCommonNameLabel.setText(self.__certificateString( |
40 self.subjectCommonNameLabel.setText(self.__certificateString( |
34 certificate.subjectInfo(QSslCertificate.CommonName))) |
41 certificate.subjectInfo(QSslCertificate.CommonName))) |
35 self.subjectOrganizationLabel.setText(self.__certificateString( |
42 self.subjectOrganizationLabel.setText(self.__certificateString( |
36 certificate.subjectInfo(QSslCertificate.Organization))) |
43 certificate.subjectInfo(QSslCertificate.Organization))) |
37 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( |
44 self.subjectOrganizationalUnitLabel.setText(self.__certificateString( |
47 self.expiresLabel.setText(certificate.expiryDate().toString("yyyy-MM-dd")) |
54 self.expiresLabel.setText(certificate.expiryDate().toString("yyyy-MM-dd")) |
48 self.sha1Label.setText(self.__formatHexString( |
55 self.sha1Label.setText(self.__formatHexString( |
49 str(certificate.digest(QCryptographicHash.Sha1).toHex(), encoding="ascii"))) |
56 str(certificate.digest(QCryptographicHash.Sha1).toHex(), encoding="ascii"))) |
50 self.md5Label.setText(self.__formatHexString( |
57 self.md5Label.setText(self.__formatHexString( |
51 str(certificate.digest(QCryptographicHash.Md5).toHex(), encoding="ascii"))) |
58 str(certificate.digest(QCryptographicHash.Md5).toHex(), encoding="ascii"))) |
|
59 |
|
60 if not certificate.isValid(): |
|
61 # something is wrong; indicate it to the user |
|
62 if self.__hasExpired(certificate.effectiveDate(), certificate.expiryDate()): |
|
63 self.expiredLabel.setVisible(True) |
|
64 else: |
|
65 self.blacklistedLabel.setVisible(True) |
52 |
66 |
53 def __certificateString(self, txt): |
67 def __certificateString(self, txt): |
54 """ |
68 """ |
55 Private method to prepare some text for display. |
69 Private method to prepare some text for display. |
56 |
70 |
76 if ':' in serial: |
90 if ':' in serial: |
77 return str(serial, encoding="ascii").upper() |
91 return str(serial, encoding="ascii").upper() |
78 else: |
92 else: |
79 hexString = hex(int(serial))[2:] |
93 hexString = hex(int(serial))[2:] |
80 return self.__formatHexString(hexString) |
94 return self.__formatHexString(hexString) |
81 |
95 |
82 def __formatHexString(self, hexString): |
96 def __formatHexString(self, hexString): |
83 """ |
97 """ |
84 Private method to format a hex string for display. |
98 Private method to format a hex string for display. |
85 |
99 |
86 @param hexString hex string to be formatted (string) |
100 @param hexString hex string to be formatted (string) |
95 while hexString: |
109 while hexString: |
96 hexList.append(hexString[:2]) |
110 hexList.append(hexString[:2]) |
97 hexString = hexString[2:] |
111 hexString = hexString[2:] |
98 |
112 |
99 return ':'.join(hexList) |
113 return ':'.join(hexList) |
|
114 |
|
115 def __hasExpired(self, effectiveDate, expiryDate): |
|
116 """ |
|
117 Private method to check for a certificate expiration. |
|
118 |
|
119 @param effectiveDate date the certificate becomes effective (QDateTime) |
|
120 @param expiryDate date the certificate expires (QDateTime) |
|
121 @return flag indicating the expiration status (boolean) |
|
122 """ |
|
123 now = QDateTime.currentDateTime() |
|
124 |
|
125 return now < effectiveDate or now >= expiryDate |