85 @param server server name of the certificate (string) |
85 @param server server name of the certificate (string) |
86 @param cert certificate to insert (QSslCertificate) |
86 @param cert certificate to insert (QSslCertificate) |
87 """ |
87 """ |
88 # step 1: extract the info to be shown |
88 # step 1: extract the info to be shown |
89 organisation = Utilities.decodeString( |
89 organisation = Utilities.decodeString( |
90 ", ".join(cert.subjectInfo(QSslCertificate.Organization))) |
90 ", ".join(cert.subjectInfo( |
|
91 QSslCertificate.SubjectInfo.Organization))) |
91 commonName = Utilities.decodeString( |
92 commonName = Utilities.decodeString( |
92 ", ".join(cert.subjectInfo(QSslCertificate.CommonName))) |
93 ", ".join(cert.subjectInfo( |
|
94 QSslCertificate.SubjectInfo.CommonName))) |
93 if organisation is None or organisation == "": |
95 if organisation is None or organisation == "": |
94 organisation = self.tr("(Unknown)") |
96 organisation = self.tr("(Unknown)") |
95 if commonName is None or commonName == "": |
97 if commonName is None or commonName == "": |
96 commonName = self.tr("(Unknown common name)") |
98 commonName = self.tr("(Unknown common name)") |
97 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
99 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
98 |
100 |
99 # step 2: create the entry |
101 # step 2: create the entry |
100 items = self.serversCertificatesTree.findItems( |
102 items = self.serversCertificatesTree.findItems( |
101 organisation, |
103 organisation, |
102 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
104 Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive) |
103 if len(items) == 0: |
105 if len(items) == 0: |
104 parent = QTreeWidgetItem( |
106 parent = QTreeWidgetItem( |
105 self.serversCertificatesTree, [organisation]) |
107 self.serversCertificatesTree, [organisation]) |
106 parent.setFirstColumnSpanned(True) |
108 parent.setFirstColumnSpanned(True) |
107 else: |
109 else: |
209 |
211 |
210 pems = QByteArray() |
212 pems = QByteArray() |
211 for cert in certs: |
213 for cert in certs: |
212 if cert in sCerts: |
214 if cert in sCerts: |
213 commonStr = ", ".join( |
215 commonStr = ", ".join( |
214 cert.subjectInfo(QSslCertificate.CommonName)) |
216 cert.subjectInfo( |
|
217 QSslCertificate.SubjectInfo.CommonName)) |
215 E5MessageBox.warning( |
218 E5MessageBox.warning( |
216 self, |
219 self, |
217 self.tr("Import Certificate"), |
220 self.tr("Import Certificate"), |
218 self.tr( |
221 self.tr( |
219 """<p>The certificate <b>{0}</b> already exists.""" |
222 """<p>The certificate <b>{0}</b> already exists.""" |
281 self.__createCaCertificateEntry(cert) |
284 self.__createCaCertificateEntry(cert) |
282 |
285 |
283 self.caCertificatesTree.expandAll() |
286 self.caCertificatesTree.expandAll() |
284 for i in range(self.caCertificatesTree.columnCount()): |
287 for i in range(self.caCertificatesTree.columnCount()): |
285 self.caCertificatesTree.resizeColumnToContents(i) |
288 self.caCertificatesTree.resizeColumnToContents(i) |
286 self.caCertificatesTree.sortItems(0, Qt.AscendingOrder) |
289 self.caCertificatesTree.sortItems(0, Qt.SortOrder.AscendingOrder) |
287 |
290 |
288 def __createCaCertificateEntry(self, cert): |
291 def __createCaCertificateEntry(self, cert): |
289 """ |
292 """ |
290 Private method to create a CA certificate entry. |
293 Private method to create a CA certificate entry. |
291 |
294 |
292 @param cert certificate to insert (QSslCertificate) |
295 @param cert certificate to insert (QSslCertificate) |
293 """ |
296 """ |
294 # step 1: extract the info to be shown |
297 # step 1: extract the info to be shown |
295 organisation = Utilities.decodeString( |
298 organisation = Utilities.decodeString( |
296 ", ".join(cert.subjectInfo(QSslCertificate.Organization))) |
299 ", ".join(cert.subjectInfo( |
|
300 QSslCertificate.SubjectInfo.Organization))) |
297 commonName = Utilities.decodeString( |
301 commonName = Utilities.decodeString( |
298 ", ".join(cert.subjectInfo(QSslCertificate.CommonName))) |
302 ", ".join(cert.subjectInfo( |
|
303 QSslCertificate.SubjectInfo.CommonName))) |
299 if organisation is None or organisation == "": |
304 if organisation is None or organisation == "": |
300 organisation = self.tr("(Unknown)") |
305 organisation = self.tr("(Unknown)") |
301 if commonName is None or commonName == "": |
306 if commonName is None or commonName == "": |
302 commonName = self.tr("(Unknown common name)") |
307 commonName = self.tr("(Unknown common name)") |
303 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
308 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") |
304 |
309 |
305 # step 2: create the entry |
310 # step 2: create the entry |
306 items = self.caCertificatesTree.findItems( |
311 items = self.caCertificatesTree.findItems( |
307 organisation, |
312 organisation, |
308 Qt.MatchFixedString | Qt.MatchCaseSensitive) |
313 Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive) |
309 if len(items) == 0: |
314 if len(items) == 0: |
310 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation]) |
315 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation]) |
311 parent.setFirstColumnSpanned(True) |
316 parent.setFirstColumnSpanned(True) |
312 else: |
317 else: |
313 parent = items[0] |
318 parent = items[0] |
393 if certs: |
398 if certs: |
394 caCerts = self.__getSystemCaCertificates() |
399 caCerts = self.__getSystemCaCertificates() |
395 for cert in certs: |
400 for cert in certs: |
396 if cert in caCerts: |
401 if cert in caCerts: |
397 commonStr = ", ".join( |
402 commonStr = ", ".join( |
398 cert.subjectInfo(QSslCertificate.CommonName)) |
403 cert.subjectInfo( |
|
404 QSslCertificate.SubjectInfo.CommonName)) |
399 E5MessageBox.warning( |
405 E5MessageBox.warning( |
400 self, |
406 self, |
401 self.tr("Import Certificate"), |
407 self.tr("Import Certificate"), |
402 self.tr( |
408 self.tr( |
403 """<p>The certificate <b>{0}</b> already exists.""" |
409 """<p>The certificate <b>{0}</b> already exists.""" |