16 with contextlib.suppress(ImportError): |
16 with contextlib.suppress(ImportError): |
17 from PyQt6.QtNetwork import ( |
17 from PyQt6.QtNetwork import ( |
18 QSslCertificate, QSslSocket, QSslConfiguration, QSsl |
18 QSslCertificate, QSslSocket, QSslConfiguration, QSsl |
19 ) |
19 ) |
20 |
20 |
21 from E5Gui import E5MessageBox, E5FileDialog |
21 from E5Gui import EricMessageBox, EricFileDialog |
22 |
22 |
23 from .Ui_EricSslCertificatesDialog import Ui_EricSslCertificatesDialog |
23 from .Ui_EricSslCertificatesDialog import Ui_EricSslCertificatesDialog |
24 |
24 |
25 import Preferences |
25 import Preferences |
26 import Utilities |
26 import Utilities |
145 def on_serversDeleteButton_clicked(self): |
145 def on_serversDeleteButton_clicked(self): |
146 """ |
146 """ |
147 Private slot to delete the selected server certificate. |
147 Private slot to delete the selected server certificate. |
148 """ |
148 """ |
149 itm = self.serversCertificatesTree.currentItem() |
149 itm = self.serversCertificatesTree.currentItem() |
150 res = E5MessageBox.yesNo( |
150 res = EricMessageBox.yesNo( |
151 self, |
151 self, |
152 self.tr("Delete Server Certificate"), |
152 self.tr("Delete Server Certificate"), |
153 self.tr("""<p>Shall the server certificate really be""" |
153 self.tr("""<p>Shall the server certificate really be""" |
154 """ deleted?</p><p>{0}</p>""" |
154 """ deleted?</p><p>{0}</p>""" |
155 """<p>If the server certificate is deleted, the""" |
155 """<p>If the server certificate is deleted, the""" |
211 for cert in certs: |
211 for cert in certs: |
212 if cert in sCerts: |
212 if cert in sCerts: |
213 commonStr = ", ".join( |
213 commonStr = ", ".join( |
214 cert.subjectInfo( |
214 cert.subjectInfo( |
215 QSslCertificate.SubjectInfo.CommonName)) |
215 QSslCertificate.SubjectInfo.CommonName)) |
216 E5MessageBox.warning( |
216 EricMessageBox.warning( |
217 self, |
217 self, |
218 self.tr("Import Certificate"), |
218 self.tr("Import Certificate"), |
219 self.tr( |
219 self.tr( |
220 """<p>The certificate <b>{0}</b> already exists.""" |
220 """<p>The certificate <b>{0}</b> already exists.""" |
221 """ Skipping.</p>""") |
221 """ Skipping.</p>""") |
350 def on_caDeleteButton_clicked(self): |
350 def on_caDeleteButton_clicked(self): |
351 """ |
351 """ |
352 Private slot to delete the selected CA certificate. |
352 Private slot to delete the selected CA certificate. |
353 """ |
353 """ |
354 itm = self.caCertificatesTree.currentItem() |
354 itm = self.caCertificatesTree.currentItem() |
355 res = E5MessageBox.yesNo( |
355 res = EricMessageBox.yesNo( |
356 self, |
356 self, |
357 self.tr("Delete CA Certificate"), |
357 self.tr("Delete CA Certificate"), |
358 self.tr( |
358 self.tr( |
359 """<p>Shall the CA certificate really be deleted?</p>""" |
359 """<p>Shall the CA certificate really be deleted?</p>""" |
360 """<p>{0}</p>""" |
360 """<p>{0}</p>""" |
396 for cert in certs: |
396 for cert in certs: |
397 if cert in caCerts: |
397 if cert in caCerts: |
398 commonStr = ", ".join( |
398 commonStr = ", ".join( |
399 cert.subjectInfo( |
399 cert.subjectInfo( |
400 QSslCertificate.SubjectInfo.CommonName)) |
400 QSslCertificate.SubjectInfo.CommonName)) |
401 E5MessageBox.warning( |
401 EricMessageBox.warning( |
402 self, |
402 self, |
403 self.tr("Import Certificate"), |
403 self.tr("Import Certificate"), |
404 self.tr( |
404 self.tr( |
405 """<p>The certificate <b>{0}</b> already exists.""" |
405 """<p>The certificate <b>{0}</b> already exists.""" |
406 """ Skipping.</p>""") |
406 """ Skipping.</p>""") |
437 |
437 |
438 @param name default file name without extension (string) |
438 @param name default file name without extension (string) |
439 @param cert certificate to be exported (QSslCertificate) |
439 @param cert certificate to be exported (QSslCertificate) |
440 """ |
440 """ |
441 if cert is not None: |
441 if cert is not None: |
442 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
442 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
443 self, |
443 self, |
444 self.tr("Export Certificate"), |
444 self.tr("Export Certificate"), |
445 name, |
445 name, |
446 self.tr("Certificate File (PEM) (*.pem);;" |
446 self.tr("Certificate File (PEM) (*.pem);;" |
447 "Certificate File (DER) (*.der)"), |
447 "Certificate File (DER) (*.der)"), |
448 None, |
448 None, |
449 E5FileDialog.DontConfirmOverwrite) |
449 EricFileDialog.DontConfirmOverwrite) |
450 |
450 |
451 if fname: |
451 if fname: |
452 ext = QFileInfo(fname).suffix() |
452 ext = QFileInfo(fname).suffix() |
453 if not ext or ext not in ["pem", "der"]: |
453 if not ext or ext not in ["pem", "der"]: |
454 ex = selectedFilter.split("(*")[1].split(")")[0] |
454 ex = selectedFilter.split("(*")[1].split(")")[0] |
455 if ex: |
455 if ex: |
456 fname += ex |
456 fname += ex |
457 if QFileInfo(fname).exists(): |
457 if QFileInfo(fname).exists(): |
458 res = E5MessageBox.yesNo( |
458 res = EricMessageBox.yesNo( |
459 self, |
459 self, |
460 self.tr("Export Certificate"), |
460 self.tr("Export Certificate"), |
461 self.tr("<p>The file <b>{0}</b> already exists." |
461 self.tr("<p>The file <b>{0}</b> already exists." |
462 " Overwrite it?</p>").format(fname), |
462 " Overwrite it?</p>").format(fname), |
463 icon=E5MessageBox.Warning) |
463 icon=EricMessageBox.Warning) |
464 if not res: |
464 if not res: |
465 return |
465 return |
466 |
466 |
467 f = QFile(fname) |
467 f = QFile(fname) |
468 if not f.open(QIODevice.OpenModeFlag.WriteOnly): |
468 if not f.open(QIODevice.OpenModeFlag.WriteOnly): |
469 E5MessageBox.critical( |
469 EricMessageBox.critical( |
470 self, |
470 self, |
471 self.tr("Export Certificate"), |
471 self.tr("Export Certificate"), |
472 self.tr( |
472 self.tr( |
473 """<p>The certificate could not be written""" |
473 """<p>The certificate could not be written""" |
474 """ to file <b>{0}</b></p><p>Error: {1}</p>""") |
474 """ to file <b>{0}</b></p><p>Error: {1}</p>""") |
486 """ |
486 """ |
487 Private method to read a certificate. |
487 Private method to read a certificate. |
488 |
488 |
489 @return certificates read (list of QSslCertificate) |
489 @return certificates read (list of QSslCertificate) |
490 """ |
490 """ |
491 fname = E5FileDialog.getOpenFileName( |
491 fname = EricFileDialog.getOpenFileName( |
492 self, |
492 self, |
493 self.tr("Import Certificate"), |
493 self.tr("Import Certificate"), |
494 "", |
494 "", |
495 self.tr("Certificate Files (*.pem *.crt *.der *.cer *.ca);;" |
495 self.tr("Certificate Files (*.pem *.crt *.der *.cer *.ca);;" |
496 "All Files (*)")) |
496 "All Files (*)")) |
497 |
497 |
498 if fname: |
498 if fname: |
499 f = QFile(fname) |
499 f = QFile(fname) |
500 if not f.open(QIODevice.OpenModeFlag.ReadOnly): |
500 if not f.open(QIODevice.OpenModeFlag.ReadOnly): |
501 E5MessageBox.critical( |
501 EricMessageBox.critical( |
502 self, |
502 self, |
503 self.tr("Export Certificate"), |
503 self.tr("Export Certificate"), |
504 self.tr( |
504 self.tr( |
505 """<p>The certificate could not be read from file""" |
505 """<p>The certificate could not be read from file""" |
506 """ <b>{0}</b></p><p>Error: {1}</p>""") |
506 """ <b>{0}</b></p><p>Error: {1}</p>""") |