src/eric7/WebBrowser/Network/SslErrorExceptionsDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to edit the SSL error exceptions.
8 """
9
10 from PyQt6.QtCore import pyqtSlot, Qt, QPoint
11 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem, QMenu
12 from PyQt6.QtWebEngineCore import QWebEngineCertificateError
13
14 from .Ui_SslErrorExceptionsDialog import Ui_SslErrorExceptionsDialog
15
16
17 class SslErrorExceptionsDialog(QDialog, Ui_SslErrorExceptionsDialog):
18 """
19 Class implementing a dialog to edit the SSL error exceptions.
20 """
21 def __init__(self, errorsDict, parent=None):
22 """
23 Constructor
24
25 @param errorsDict error exceptions
26 @type dict of list of int
27 @param parent reference to the parent widget
28 @type QWidget
29 """
30 super().__init__(parent)
31 self.setupUi(self)
32
33 self.__errorDescriptions = {
34 QWebEngineCertificateError.Type.SslPinnedKeyNotInCertificateChain:
35 self.tr("The certificate did not match the built-in public"
36 " keys pinned for the host name."),
37 QWebEngineCertificateError.Type.CertificateCommonNameInvalid:
38 self.tr("The certificate's common name did not match the"
39 " host name."),
40 QWebEngineCertificateError.Type.CertificateDateInvalid:
41 self.tr("The certificate is not valid at the current date"
42 " and time."),
43 QWebEngineCertificateError.Type.CertificateAuthorityInvalid:
44 self.tr("The certificate is not signed by a trusted"
45 " authority."),
46 QWebEngineCertificateError.Type.CertificateContainsErrors:
47 self.tr("The certificate contains errors."),
48 QWebEngineCertificateError.Type.CertificateNoRevocationMechanism:
49 self.tr("The certificate has no mechanism for determining if"
50 " it has been revoked."),
51 QWebEngineCertificateError.Type
52 .CertificateUnableToCheckRevocation:
53 self.tr("Revocation information for the certificate is"
54 " not available."),
55 QWebEngineCertificateError.Type.CertificateRevoked:
56 self.tr("The certificate has been revoked."),
57 QWebEngineCertificateError.Type.CertificateInvalid:
58 self.tr("The certificate is invalid."),
59 QWebEngineCertificateError.Type.CertificateWeakSignatureAlgorithm:
60 self.tr("The certificate is signed using a weak signature"
61 " algorithm."),
62 QWebEngineCertificateError.Type.CertificateNonUniqueName:
63 self.tr("The host name specified in the certificate is"
64 " not unique."),
65 QWebEngineCertificateError.Type.CertificateWeakKey:
66 self.tr("The certificate contains a weak key."),
67 QWebEngineCertificateError.Type
68 .CertificateNameConstraintViolation:
69 self.tr("The certificate claimed DNS names that are in"
70 " violation of name constraints."),
71 QWebEngineCertificateError.Type.CertificateValidityTooLong:
72 self.tr("The certificate has a validity period that is"
73 " too long."),
74 QWebEngineCertificateError.Type.CertificateTransparencyRequired:
75 self.tr("Certificate Transparency was required for this"
76 " connection, but the server did not provide"
77 " information that complied with the policy."),
78 QWebEngineCertificateError.Type
79 .CertificateKnownInterceptionBlocked:
80 self.tr("The certificate is known to be used for interception"
81 " by an entity other than the device owner."),
82 QWebEngineCertificateError.Type.SslObsoleteVersion:
83 self.tr("The connection uses an obsolete version of SSL/TLS."),
84 QWebEngineCertificateError.Type.CertificateSymantecLegacy:
85 self.tr("The certificate is a legacy Symantec one that's no"
86 " longer valid."),
87 }
88
89 for host, errors in errorsDict.items():
90 itm = QTreeWidgetItem(self.errorsTree, [host])
91 self.errorsTree.setFirstItemColumnSpanned(itm, True)
92 for error in errors:
93 try:
94 errorDesc = self.__errorDescriptions[error]
95 except KeyError:
96 errorDesc = self.tr("No error description available.")
97 QTreeWidgetItem(itm, [str(error), errorDesc])
98
99 self.errorsTree.expandAll()
100 for i in range(self.errorsTree.columnCount()):
101 self.errorsTree.resizeColumnToContents(i)
102 self.errorsTree.sortItems(0, Qt.SortOrder.AscendingOrder)
103
104 self.__setRemoveButtons()
105
106 def __setRemoveButtons(self):
107 """
108 Private method to set the state of the 'remove' buttons.
109 """
110 if self.errorsTree.topLevelItemCount() == 0:
111 self.removeButton.setEnabled(False)
112 self.removeAllButton.setEnabled(False)
113 else:
114 self.removeAllButton.setEnabled(True)
115 self.removeButton.setEnabled(
116 len(self.errorsTree.selectedItems()) > 0)
117
118 @pyqtSlot(QPoint)
119 def on_errorsTree_customContextMenuRequested(self, pos):
120 """
121 Private slot to show the context menu.
122
123 @param pos cursor position
124 @type QPoint
125 """
126 menu = QMenu()
127 menu.addAction(
128 self.tr("Remove Selected"),
129 self.on_removeButton_clicked).setEnabled(
130 self.errorsTree.topLevelItemCount() > 0 and
131 len(self.errorsTree.selectedItems()) > 0)
132 menu.addAction(
133 self.tr("Remove All"),
134 self.on_removeAllButton_clicked).setEnabled(
135 self.errorsTree.topLevelItemCount() > 0)
136
137 menu.exec(self.errorsTree.mapToGlobal(pos))
138
139 @pyqtSlot()
140 def on_errorsTree_itemSelectionChanged(self):
141 """
142 Private slot handling the selection of entries.
143 """
144 self.__setRemoveButtons()
145
146 @pyqtSlot()
147 def on_removeButton_clicked(self):
148 """
149 Private slot to remove the selected items.
150 """
151 for itm in self.errorsTree.selectedItems():
152 pitm = itm.parent()
153 if pitm:
154 pitm.removeChild(itm)
155 else:
156 index = self.errorsTree.indexOfTopLevelItem(itm)
157 self.errorsTree.takeTopLevelItem(index)
158 del itm
159
160 # remove all hosts without an exception
161 for index in range(self.errorsTree.topLevelItemCount() - 1, -1, -1):
162 itm = self.errorsTree.topLevelItem(index)
163 if itm.childCount() == 0:
164 self.errorsTree.takeTopLevelItem(index)
165 del itm
166
167 @pyqtSlot()
168 def on_removeAllButton_clicked(self):
169 """
170 Private slot to remove all entries.
171 """
172 self.errorsTree.clear()
173
174 def getSslErrorExceptions(self):
175 """
176 Public method to retrieve the list of SSL error exceptions.
177
178 @return error exceptions
179 @rtype dict of list of int
180 """
181 errors = {}
182
183 for index in range(self.errorsTree.topLevelItemCount()):
184 itm = self.errorsTree.topLevelItem(index)
185 host = itm.text(0)
186 errors[host] = []
187 for cindex in range(itm.childCount()):
188 citm = itm.child(cindex)
189 errors[host].append(int(citm.text(0)))
190
191 return errors

eric ide

mercurial