13 from PyQt5.QtWidgets import QMenu, QGridLayout, QLabel, QSizePolicy |
13 from PyQt5.QtWidgets import QMenu, QGridLayout, QLabel, QSizePolicy |
14 from PyQt5.QtNetwork import QSsl, QSslConfiguration, QSslCertificate |
14 from PyQt5.QtNetwork import QSsl, QSslConfiguration, QSslCertificate |
15 |
15 |
16 import UI.PixmapCache |
16 import UI.PixmapCache |
17 import Utilities |
17 import Utilities |
18 from Globals import qVersionTuple |
|
19 |
18 |
20 |
19 |
21 class E5SslInfoWidget(QMenu): |
20 class E5SslInfoWidget(QMenu): |
22 """ |
21 """ |
23 Class implementing a widget to show SSL certificate infos. |
22 Class implementing a widget to show SSL certificate infos. |
67 if cert.isNull(): |
66 if cert.isNull(): |
68 label.setText(self.tr( |
67 label.setText(self.tr( |
69 "Warning: this site is NOT carrying a certificate.")) |
68 "Warning: this site is NOT carrying a certificate.")) |
70 imageLabel.setPixmap(UI.PixmapCache.getPixmap("securityLow32.png")) |
69 imageLabel.setPixmap(UI.PixmapCache.getPixmap("securityLow32.png")) |
71 else: |
70 else: |
72 if qVersionTuple() >= (5, 0, 0): |
71 valid = not cert.isBlacklisted() |
73 valid = not cert.isBlacklisted() |
|
74 else: |
|
75 valid = cert.isValid() |
|
76 if valid: |
72 if valid: |
77 if qVersionTuple() >= (5, 0, 0): |
73 txt = ", ".join( |
78 txt = ", ".join( |
74 cert.issuerInfo(QSslCertificate.CommonName)) |
79 cert.issuerInfo(QSslCertificate.CommonName)) |
|
80 else: |
|
81 txt = cert.issuerInfo(QSslCertificate.CommonName) |
|
82 label.setText(self.tr( |
75 label.setText(self.tr( |
83 "The certificate for this site is valid" |
76 "The certificate for this site is valid" |
84 " and has been verified by:\n{0}").format( |
77 " and has been verified by:\n{0}").format( |
85 Utilities.decodeString(txt))) |
78 Utilities.decodeString(txt))) |
86 imageLabel.setPixmap( |
79 imageLabel.setPixmap( |
150 UI.PixmapCache.getPixmap("securityLow32.png")) |
143 UI.PixmapCache.getPixmap("securityLow32.png")) |
151 else: |
144 else: |
152 sslVersion = self.tr("unknown") |
145 sslVersion = self.tr("unknown") |
153 imageLabel.setPixmap( |
146 imageLabel.setPixmap( |
154 UI.PixmapCache.getPixmap("securityLow32.png")) |
147 UI.PixmapCache.getPixmap("securityLow32.png")) |
155 if qVersionTuple() >= (5, 0, 0): |
148 if proto == QSsl.TlsV1_0: |
156 if proto == QSsl.TlsV1_0: |
149 sslVersion = "TLS 1.0" |
157 sslVersion = "TLS 1.0" |
150 imageLabel.setPixmap( |
158 imageLabel.setPixmap( |
151 UI.PixmapCache.getPixmap("securityHigh32.png")) |
159 UI.PixmapCache.getPixmap("securityHigh32.png")) |
152 elif proto == QSsl.TlsV1_1: |
160 elif proto == QSsl.TlsV1_1: |
153 sslVersion = "TLS 1.1" |
161 sslVersion = "TLS 1.1" |
154 imageLabel.setPixmap( |
162 imageLabel.setPixmap( |
155 UI.PixmapCache.getPixmap("securityHigh32.png")) |
163 UI.PixmapCache.getPixmap("securityHigh32.png")) |
156 elif proto == QSsl.TlsV1_2: |
164 elif proto == QSsl.TlsV1_2: |
157 sslVersion = "TLS 1.2" |
|
158 imageLabel.setPixmap( |
|
159 UI.PixmapCache.getPixmap("securityHigh32.png")) |
|
160 try: |
|
161 # Qt 5.12 and newer |
|
162 if proto == QSsl.TlsV1_2: |
165 sslVersion = "TLS 1.2" |
163 sslVersion = "TLS 1.2" |
166 imageLabel.setPixmap( |
164 imageLabel.setPixmap( |
167 UI.PixmapCache.getPixmap("securityHigh32.png")) |
165 UI.PixmapCache.getPixmap("securityHigh32.png")) |
168 else: |
166 except AttributeError: |
169 if proto == QSsl.TlsV1: |
167 pass |
170 sslVersion = "TLS 1.0" |
|
171 imageLabel.setPixmap( |
|
172 UI.PixmapCache.getPixmap("securityHigh32.png")) |
|
173 rows += 1 |
168 rows += 1 |
174 |
169 |
175 label = QLabel(self) |
170 label = QLabel(self) |
176 label.setWordWrap(True) |
171 label.setWordWrap(True) |
177 label.setText(self.tr( |
172 label.setText(self.tr( |