eric6/WebBrowser/Network/NetworkManager.py

branch
maintenance
changeset 7607
dd1054be15aa
parent 7362
028bf21bb5a2
parent 7570
a7a5750aded4
child 7737
5371a22cf2aa
equal deleted inserted replaced
7569:707442ffadc3 7607:dd1054be15aa
62 62
63 self.languagesChanged() 63 self.languagesChanged()
64 64
65 if SSL_AVAILABLE: 65 if SSL_AVAILABLE:
66 self.__sslErrorHandler = E5SslErrorHandler(self) 66 self.__sslErrorHandler = E5SslErrorHandler(self)
67 self.sslErrors.connect(self.__sslErrorHandler.sslErrorsReplySlot) 67 self.sslErrors.connect(self.__sslErrorHandlingSlot)
68 68
69 self.__temporarilyIgnoredSslErrors = {} 69 self.__temporarilyIgnoredSslErrors = {}
70 self.__permanentlyIgnoredSslErrors = {} 70 self.__permanentlyIgnoredSslErrors = {}
71 # dictionaries of permanently and temporarily ignored SSL errors 71 # dictionaries of permanently and temporarily ignored SSL errors
72
73 self.__insecureHosts = set()
72 74
73 self.__loaded = False 75 self.__loaded = False
74 self.__saveTimer = AutoSaver(self, self.__save) 76 self.__saveTimer = AutoSaver(self, self.__save)
75 77
76 self.changed.connect(self.__saveTimer.changeOccurred) 78 self.changed.connect(self.__saveTimer.changeOccurred)
173 @param view reference to a view to be used as parent for the dialog 175 @param view reference to a view to be used as parent for the dialog
174 @type QWidget 176 @type QWidget
175 @return flag indicating to ignore this error 177 @return flag indicating to ignore this error
176 @rtype bool 178 @rtype bool
177 """ 179 """
180 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"):
181 return False
182
178 self.__load() 183 self.__load()
179 184
180 host = error.url().host() 185 host = error.url().host()
186
187 self.__insecureHosts.add(host)
181 188
182 if ( 189 if (
183 host in self.__temporarilyIgnoredSslErrors and 190 host in self.__temporarilyIgnoredSslErrors and
184 error.error() in self.__temporarilyIgnoredSslErrors[host] 191 error.error() in self.__temporarilyIgnoredSslErrors[host]
185 ): 192 ):
194 title = self.tr("SSL Certificate Error") 201 title = self.tr("SSL Certificate Error")
195 msgBox = E5MessageBox.E5MessageBox( 202 msgBox = E5MessageBox.E5MessageBox(
196 E5MessageBox.Warning, 203 E5MessageBox.Warning,
197 title, 204 title,
198 self.tr("""<b>{0}</b>""" 205 self.tr("""<b>{0}</b>"""
199 """<p>The page you are trying to access has errors""" 206 """<p>The host <b>{1}</b> you are trying to access has"""
200 """ in the SSL certificate.</p>""" 207 """ errors in the SSL certificate.</p>"""
201 """<ul><li>{1}</li></ul>""" 208 """<ul><li>{2}</li></ul>"""
202 """<p>Would you like to make an exception?</p>""") 209 """<p>Would you like to make an exception?</p>""")
203 .format(title, error.errorDescription()), 210 .format(title, host, error.errorDescription()),
204 modal=True, parent=view) 211 modal=True, parent=view)
205 permButton = msgBox.addButton(self.tr("&Permanent accept"), 212 permButton = msgBox.addButton(self.tr("&Permanent accept"),
206 E5MessageBox.AcceptRole) 213 E5MessageBox.AcceptRole)
207 tempButton = msgBox.addButton(self.tr("&Temporary accept"), 214 tempButton = msgBox.addButton(self.tr("&Temporary accept"),
208 E5MessageBox.AcceptRole) 215 E5MessageBox.AcceptRole)
219 self.__temporarilyIgnoredSslErrors[host] = [] 226 self.__temporarilyIgnoredSslErrors[host] = []
220 self.__temporarilyIgnoredSslErrors[host].append(error.error()) 227 self.__temporarilyIgnoredSslErrors[host].append(error.error())
221 return True 228 return True
222 else: 229 else:
223 return False 230 return False
231
232 def __sslErrorHandlingSlot(self, reply, errors):
233 """
234 Private slot to handle SSL errors for a network reply.
235
236 @param reply reference to the reply object
237 @type QNetworkReply
238 @param errors list of SSL errors
239 @type list of QSslError
240 """
241 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"):
242 return
243
244 self.__load()
245
246 host = reply.url().host()
247 if (
248 host in self.__permanentlyIgnoredSslErrors or
249 host in self.__temporarilyIgnoredSslErrors
250 ):
251 reply.ignoreSslErrors()
252 else:
253 self.__sslErrorHandler.sslErrorsReply(reply, errors)
254
255 def isInsecureHost(self, host):
256 """
257 Public method to check a host against the list of insecure hosts.
258
259 @param host name of the host to be checked
260 @type str
261 @return flag indicating an insecure host
262 @rtype bool
263 """
264 return host in self.__insecureHosts
224 265
225 def authentication(self, url, auth, page=None): 266 def authentication(self, url, auth, page=None):
226 """ 267 """
227 Public slot to handle an authentication request. 268 Public slot to handle an authentication request.
228 269

eric ide

mercurial