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