Helpviewer/SslCertificatesDialog.py

changeset 2078
9f4a45741622
parent 1509
c0b5e693b0eb
child 2080
4b33165dd55b
equal deleted inserted replaced
2077:68a34718a0ce 2078:9f4a45741622
5 5
6 """ 6 """
7 Module implementing a dialog to show and edit all certificates. 7 Module implementing a dialog to show and edit all certificates.
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSlot, Qt, QByteArray, QFile, QFileInfo, QIODevice 10 from PyQt4.QtCore import pyqtSlot, Qt, QByteArray, QFile, QFileInfo, QIODevice, \
11 qVersion
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem 12 from PyQt4.QtGui import QDialog, QTreeWidgetItem
12 try: 13 try:
13 from PyQt4.QtNetwork import QSslCertificate, QSslSocket, QSslConfiguration, QSsl 14 from PyQt4.QtNetwork import QSslCertificate, QSslSocket, QSslConfiguration, QSsl
14 except ImportError: 15 except ImportError:
15 pass 16 pass
65 66
66 @param server server name of the certificate (string) 67 @param server server name of the certificate (string)
67 @param cert certificate to insert (QSslCertificate) 68 @param cert certificate to insert (QSslCertificate)
68 """ 69 """
69 # step 1: extract the info to be shown 70 # step 1: extract the info to be shown
70 organisation = Qt.escape(Utilities.decodeString( 71 if qVersion() >= "5.0.0":
71 cert.subjectInfo(QSslCertificate.Organization))) 72 organisation = Qt.escape(Utilities.decodeString(
73 ", ".join(cert.subjectInfo(QSslCertificate.Organization))))
74 commonName = Qt.escape(Utilities.decodeString(
75 ", ".join(cert.subjectInfo(QSslCertificate.CommonName))))
76 else:
77 organisation = Qt.escape(Utilities.decodeString(
78 cert.subjectInfo(QSslCertificate.Organization)))
79 commonName = Qt.escape(Utilities.decodeString(
80 cert.subjectInfo(QSslCertificate.CommonName)))
72 if organisation is None or organisation == "": 81 if organisation is None or organisation == "":
73 organisation = self.trUtf8("(Unknown)") 82 organisation = self.trUtf8("(Unknown)")
74 commonName = Qt.escape(Utilities.decodeString(
75 cert.subjectInfo(QSslCertificate.CommonName)))
76 if commonName is None or commonName == "": 83 if commonName is None or commonName == "":
77 commonName = self.trUtf8("(Unknown common name)") 84 commonName = self.trUtf8("(Unknown common name)")
78 expiryDate = Qt.escape(cert.expiryDate().toString("yyyy-MM-dd")) 85 expiryDate = Qt.escape(cert.expiryDate().toString("yyyy-MM-dd"))
79 86
80 # step 2: create the entry 87 # step 2: create the entry
172 sCerts = [] 179 sCerts = []
173 180
174 pems = QByteArray() 181 pems = QByteArray()
175 for cert in certs: 182 for cert in certs:
176 if cert in sCerts: 183 if cert in sCerts:
184 if qVersion() >= "5.0.0":
185 commonStr = ", ".join(
186 cert.subjectInfo(QSslCertificate.CommonName))
187 else:
188 commonStr = cert.subjectInfo(QSslCertificate.CommonName)
177 E5MessageBox.warning(self, 189 E5MessageBox.warning(self,
178 self.trUtf8("Import Certificate"), 190 self.trUtf8("Import Certificate"),
179 self.trUtf8("""<p>The certificate <b>{0}</b> already exists.""" 191 self.trUtf8("""<p>The certificate <b>{0}</b> already exists."""
180 """ Skipping.</p>""") 192 """ Skipping.</p>""")
181 .format(Utilities.decodeString( 193 .format(Utilities.decodeString(commonStr)))
182 cert.subjectInfo(QSslCertificate.CommonName))))
183 else: 194 else:
184 pems.append(cert.toPem() + '\n') 195 pems.append(cert.toPem() + '\n')
185 if server not in certificateDict: 196 if server not in certificateDict:
186 certificateDict[server] = QByteArray() 197 certificateDict[server] = QByteArray()
187 certificateDict[server].append(pems) 198 certificateDict[server].append(pems)
247 Private method to create a CA certificate entry. 258 Private method to create a CA certificate entry.
248 259
249 @param cert certificate to insert (QSslCertificate) 260 @param cert certificate to insert (QSslCertificate)
250 """ 261 """
251 # step 1: extract the info to be shown 262 # step 1: extract the info to be shown
252 organisation = Qt.escape(Utilities.decodeString( 263 if qVersion() >= "5.0.0":
253 cert.subjectInfo(QSslCertificate.Organization))) 264 organisation = Qt.escape(Utilities.decodeString(
265 ", ".join(cert.subjectInfo(QSslCertificate.Organization))))
266 commonName = Qt.escape(Utilities.decodeString(
267 ", ".join(cert.subjectInfo(QSslCertificate.CommonName))))
268 else:
269 organisation = Qt.escape(Utilities.decodeString(
270 cert.subjectInfo(QSslCertificate.Organization)))
271 commonName = Qt.escape(Utilities.decodeString(
272 cert.subjectInfo(QSslCertificate.CommonName)))
254 if organisation is None or organisation == "": 273 if organisation is None or organisation == "":
255 organisation = self.trUtf8("(Unknown)") 274 organisation = self.trUtf8("(Unknown)")
256 commonName = Qt.escape(Utilities.decodeString(
257 cert.subjectInfo(QSslCertificate.CommonName)))
258 if commonName is None or commonName == "": 275 if commonName is None or commonName == "":
259 commonName = self.trUtf8("(Unknown common name)") 276 commonName = self.trUtf8("(Unknown common name)")
260 expiryDate = Qt.escape(cert.expiryDate().toString("yyyy-MM-dd")) 277 expiryDate = Qt.escape(cert.expiryDate().toString("yyyy-MM-dd"))
261 278
262 # step 2: create the entry 279 # step 2: create the entry
336 certs = self.__importCertificate() 353 certs = self.__importCertificate()
337 if certs: 354 if certs:
338 caCerts = self.__getSystemCaCertificates() 355 caCerts = self.__getSystemCaCertificates()
339 for cert in certs: 356 for cert in certs:
340 if cert in caCerts: 357 if cert in caCerts:
358 if qVersion() >= "5.0.0":
359 commonStr = ", ".join(
360 cert.subjectInfo(QSslCertificate.CommonName))
361 else:
362 commonStr = cert.subjectInfo(QSslCertificate.CommonName)
341 E5MessageBox.warning(self, 363 E5MessageBox.warning(self,
342 self.trUtf8("Import Certificate"), 364 self.trUtf8("Import Certificate"),
343 self.trUtf8("""<p>The certificate <b>{0}</b> already exists.""" 365 self.trUtf8("""<p>The certificate <b>{0}</b> already exists."""
344 """ Skipping.</p>""") 366 """ Skipping.</p>""")
345 .format(Utilities.decodeString( 367 .format(Utilities.decodeString(commonStr)))
346 cert.subjectInfo(QSslCertificate.CommonName))))
347 else: 368 else:
348 caCerts.append(cert) 369 caCerts.append(cert)
349 370
350 pems = QByteArray() 371 pems = QByteArray()
351 for cert in caCerts: 372 for cert in caCerts:

eric ide

mercurial