24 pass |
24 pass |
25 |
25 |
26 import Preferences |
26 import Preferences |
27 import Utilities |
27 import Utilities |
28 |
28 |
|
29 |
29 class SslCertificatesDialog(QDialog, Ui_SslCertificatesDialog): |
30 class SslCertificatesDialog(QDialog, Ui_SslCertificatesDialog): |
30 """ |
31 """ |
31 Class implementing a dialog to show and edit all certificates. |
32 Class implementing a dialog to show and edit all certificates. |
32 """ |
33 """ |
33 CertRole = Qt.UserRole + 1 |
34 CertRole = Qt.UserRole + 1 |
34 |
35 |
35 def __init__(self, parent = None): |
36 def __init__(self, parent=None): |
36 """ |
37 """ |
37 Constructor |
38 Constructor |
38 |
39 |
39 @param parent reference to the parent widget (QWidget) |
40 @param parent reference to the parent widget (QWidget) |
40 """ |
41 """ |
75 if commonName is None or commonName == "": |
76 if commonName is None or commonName == "": |
76 commonName = self.trUtf8("(Unknown common name)") |
77 commonName = self.trUtf8("(Unknown common name)") |
77 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
78 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
78 |
79 |
79 # step 2: create the entry |
80 # step 2: create the entry |
80 items = self.serversCertificatesTree.findItems(organisation, |
81 items = self.serversCertificatesTree.findItems(organisation, |
81 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
82 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
82 if len(items) == 0: |
83 if len(items) == 0: |
83 parent = QTreeWidgetItem(self.serversCertificatesTree, [organisation]) |
84 parent = QTreeWidgetItem(self.serversCertificatesTree, [organisation]) |
84 else: |
85 else: |
85 parent = items[0] |
86 parent = items[0] |
147 for cert in certs: |
148 for cert in certs: |
148 pems.append(cert.toPem() + '\n') |
149 pems.append(cert.toPem() + '\n') |
149 certificateDict[server] = pems |
150 certificateDict[server] = pems |
150 else: |
151 else: |
151 del certificateDict[server] |
152 del certificateDict[server] |
152 Preferences.Prefs.settings.setValue("Help/CaCertificatesDict", |
153 Preferences.Prefs.settings.setValue("Help/CaCertificatesDict", |
153 certificateDict) |
154 certificateDict) |
154 |
155 |
155 # delete the certificate from the default certificates |
156 # delete the certificate from the default certificates |
156 self.__updateDefaultConfiguration() |
157 self.__updateDefaultConfiguration() |
157 |
158 |
182 else: |
183 else: |
183 pems.append(cert.toPem() + '\n') |
184 pems.append(cert.toPem() + '\n') |
184 if server not in certificateDict: |
185 if server not in certificateDict: |
185 certificateDict[server] = QByteArray() |
186 certificateDict[server] = QByteArray() |
186 certificateDict[server].append(pems) |
187 certificateDict[server].append(pems) |
187 Preferences.Prefs.settings.setValue("Help/CaCertificatesDict", |
188 Preferences.Prefs.settings.setValue("Help/CaCertificatesDict", |
188 certificateDict) |
189 certificateDict) |
189 |
190 |
190 self.serversCertificatesTree.clear() |
191 self.serversCertificatesTree.clear() |
191 self.__populateServerCertificatesTree() |
192 self.__populateServerCertificatesTree() |
192 |
193 |
257 if commonName is None or commonName == "": |
258 if commonName is None or commonName == "": |
258 commonName = self.trUtf8("(Unknown common name)") |
259 commonName = self.trUtf8("(Unknown common name)") |
259 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
260 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
260 |
261 |
261 # step 2: create the entry |
262 # step 2: create the entry |
262 items = self.caCertificatesTree.findItems(organisation, |
263 items = self.caCertificatesTree.findItems(organisation, |
263 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
264 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
264 if len(items) == 0: |
265 if len(items) == 0: |
265 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation]) |
266 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation]) |
266 else: |
267 else: |
267 parent = items[0] |
268 parent = items[0] |
270 itm.setData(0, self.CertRole, cert) |
271 itm.setData(0, self.CertRole, cert) |
271 |
272 |
272 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
273 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
273 def on_caCertificatesTree_currentItemChanged(self, current, previous): |
274 def on_caCertificatesTree_currentItemChanged(self, current, previous): |
274 """ |
275 """ |
275 Private slot handling a change of the current item |
276 Private slot handling a change of the current item |
276 in the CA certificates list. |
277 in the CA certificates list. |
277 |
278 |
278 @param current new current item (QTreeWidgetItem) |
279 @param current new current item (QTreeWidgetItem) |
279 @param previous previous current item (QTreeWidgetItem) |
280 @param previous previous current item (QTreeWidgetItem) |
280 """ |
281 """ |
392 if QFileInfo(fname).exists(): |
393 if QFileInfo(fname).exists(): |
393 res = E5MessageBox.yesNo(self, |
394 res = E5MessageBox.yesNo(self, |
394 self.trUtf8("Export Certificate"), |
395 self.trUtf8("Export Certificate"), |
395 self.trUtf8("<p>The file <b>{0}</b> already exists." |
396 self.trUtf8("<p>The file <b>{0}</b> already exists." |
396 " Overwrite it?</p>").format(fname), |
397 " Overwrite it?</p>").format(fname), |
397 icon = E5MessageBox.Warning) |
398 icon=E5MessageBox.Warning) |
398 if not res: |
399 if not res: |
399 return |
400 return |
400 |
401 |
401 f = QFile(fname) |
402 f = QFile(fname) |
402 if not f.open(QIODevice.WriteOnly): |
403 if not f.open(QIODevice.WriteOnly): |