40 |
40 |
41 caList = self.__getSystemCaCertificates() |
41 caList = self.__getSystemCaCertificates() |
42 if Preferences.Prefs.settings.contains("Help/CaCertificatesDict"): |
42 if Preferences.Prefs.settings.contains("Help/CaCertificatesDict"): |
43 # port old entries stored under 'Help' |
43 # port old entries stored under 'Help' |
44 certificateDict = Preferences.toDict( |
44 certificateDict = Preferences.toDict( |
45 Preferences.Prefs.settings.value("Help/CaCertificatesDict")) |
45 Preferences.Prefs.settings.value("Help/CaCertificatesDict")) |
46 Preferences.Prefs.settings.setValue("Ssl/CaCertificatesDict", |
46 Preferences.Prefs.settings.setValue("Ssl/CaCertificatesDict", |
47 certificateDict) |
47 certificateDict) |
48 Preferences.Prefs.settings.remove("Help/CaCertificatesDict") |
48 Preferences.Prefs.settings.remove("Help/CaCertificatesDict") |
49 else: |
49 else: |
50 certificateDict = Preferences.toDict( |
50 certificateDict = Preferences.toDict( |
76 Public slot to handle SSL errors for a network reply. |
76 Public slot to handle SSL errors for a network reply. |
77 |
77 |
78 @param reply reference to the reply object (QNetworkReply) |
78 @param reply reference to the reply object (QNetworkReply) |
79 @param errors list of SSL errors (list of QSslError) |
79 @param errors list of SSL errors (list of QSslError) |
80 @return tuple indicating to ignore the SSL errors (one of NotIgnored, |
80 @return tuple indicating to ignore the SSL errors (one of NotIgnored, |
81 SystemIgnored or UserIgnored) and indicating a change of the default |
81 SystemIgnored or UserIgnored) and indicating a change of the |
82 SSL configuration (boolean) |
82 default SSL configuration (boolean) |
83 """ |
83 """ |
84 url = reply.url() |
84 url = reply.url() |
85 ignore, defaultChanged = self.sslErrors(errors, url.host(), url.port()) |
85 ignore, defaultChanged = self.sslErrors(errors, url.host(), url.port()) |
86 if ignore: |
86 if ignore: |
87 if defaultChanged: |
87 if defaultChanged: |
88 reply.setSslConfiguration(QSslConfiguration.defaultConfiguration()) |
88 reply.setSslConfiguration( |
|
89 QSslConfiguration.defaultConfiguration()) |
89 reply.ignoreSslErrors() |
90 reply.ignoreSslErrors() |
90 else: |
91 else: |
91 reply.abort() |
92 reply.abort() |
92 |
93 |
93 return ignore, defaultChanged |
94 return ignore, defaultChanged |
98 |
99 |
99 @param errors list of SSL errors (list of QSslError) |
100 @param errors list of SSL errors (list of QSslError) |
100 @param server name of the server (string) |
101 @param server name of the server (string) |
101 @keyparam port value of the port (integer) |
102 @keyparam port value of the port (integer) |
102 @return tuple indicating to ignore the SSL errors (one of NotIgnored, |
103 @return tuple indicating to ignore the SSL errors (one of NotIgnored, |
103 SystemIgnored or UserIgnored) and indicating a change of the default |
104 SystemIgnored or UserIgnored) and indicating a change of the |
104 SSL configuration (boolean) |
105 default SSL configuration (boolean) |
105 """ |
106 """ |
106 caMerge = {} |
107 caMerge = {} |
107 certificateDict = Preferences.toDict( |
108 certificateDict = Preferences.toDict( |
108 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict")) |
109 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict")) |
109 for caServer in certificateDict: |
110 for caServer in certificateDict: |
110 caMerge[caServer] = QSslCertificate.fromData(certificateDict[caServer]) |
111 caMerge[caServer] = QSslCertificate.fromData( |
|
112 certificateDict[caServer]) |
111 caNew = [] |
113 caNew = [] |
112 |
114 |
113 errorStrings = [] |
115 errorStrings = [] |
114 if port != -1: |
116 if port != -1: |
115 server += ":{0:d}".format(port) |
117 server += ":{0:d}".format(port) |
142 certinfos = [] |
144 certinfos = [] |
143 for cert in caNew: |
145 for cert in caNew: |
144 certinfos.append(self.__certToString(cert)) |
146 certinfos.append(self.__certToString(cert)) |
145 caRet = E5MessageBox.yesNo(None, |
147 caRet = E5MessageBox.yesNo(None, |
146 self.trUtf8("Certificates"), |
148 self.trUtf8("Certificates"), |
147 self.trUtf8("""<p>Certificates:<br/>{0}<br/>""" |
149 self.trUtf8( |
148 """Do you want to accept all these certificates?</p>""")\ |
150 """<p>Certificates:<br/>{0}<br/>""" |
|
151 """Do you want to accept all these certificates?""" |
|
152 """</p>""")\ |
149 .format("".join(certinfos))) |
153 .format("".join(certinfos))) |
150 if caRet: |
154 if caRet: |
151 if server not in caMerge: |
155 if server not in caMerge: |
152 caMerge[server] = [] |
156 caMerge[server] = [] |
153 for cert in caNew: |
157 for cert in caNew: |
165 for server in caMerge: |
169 for server in caMerge: |
166 pems = QByteArray() |
170 pems = QByteArray() |
167 for cert in caMerge[server]: |
171 for cert in caMerge[server]: |
168 pems.append(cert.toPem() + '\n') |
172 pems.append(cert.toPem() + '\n') |
169 certificateDict[server] = pems |
173 certificateDict[server] = pems |
170 Preferences.Prefs.settings.setValue("Ssl/CaCertificatesDict", |
174 Preferences.Prefs.settings.setValue( |
|
175 "Ssl/CaCertificatesDict", |
171 certificateDict) |
176 certificateDict) |
172 |
177 |
173 return E5SslErrorHandler.UserIgnored, caRet |
178 return E5SslErrorHandler.UserIgnored, caRet |
174 |
179 |
175 else: |
180 else: |
189 .format(Utilities.html_encode(Utilities.decodeString( |
194 .format(Utilities.html_encode(Utilities.decodeString( |
190 ", ".join(cert.subjectInfo(QSslCertificate.CommonName))))) |
195 ", ".join(cert.subjectInfo(QSslCertificate.CommonName))))) |
191 |
196 |
192 result += self.trUtf8("<br/>Organization: {0}")\ |
197 result += self.trUtf8("<br/>Organization: {0}")\ |
193 .format(Utilities.html_encode(Utilities.decodeString( |
198 .format(Utilities.html_encode(Utilities.decodeString( |
194 ", ".join(cert.subjectInfo(QSslCertificate.Organization))))) |
199 ", ".join(cert.subjectInfo( |
|
200 QSslCertificate.Organization))))) |
195 |
201 |
196 result += self.trUtf8("<br/>Issuer: {0}")\ |
202 result += self.trUtf8("<br/>Issuer: {0}")\ |
197 .format(Utilities.html_encode(Utilities.decodeString( |
203 .format(Utilities.html_encode(Utilities.decodeString( |
198 ", ".join(cert.issuerInfo(QSslCertificate.CommonName))))) |
204 ", ".join(cert.issuerInfo(QSslCertificate.CommonName))))) |
199 else: |
205 else: |
207 |
213 |
208 result += self.trUtf8("<br/>Issuer: {0}")\ |
214 result += self.trUtf8("<br/>Issuer: {0}")\ |
209 .format(Utilities.html_encode(Utilities.decodeString( |
215 .format(Utilities.html_encode(Utilities.decodeString( |
210 cert.issuerInfo(QSslCertificate.CommonName)))) |
216 cert.issuerInfo(QSslCertificate.CommonName)))) |
211 |
217 |
212 result += self.trUtf8("<br/>Not valid before: {0}<br/>Valid Until: {1}")\ |
218 result += self.trUtf8( |
213 .format(Utilities.html_encode(cert.effectiveDate().toString("yyyy-MM-dd")), |
219 "<br/>Not valid before: {0}<br/>Valid Until: {1}")\ |
214 Utilities.html_encode(cert.expiryDate().toString("yyyy-MM-dd"))) |
220 .format(Utilities.html_encode( |
|
221 cert.effectiveDate().toString("yyyy-MM-dd")), |
|
222 Utilities.html_encode( |
|
223 cert.expiryDate().toString("yyyy-MM-dd"))) |
215 |
224 |
216 result += "</p>" |
225 result += "</p>" |
217 |
226 |
218 return result |
227 return result |
219 |
228 |