E5Network/E5SslErrorHandler.py

changeset 2360
b6bf3925e3e1
parent 2354
c63de4af553d
child 2525
8b507a9a2d40
child 2990
583beaf0b4b8
equal deleted inserted replaced
2359:ef81d2d0a031 2360:b6bf3925e3e1
22 Class implementing a handler for SSL errors. 22 Class implementing a handler for SSL errors.
23 23
24 It also initializes the default SSL configuration with certificates 24 It also initializes the default SSL configuration with certificates
25 permanently accepted by the user already. 25 permanently accepted by the user already.
26 """ 26 """
27 NotIgnored = 0
28 SystemIgnored = 1
29 UserIgnored = 2
30
27 def __init__(self, parent=None): 31 def __init__(self, parent=None):
28 """ 32 """
29 Constructor 33 Constructor
30 34
31 @param parent reference to the parent object (QObject) 35 @param parent reference to the parent object (QObject)
69 """ 73 """
70 Public slot to handle SSL errors for a network reply. 74 Public slot to handle SSL errors for a network reply.
71 75
72 @param reply reference to the reply object (QNetworkReply) 76 @param reply reference to the reply object (QNetworkReply)
73 @param errors list of SSL errors (list of QSslError) 77 @param errors list of SSL errors (list of QSslError)
74 @return tuple of two flags indicating to ignore the SSL errors (boolean) 78 @return tuple indicating to ignore the SSL errors (one of NotIgnored,
75 and indicating a change of the default SSL configuration (boolean) 79 SystemIgnored or UserIgnored) and indicating a change of the default
80 SSL configuration (boolean)
76 """ 81 """
77 url = reply.url() 82 url = reply.url()
78 ignore, defaultChanged = self.sslErrors(errors, url.host(), url.port()) 83 ignore, defaultChanged = self.sslErrors(errors, url.host(), url.port())
79 if ignore: 84 if ignore:
80 if defaultChanged: 85 if defaultChanged:
90 Public method to handle SSL errors. 95 Public method to handle SSL errors.
91 96
92 @param errors list of SSL errors (list of QSslError) 97 @param errors list of SSL errors (list of QSslError)
93 @param server name of the server (string) 98 @param server name of the server (string)
94 @keyparam port value of the port (integer) 99 @keyparam port value of the port (integer)
95 @return tuple of two flags indicating to ignore the SSL errors (boolean) 100 @return tuple indicating to ignore the SSL errors (one of NotIgnored,
96 and indicating a change of the default SSL configuration (boolean) 101 SystemIgnored or UserIgnored) and indicating a change of the default
102 SSL configuration (boolean)
97 """ 103 """
98 caMerge = {} 104 caMerge = {}
99 certificateDict = Preferences.toDict( 105 certificateDict = Preferences.toDict(
100 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict")) 106 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
101 for caServer in certificateDict: 107 for caServer in certificateDict:
115 if not err.certificate().isNull(): 121 if not err.certificate().isNull():
116 cert = err.certificate() 122 cert = err.certificate()
117 if cert not in caNew: 123 if cert not in caNew:
118 caNew.append(cert) 124 caNew.append(cert)
119 if not errorStrings: 125 if not errorStrings:
120 return True, False 126 return E5SslErrorHandler.SystemIgnored, False
121 127
122 errorString = '.</li><li>'.join(errorStrings) 128 errorString = '.</li><li>'.join(errorStrings)
123 ret = E5MessageBox.yesNo(None, 129 ret = E5MessageBox.yesNo(None,
124 self.trUtf8("SSL Errors"), 130 self.trUtf8("SSL Errors"),
125 self.trUtf8("""<p>SSL Errors for <br /><b>{0}</b>""" 131 self.trUtf8("""<p>SSL Errors for <br /><b>{0}</b>"""
160 pems.append(cert.toPem() + '\n') 166 pems.append(cert.toPem() + '\n')
161 certificateDict[server] = pems 167 certificateDict[server] = pems
162 Preferences.Prefs.settings.setValue("Ssl/CaCertificatesDict", 168 Preferences.Prefs.settings.setValue("Ssl/CaCertificatesDict",
163 certificateDict) 169 certificateDict)
164 170
165 return True, caRet 171 return E5SslErrorHandler.UserIgnored, caRet
166 172
167 else: 173 else:
168 return False, False 174 return E5SslErrorHandler.NotIgnored, False
169 175
170 def __certToString(self, cert): 176 def __certToString(self, cert):
171 """ 177 """
172 Private method to convert a certificate to a formatted string. 178 Private method to convert a certificate to a formatted string.
173 179

eric ide

mercurial