E5Network/E5SslCertificatesDialog.py

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

eric ide

mercurial