E5Network/E5SslCertificatesDialog.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3484
645c12de6b0c
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
92 organisation = Utilities.decodeString( 92 organisation = Utilities.decodeString(
93 cert.subjectInfo(QSslCertificate.Organization)) 93 cert.subjectInfo(QSslCertificate.Organization))
94 commonName = Utilities.decodeString( 94 commonName = Utilities.decodeString(
95 cert.subjectInfo(QSslCertificate.CommonName)) 95 cert.subjectInfo(QSslCertificate.CommonName))
96 if organisation is None or organisation == "": 96 if organisation is None or organisation == "":
97 organisation = self.trUtf8("(Unknown)") 97 organisation = self.tr("(Unknown)")
98 if commonName is None or commonName == "": 98 if commonName is None or commonName == "":
99 commonName = self.trUtf8("(Unknown common name)") 99 commonName = self.tr("(Unknown common name)")
100 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") 100 expiryDate = cert.expiryDate().toString("yyyy-MM-dd")
101 101
102 # step 2: create the entry 102 # step 2: create the entry
103 items = self.serversCertificatesTree.findItems( 103 items = self.serversCertificatesTree.findItems(
104 organisation, 104 organisation,
148 Private slot to delete the selected server certificate. 148 Private slot to delete the selected server certificate.
149 """ 149 """
150 itm = self.serversCertificatesTree.currentItem() 150 itm = self.serversCertificatesTree.currentItem()
151 res = E5MessageBox.yesNo( 151 res = E5MessageBox.yesNo(
152 self, 152 self,
153 self.trUtf8("Delete Server Certificate"), 153 self.tr("Delete Server Certificate"),
154 self.trUtf8("""<p>Shall the server certificate really be""" 154 self.tr("""<p>Shall the server certificate really be"""
155 """ deleted?</p><p>{0}</p>""" 155 """ deleted?</p><p>{0}</p>"""
156 """<p>If the server certificate is deleted, the""" 156 """<p>If the server certificate is deleted, the"""
157 """ normal security checks will be reinstantiated""" 157 """ normal security checks will be reinstantiated"""
158 """ and the server has to present a valid""" 158 """ and the server has to present a valid"""
159 """ certificate.</p>""") 159 """ certificate.</p>""")
160 .format(itm.text(0))) 160 .format(itm.text(0)))
161 if res: 161 if res:
162 server = itm.text(1) 162 server = itm.text(1)
163 cert = self.serversCertificatesTree.currentItem().data( 163 cert = self.serversCertificatesTree.currentItem().data(
164 0, self.CertRole) 164 0, self.CertRole)
216 else: 216 else:
217 commonStr = cert.subjectInfo( 217 commonStr = cert.subjectInfo(
218 QSslCertificate.CommonName) 218 QSslCertificate.CommonName)
219 E5MessageBox.warning( 219 E5MessageBox.warning(
220 self, 220 self,
221 self.trUtf8("Import Certificate"), 221 self.tr("Import Certificate"),
222 self.trUtf8( 222 self.tr(
223 """<p>The certificate <b>{0}</b> already exists.""" 223 """<p>The certificate <b>{0}</b> already exists."""
224 """ Skipping.</p>""") 224 """ Skipping.</p>""")
225 .format(Utilities.decodeString(commonStr))) 225 .format(Utilities.decodeString(commonStr)))
226 else: 226 else:
227 pems.append(cert.toPem() + '\n') 227 pems.append(cert.toPem() + '\n')
303 organisation = Utilities.decodeString( 303 organisation = Utilities.decodeString(
304 cert.subjectInfo(QSslCertificate.Organization)) 304 cert.subjectInfo(QSslCertificate.Organization))
305 commonName = Utilities.decodeString( 305 commonName = Utilities.decodeString(
306 cert.subjectInfo(QSslCertificate.CommonName)) 306 cert.subjectInfo(QSslCertificate.CommonName))
307 if organisation is None or organisation == "": 307 if organisation is None or organisation == "":
308 organisation = self.trUtf8("(Unknown)") 308 organisation = self.tr("(Unknown)")
309 if commonName is None or commonName == "": 309 if commonName is None or commonName == "":
310 commonName = self.trUtf8("(Unknown common name)") 310 commonName = self.tr("(Unknown common name)")
311 expiryDate = cert.expiryDate().toString("yyyy-MM-dd") 311 expiryDate = cert.expiryDate().toString("yyyy-MM-dd")
312 312
313 # step 2: create the entry 313 # step 2: create the entry
314 items = self.caCertificatesTree.findItems( 314 items = self.caCertificatesTree.findItems(
315 organisation, 315 organisation,
357 Private slot to delete the selected CA certificate. 357 Private slot to delete the selected CA certificate.
358 """ 358 """
359 itm = self.caCertificatesTree.currentItem() 359 itm = self.caCertificatesTree.currentItem()
360 res = E5MessageBox.yesNo( 360 res = E5MessageBox.yesNo(
361 self, 361 self,
362 self.trUtf8("Delete CA Certificate"), 362 self.tr("Delete CA Certificate"),
363 self.trUtf8( 363 self.tr(
364 """<p>Shall the CA certificate really be deleted?</p>""" 364 """<p>Shall the CA certificate really be deleted?</p>"""
365 """<p>{0}</p>""" 365 """<p>{0}</p>"""
366 """<p>If the CA certificate is deleted, the browser""" 366 """<p>If the CA certificate is deleted, the browser"""
367 """ will not trust any certificate issued by this CA.</p>""") 367 """ will not trust any certificate issued by this CA.</p>""")
368 .format(itm.text(0))) 368 .format(itm.text(0)))
406 else: 406 else:
407 commonStr = cert.subjectInfo( 407 commonStr = cert.subjectInfo(
408 QSslCertificate.CommonName) 408 QSslCertificate.CommonName)
409 E5MessageBox.warning( 409 E5MessageBox.warning(
410 self, 410 self,
411 self.trUtf8("Import Certificate"), 411 self.tr("Import Certificate"),
412 self.trUtf8( 412 self.tr(
413 """<p>The certificate <b>{0}</b> already exists.""" 413 """<p>The certificate <b>{0}</b> already exists."""
414 """ Skipping.</p>""") 414 """ Skipping.</p>""")
415 .format(Utilities.decodeString(commonStr))) 415 .format(Utilities.decodeString(commonStr)))
416 else: 416 else:
417 caCerts.append(cert) 417 caCerts.append(cert)
445 @param cert certificate to be exported (QSslCertificate) 445 @param cert certificate to be exported (QSslCertificate)
446 """ 446 """
447 if cert is not None: 447 if cert is not None:
448 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 448 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
449 self, 449 self,
450 self.trUtf8("Export Certificate"), 450 self.tr("Export Certificate"),
451 name, 451 name,
452 self.trUtf8("Certificate File (PEM) (*.pem);;" 452 self.tr("Certificate File (PEM) (*.pem);;"
453 "Certificate File (DER) (*.der)"), 453 "Certificate File (DER) (*.der)"),
454 None, 454 None,
455 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) 455 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
456 456
457 if fname: 457 if fname:
458 ext = QFileInfo(fname).suffix() 458 ext = QFileInfo(fname).suffix()
461 if ex: 461 if ex:
462 fname += ex 462 fname += ex
463 if QFileInfo(fname).exists(): 463 if QFileInfo(fname).exists():
464 res = E5MessageBox.yesNo( 464 res = E5MessageBox.yesNo(
465 self, 465 self,
466 self.trUtf8("Export Certificate"), 466 self.tr("Export Certificate"),
467 self.trUtf8("<p>The file <b>{0}</b> already exists." 467 self.tr("<p>The file <b>{0}</b> already exists."
468 " Overwrite it?</p>").format(fname), 468 " Overwrite it?</p>").format(fname),
469 icon=E5MessageBox.Warning) 469 icon=E5MessageBox.Warning)
470 if not res: 470 if not res:
471 return 471 return
472 472
473 f = QFile(fname) 473 f = QFile(fname)
474 if not f.open(QIODevice.WriteOnly): 474 if not f.open(QIODevice.WriteOnly):
475 E5MessageBox.critical( 475 E5MessageBox.critical(
476 self, 476 self,
477 self.trUtf8("Export Certificate"), 477 self.tr("Export Certificate"),
478 self.trUtf8( 478 self.tr(
479 """<p>The certificate could not be written""" 479 """<p>The certificate could not be written"""
480 """ to file <b>{0}</b></p><p>Error: {1}</p>""") 480 """ to file <b>{0}</b></p><p>Error: {1}</p>""")
481 .format(fname, f.errorString())) 481 .format(fname, f.errorString()))
482 return 482 return
483 483
494 494
495 @return certificates read (list of QSslCertificate) 495 @return certificates read (list of QSslCertificate)
496 """ 496 """
497 fname = E5FileDialog.getOpenFileName( 497 fname = E5FileDialog.getOpenFileName(
498 self, 498 self,
499 self.trUtf8("Import Certificate"), 499 self.tr("Import Certificate"),
500 "", 500 "",
501 self.trUtf8("Certificate Files (*.pem *.crt *.der *.cer *.ca);;" 501 self.tr("Certificate Files (*.pem *.crt *.der *.cer *.ca);;"
502 "All Files (*)")) 502 "All Files (*)"))
503 503
504 if fname: 504 if fname:
505 f = QFile(fname) 505 f = QFile(fname)
506 if not f.open(QIODevice.ReadOnly): 506 if not f.open(QIODevice.ReadOnly):
507 E5MessageBox.critical( 507 E5MessageBox.critical(
508 self, 508 self,
509 self.trUtf8("Export Certificate"), 509 self.tr("Export Certificate"),
510 self.trUtf8( 510 self.tr(
511 """<p>The certificate could not be read from file""" 511 """<p>The certificate could not be read from file"""
512 """ <b>{0}</b></p><p>Error: {1}</p>""") 512 """ <b>{0}</b></p><p>Error: {1}</p>""")
513 .format(fname, f.errorString())) 513 .format(fname, f.errorString()))
514 return [] 514 return []
515 515

eric ide

mercurial