34 """ |
36 """ |
35 QDialog.__init__(self, parent) |
37 QDialog.__init__(self, parent) |
36 self.setupUi(self) |
38 self.setupUi(self) |
37 |
39 |
38 self.__populateServerCertificatesTree() |
40 self.__populateServerCertificatesTree() |
|
41 self.__populateCaCertificatesTree() |
39 |
42 |
40 def __populateServerCertificatesTree(self): |
43 def __populateServerCertificatesTree(self): |
41 """ |
44 """ |
42 Private slot to populate the server certificates tree. |
45 Private slot to populate the server certificates tree. |
43 """ |
46 """ |
44 certificateDict = Preferences.toDict( |
47 certificateDict = Preferences.toDict( |
45 Preferences.Prefs.settings.value("Help/CaCertificatesDict")) |
48 Preferences.Prefs.settings.value("Help/CaCertificatesDict")) |
46 for server in certificateDict: |
49 for server in certificateDict: |
47 for cert in QSslCertificate.fromData(certificateDict[server]): |
50 for cert in QSslCertificate.fromData(certificateDict[server]): |
48 self.__createCertificateEntry(self.serversCertificatesTree, server, cert) |
51 self.__createServerCertificateEntry(server, cert) |
49 |
52 |
50 self.serversCertificatesTree.expandAll() |
53 self.serversCertificatesTree.expandAll() |
51 for i in range(self.serversCertificatesTree.columnCount()): |
54 for i in range(self.serversCertificatesTree.columnCount()): |
52 self.serversCertificatesTree.resizeColumnToContents(i) |
55 self.serversCertificatesTree.resizeColumnToContents(i) |
53 |
56 |
54 def __createCertificateEntry(self, tree, server, cert): |
57 def __createServerCertificateEntry(self, server, cert): |
55 """ |
58 """ |
56 Private method to create a certificate entry. |
59 Private method to create a certificate entry. |
57 |
60 |
58 @param tree reference to the tree to insert the certificate (QTreeWidget) |
|
59 @param server server name of the certificate (string) |
61 @param server server name of the certificate (string) |
60 @param cert certificate to insert (QSslCertificate) |
62 @param cert certificate to insert (QSslCertificate) |
61 """ |
63 """ |
62 # step 1: extract the info to be shown |
64 # step 1: extract the info to be shown |
63 organisation = cert.subjectInfo(QSslCertificate.Organization) |
65 organisation = cert.subjectInfo(QSslCertificate.Organization) |
67 if commonName is None or commonName == "": |
69 if commonName is None or commonName == "": |
68 commonName = self.trUtf8("(Unknown common name)") |
70 commonName = self.trUtf8("(Unknown common name)") |
69 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
71 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
70 |
72 |
71 # step 2: create the entry |
73 # step 2: create the entry |
72 items = tree.findItems(organisation, Qt.MatchFixedString | Qt.MatchCaseSensitive) |
74 items = self.serversCertificatesTree.findItems(organisation, |
|
75 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
73 if len(items) == 0: |
76 if len(items) == 0: |
74 parent = QTreeWidgetItem(tree, [organisation]) |
77 parent = QTreeWidgetItem(self.serversCertificatesTree, [organisation]) |
75 else: |
78 else: |
76 parent = items[0] |
79 parent = items[0] |
77 |
80 |
78 itm = QTreeWidgetItem(parent, [commonName, server, expiryDate]) |
81 itm = QTreeWidgetItem(parent, [commonName, server, expiryDate]) |
79 itm.setData(0, self.CertRole, cert) |
82 itm.setData(0, self.CertRole, cert) |
91 self.serversDeleteButton.setEnabled(enable) |
94 self.serversDeleteButton.setEnabled(enable) |
92 |
95 |
93 @pyqtSlot() |
96 @pyqtSlot() |
94 def on_serversViewButton_clicked(self): |
97 def on_serversViewButton_clicked(self): |
95 """ |
98 """ |
96 Private slot to show data of the selected certificate |
99 Private slot to show data of the selected certificate. |
97 """ |
100 """ |
98 cert = self.serversCertificatesTree.currentItem().data(0, self.CertRole) |
101 cert = self.serversCertificatesTree.currentItem().data(0, self.CertRole) |
99 dlg = SslInfoDialog(cert, self) |
102 dlg = SslInfoDialog(cert, self) |
100 dlg.exec_() |
103 dlg.exec_() |
101 |
104 |
102 @pyqtSlot() |
105 @pyqtSlot() |
103 def on_serversDeleteButton_clicked(self): |
106 def on_serversDeleteButton_clicked(self): |
104 """ |
107 """ |
|
108 Private slot to delete the selected certificate. |
|
109 """ |
|
110 itm = self.serversCertificatesTree.currentItem() |
|
111 res = E5MessageBox.yesNo(self, |
|
112 self.trUtf8("Delete Server Certificate"), |
|
113 self.trUtf8("""<p>Shall the server certificate really be deleted?</p>""" |
|
114 """<p>{0}</p>""" |
|
115 """<p>If the server certificate is deleted, the normal security""" |
|
116 """ checks will be reinstantiated and the server has to""" |
|
117 """ present a valid certificate.</p>""")\ |
|
118 .format(itm.text(0))) |
|
119 if res: |
|
120 server = itm.text(1) |
|
121 |
|
122 # delete the selected entry and it's parent entry, if it was the only one |
|
123 parent = itm.parent() |
|
124 parent.takeChild(parent.indexOfChild(itm)) |
|
125 if parent.childCount() == 0: |
|
126 self.serversCertificatesTree.takeTopLevelItem( |
|
127 self.serversCertificatesTree.indexOfTopLevelItem(parent)) |
|
128 |
|
129 # delete the certificate from the user certificate store |
|
130 certificateDict = Preferences.toDict( |
|
131 Preferences.Prefs.settings.value("Help/CaCertificatesDict")) |
|
132 del certificateDict[server] |
|
133 Preferences.Prefs.settings.setValue("Help/CaCertificatesDict", |
|
134 certificateDict) |
|
135 |
|
136 # delete the certificate from the default certificates |
|
137 caNew = [] |
|
138 for topLevelIndex in range(self.serversCertificatesTree.topLevelItemCount()): |
|
139 parent = self.serversCertificatesTree.topLevelItem(topLevelIndex) |
|
140 for childIndex in range(parent.childCount()): |
|
141 cert = parent.child(childIndex).data(0, self.CertRole) |
|
142 if cert not in caNew: |
|
143 caNew.append(cert) |
|
144 caList = QSslSocket.systemCaCertificates() |
|
145 caList.extend(caNew) |
|
146 sslCfg = QSslConfiguration.defaultConfiguration() |
|
147 sslCfg.setCaCertificates(caList) |
|
148 QSslConfiguration.setDefaultConfiguration(sslCfg) |
|
149 |
|
150 def __populateCaCertificatesTree(self): |
|
151 """ |
|
152 Private slot to populate the CA certificates tree. |
|
153 """ |
|
154 for cert in QSslSocket.systemCaCertificates(): |
|
155 self.__createCaCertificateEntry(cert) |
|
156 |
|
157 self.caCertificatesTree.expandAll() |
|
158 for i in range(self.caCertificatesTree.columnCount()): |
|
159 self.caCertificatesTree.resizeColumnToContents(i) |
|
160 self.caCertificatesTree.sortItems(0, Qt.AscendingOrder) |
|
161 |
|
162 def __createCaCertificateEntry(self, cert): |
|
163 """ |
|
164 Private method to create a certificate entry. |
|
165 |
|
166 @param cert certificate to insert (QSslCertificate) |
|
167 """ |
|
168 # step 1: extract the info to be shown |
|
169 organisation = cert.subjectInfo(QSslCertificate.Organization) |
|
170 if organisation is None or organisation == "": |
|
171 organisation = self.trUtf8("(Unknown)") |
|
172 commonName = cert.subjectInfo(QSslCertificate.CommonName) |
|
173 if commonName is None or commonName == "": |
|
174 commonName = self.trUtf8("(Unknown common name)") |
|
175 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
|
176 |
|
177 # step 2: create the entry |
|
178 items = self.caCertificatesTree.findItems(organisation, |
|
179 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
|
180 if len(items) == 0: |
|
181 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation]) |
|
182 else: |
|
183 parent = items[0] |
|
184 |
|
185 QTreeWidgetItem(parent, [commonName, expiryDate]) |
|
186 |
|
187 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
|
188 def on_caCertificatesTree_currentItemChanged(self, current, previous): |
|
189 """ |
105 Slot documentation goes here. |
190 Slot documentation goes here. |
106 """ |
191 """ |
107 # TODO: not implemented yet |
192 # TODO: not implemented yet |
108 raise NotImplementedError |
193 raise NotImplementedError |
|
194 |
|
195 @pyqtSlot() |
|
196 def on_caViewButton_clicked(self): |
|
197 """ |
|
198 Slot documentation goes here. |
|
199 """ |
|
200 # TODO: not implemented yet |
|
201 raise NotImplementedError |