eric6/E5Network/E5SslCertificatesDialog.py

Tue, 06 Oct 2020 17:52:44 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 06 Oct 2020 17:52:44 +0200
changeset 7759
51aa6c6b66f7
parent 7533
88261c96484b
child 7780
41420f82c0ac
permissions
-rw-r--r--

Changed calls to exec_() into exec() (remainder of Python2 elimination).

2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7253
diff changeset
3 # Copyright (c) 2010 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to show and edit all certificates.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
10
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
11 from PyQt5.QtCore import (
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 pyqtSlot, Qt, QByteArray, QFile, QFileInfo, QIODevice
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 )
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 try:
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 from PyQt5.QtNetwork import (
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 QSslCertificate, QSslSocket, QSslConfiguration, QSsl
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
18 )
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 except ImportError:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 pass
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 from E5Gui import E5MessageBox, E5FileDialog
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 from .Ui_E5SslCertificatesDialog import Ui_E5SslCertificatesDialog
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 import Preferences
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import Utilities
2361
fe8bccb78a8d Added some eye candy to the SSL stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
28 import UI.PixmapCache
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
29 import Globals
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 class E5SslCertificatesDialog(QDialog, Ui_E5SslCertificatesDialog):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Class implementing a dialog to show and edit all certificates.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 CertRole = Qt.UserRole + 1
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def __init__(self, parent=None):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Constructor
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @param parent reference to the parent widget (QWidget)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
44 super(E5SslCertificatesDialog, self).__init__(parent)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setupUi(self)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
47 self.serversViewButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
48 UI.PixmapCache.getIcon("certificates"))
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
49 self.serversDeleteButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
50 UI.PixmapCache.getIcon("certificateDelete"))
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
51 self.serversExportButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
52 UI.PixmapCache.getIcon("certificateExport"))
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
53 self.serversImportButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
54 UI.PixmapCache.getIcon("certificateImport"))
2361
fe8bccb78a8d Added some eye candy to the SSL stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
55
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
56 self.caViewButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
57 UI.PixmapCache.getIcon("certificates"))
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
58 self.caDeleteButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
59 UI.PixmapCache.getIcon("certificateDelete"))
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
60 self.caExportButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
61 UI.PixmapCache.getIcon("certificateExport"))
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
62 self.caImportButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
63 UI.PixmapCache.getIcon("certificateImport"))
2361
fe8bccb78a8d Added some eye candy to the SSL stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
64
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__populateServerCertificatesTree()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.__populateCaCertificatesTree()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def __populateServerCertificatesTree(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Private slot to populate the server certificates tree.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
72 certificateDict = Globals.toDict(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
73 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 for server in certificateDict:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 for cert in QSslCertificate.fromData(certificateDict[server]):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__createServerCertificateEntry(server, cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.serversCertificatesTree.expandAll()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 for i in range(self.serversCertificatesTree.columnCount()):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.serversCertificatesTree.resizeColumnToContents(i)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 def __createServerCertificateEntry(self, server, cert):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 Private method to create a server certificate entry.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @param server server name of the certificate (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 @param cert certificate to insert (QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 # step 1: extract the info to be shown
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
90 organisation = Utilities.decodeString(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
91 ", ".join(cert.subjectInfo(QSslCertificate.Organization)))
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
92 commonName = Utilities.decodeString(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
93 ", ".join(cert.subjectInfo(QSslCertificate.CommonName)))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if organisation is None or organisation == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
95 organisation = self.tr("(Unknown)")
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 if commonName is None or commonName == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
97 commonName = self.tr("(Unknown common name)")
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 expiryDate = cert.expiryDate().toString("yyyy-MM-dd")
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 # step 2: create the entry
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
101 items = self.serversCertificatesTree.findItems(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
102 organisation,
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 Qt.MatchFixedString | Qt.MatchCaseSensitive)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 if len(items) == 0:
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
105 parent = QTreeWidgetItem(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
106 self.serversCertificatesTree, [organisation])
6662
0002926e71d3 Web Browser (NG): added support to select a client SSL certificate (as of Qt 5.12).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
107 parent.setFirstColumnSpanned(True)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 parent = items[0]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 itm = QTreeWidgetItem(parent, [commonName, server, expiryDate])
2363
d5d006a038a4 Introduced a workaround for an issue in Qt5/PyQt4 attaching a QSslCertificate to a QTreeWidgetItem.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2361
diff changeset
112 itm.setData(0, self.CertRole, cert.toPem())
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 def on_serversCertificatesTree_currentItemChanged(self, current, previous):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 Private slot handling a change of the current item in the
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 server certificates list.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @param current new current item (QTreeWidgetItem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @param previous previous current item (QTreeWidgetItem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 enable = current is not None and current.parent() is not None
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.serversViewButton.setEnabled(enable)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.serversDeleteButton.setEnabled(enable)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.serversExportButton.setEnabled(enable)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 def on_serversViewButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 Private slot to show data of the selected server certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
133 try:
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
134 from E5Network.E5SslCertificatesInfoDialog import (
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
135 E5SslCertificatesInfoDialog
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
136 )
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
137 cert = QSslCertificate.fromData(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
138 self.serversCertificatesTree.currentItem().data(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
139 0, self.CertRole))
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
140 dlg = E5SslCertificatesInfoDialog(cert, self)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
141 dlg.exec()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
142 except ImportError:
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
143 pass
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def on_serversDeleteButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Private slot to delete the selected server certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 itm = self.serversCertificatesTree.currentItem()
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
151 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
152 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
153 self.tr("Delete Server Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
154 self.tr("""<p>Shall the server certificate really be"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
155 """ deleted?</p><p>{0}</p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
156 """<p>If the server certificate is deleted, the"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
157 """ normal security checks will be reinstantiated"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
158 """ and the server has to present a valid"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
159 """ certificate.</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
160 .format(itm.text(0)))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 if res:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 server = itm.text(1)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
163 cert = self.serversCertificatesTree.currentItem().data(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
164 0, self.CertRole)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
166 # delete the selected entry and its parent entry,
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
167 # if it was the only one
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 parent = itm.parent()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 parent.takeChild(parent.indexOfChild(itm))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 if parent.childCount() == 0:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.serversCertificatesTree.takeTopLevelItem(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.serversCertificatesTree.indexOfTopLevelItem(parent))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 # delete the certificate from the user certificate store
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
175 certificateDict = Globals.toDict(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
176 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 if server in certificateDict:
6606
593488c37f2c E5SslCertificatesDialog: fixed an issue handling the deletion of a certificate
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178 certs = [c.toPem() for c in
593488c37f2c E5SslCertificatesDialog: fixed an issue handling the deletion of a certificate
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 QSslCertificate.fromData(certificateDict[server])]
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 if cert in certs:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 certs.remove(cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if certs:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 pems = QByteArray()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 for cert in certs:
6606
593488c37f2c E5SslCertificatesDialog: fixed an issue handling the deletion of a certificate
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
185 pems.append(cert + b'\n')
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 certificateDict[server] = pems
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 del certificateDict[server]
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
189 Preferences.Prefs.settings.setValue(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
190 "Ssl/CaCertificatesDict",
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 certificateDict)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 # delete the certificate from the default certificates
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 self.__updateDefaultConfiguration()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 def on_serversImportButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 Private slot to import server certificates.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 certs = self.__importCertificate()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 if certs:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 server = "*"
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
204 certificateDict = Globals.toDict(
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 if server in certificateDict:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 sCerts = QSslCertificate.fromData(certificateDict[server])
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 sCerts = []
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 pems = QByteArray()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 for cert in certs:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 if cert in sCerts:
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
214 commonStr = ", ".join(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
215 cert.subjectInfo(QSslCertificate.CommonName))
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
216 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
217 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
218 self.tr("Import Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
219 self.tr(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
220 """<p>The certificate <b>{0}</b> already exists."""
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
221 """ Skipping.</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
222 .format(Utilities.decodeString(commonStr)))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 pems.append(cert.toPem() + '\n')
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 if server not in certificateDict:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 certificateDict[server] = QByteArray()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 certificateDict[server].append(pems)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
228 Preferences.Prefs.settings.setValue(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
229 "Ssl/CaCertificatesDict",
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 certificateDict)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 self.serversCertificatesTree.clear()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 self.__populateServerCertificatesTree()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 self.__updateDefaultConfiguration()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 def on_serversExportButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 Private slot to export the selected server certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
242 cert = self.serversCertificatesTree.currentItem().data(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
243 0, self.CertRole)
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
244 fname = (
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
245 self.serversCertificatesTree.currentItem().text(0).replace(" ", "")
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
246 .replace("\t", "")
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
247 )
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 self.__exportCertificate(fname, cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 def __updateDefaultConfiguration(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 Private method to update the default SSL configuration.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 caList = self.__getSystemCaCertificates()
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
255 certificateDict = Globals.toDict(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
256 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 for server in certificateDict:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 for cert in QSslCertificate.fromData(certificateDict[server]):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 if cert not in caList:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 caList.append(cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 sslCfg = QSslConfiguration.defaultConfiguration()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 sslCfg.setCaCertificates(caList)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 QSslConfiguration.setDefaultConfiguration(sslCfg)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 def __getSystemCaCertificates(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 Private method to get the list of system certificates.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 @return list of system certificates (list of QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 """
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
271 caList = QSslCertificate.fromData(Globals.toByteArray(
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 Preferences.Prefs.settings.value("Help/SystemCertificates")))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 if not caList:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 caList = QSslSocket.systemCaCertificates()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 return caList
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 def __populateCaCertificatesTree(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 Private slot to populate the CA certificates tree.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 for cert in self.__getSystemCaCertificates():
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 self.__createCaCertificateEntry(cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 self.caCertificatesTree.expandAll()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 for i in range(self.caCertificatesTree.columnCount()):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 self.caCertificatesTree.resizeColumnToContents(i)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 self.caCertificatesTree.sortItems(0, Qt.AscendingOrder)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 def __createCaCertificateEntry(self, cert):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 Private method to create a CA certificate entry.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 @param cert certificate to insert (QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 # step 1: extract the info to be shown
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
296 organisation = Utilities.decodeString(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
297 ", ".join(cert.subjectInfo(QSslCertificate.Organization)))
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
298 commonName = Utilities.decodeString(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
299 ", ".join(cert.subjectInfo(QSslCertificate.CommonName)))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 if organisation is None or organisation == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
301 organisation = self.tr("(Unknown)")
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 if commonName is None or commonName == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
303 commonName = self.tr("(Unknown common name)")
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 expiryDate = cert.expiryDate().toString("yyyy-MM-dd")
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 # step 2: create the entry
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
307 items = self.caCertificatesTree.findItems(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
308 organisation,
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 Qt.MatchFixedString | Qt.MatchCaseSensitive)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 if len(items) == 0:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation])
6662
0002926e71d3 Web Browser (NG): added support to select a client SSL certificate (as of Qt 5.12).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
312 parent.setFirstColumnSpanned(True)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 parent = items[0]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 itm = QTreeWidgetItem(parent, [commonName, expiryDate])
2363
d5d006a038a4 Introduced a workaround for an issue in Qt5/PyQt4 attaching a QSslCertificate to a QTreeWidgetItem.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2361
diff changeset
317 itm.setData(0, self.CertRole, cert.toPem())
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 def on_caCertificatesTree_currentItemChanged(self, current, previous):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 Private slot handling a change of the current item
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 in the CA certificates list.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 @param current new current item (QTreeWidgetItem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 @param previous previous current item (QTreeWidgetItem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 enable = current is not None and current.parent() is not None
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 self.caViewButton.setEnabled(enable)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 self.caDeleteButton.setEnabled(enable)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 self.caExportButton.setEnabled(enable)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 def on_caViewButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 Private slot to show data of the selected CA certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
338 try:
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
339 from E5Network.E5SslCertificatesInfoDialog import (
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
340 E5SslCertificatesInfoDialog
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
341 )
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
342 cert = QSslCertificate.fromData(
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
343 self.caCertificatesTree.currentItem().data(0, self.CertRole))
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
344 dlg = E5SslCertificatesInfoDialog(cert, self)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
345 dlg.exec()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
346 except ImportError:
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2363
diff changeset
347 pass
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 def on_caDeleteButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 Private slot to delete the selected CA certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 itm = self.caCertificatesTree.currentItem()
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
355 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
356 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
357 self.tr("Delete CA Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
358 self.tr(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
359 """<p>Shall the CA certificate really be deleted?</p>"""
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
360 """<p>{0}</p>"""
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
361 """<p>If the CA certificate is deleted, the browser"""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
362 """ will not trust any certificate issued by this CA.</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
363 .format(itm.text(0)))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 if res:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 cert = self.caCertificatesTree.currentItem().data(0, self.CertRole)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
367 # delete the selected entry and its parent entry,
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
368 # if it was the only one
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 parent = itm.parent()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 parent.takeChild(parent.indexOfChild(itm))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 if parent.childCount() == 0:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 self.caCertificatesTree.takeTopLevelItem(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 self.caCertificatesTree.indexOfTopLevelItem(parent))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 # delete the certificate from the CA certificate store
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 caCerts = self.__getSystemCaCertificates()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 if cert in caCerts:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 caCerts.remove(cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 pems = QByteArray()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 for cert in caCerts:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 pems.append(cert.toPem() + '\n')
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
382 Preferences.Prefs.settings.setValue(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
383 "Help/SystemCertificates", pems)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 # delete the certificate from the default certificates
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 self.__updateDefaultConfiguration()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 def on_caImportButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 Private slot to import server certificates.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 certs = self.__importCertificate()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 if certs:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 caCerts = self.__getSystemCaCertificates()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 for cert in certs:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 if cert in caCerts:
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
398 commonStr = ", ".join(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
399 cert.subjectInfo(QSslCertificate.CommonName))
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
400 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
401 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
402 self.tr("Import Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
403 self.tr(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
404 """<p>The certificate <b>{0}</b> already exists."""
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
405 """ Skipping.</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
406 .format(Utilities.decodeString(commonStr)))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 caCerts.append(cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 pems = QByteArray()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 for cert in caCerts:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 pems.append(cert.toPem() + '\n')
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
413 Preferences.Prefs.settings.setValue(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
414 "Help/SystemCertificates", pems)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 self.caCertificatesTree.clear()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 self.__populateCaCertificatesTree()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 self.__updateDefaultConfiguration()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 @pyqtSlot()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 def on_caExportButton_clicked(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 Private slot to export the selected CA certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 cert = self.caCertificatesTree.currentItem().data(0, self.CertRole)
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
427 fname = (
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
428 self.caCertificatesTree.currentItem().text(0).replace(" ", "")
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
429 .replace("\t", "")
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
430 )
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 self.__exportCertificate(fname, cert)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 def __exportCertificate(self, name, cert):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 Private slot to export a certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 @param name default file name without extension (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 @param cert certificate to be exported (QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 if cert is not None:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
443 self.tr("Export Certificate"),
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 name,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
445 self.tr("Certificate File (PEM) (*.pem);;"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
446 "Certificate File (DER) (*.der)"),
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 None,
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 if fname:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 ext = QFileInfo(fname).suffix()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 if not ext or ext not in ["pem", "der"]:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 ex = selectedFilter.split("(*")[1].split(")")[0]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 if ex:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 fname += ex
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
457 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
458 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
459 self.tr("Export Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
460 self.tr("<p>The file <b>{0}</b> already exists."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
461 " Overwrite it?</p>").format(fname),
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 icon=E5MessageBox.Warning)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 if not res:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 return
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 f = QFile(fname)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 if not f.open(QIODevice.WriteOnly):
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
468 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
469 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
470 self.tr("Export Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
471 self.tr(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
472 """<p>The certificate could not be written"""
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
473 """ to file <b>{0}</b></p><p>Error: {1}</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
474 .format(fname, f.errorString()))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 return
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 if fname.endswith(".pem"):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 crt = cert.toPem()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480 crt = cert.toDer()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 f.write(crt)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 f.close()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 def __importCertificate(self):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 Private method to read a certificate.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 @return certificates read (list of QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 fname = E5FileDialog.getOpenFileName(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
492 self.tr("Import Certificate"),
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
494 self.tr("Certificate Files (*.pem *.crt *.der *.cer *.ca);;"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
495 "All Files (*)"))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 if fname:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 f = QFile(fname)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 if not f.open(QIODevice.ReadOnly):
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
500 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
501 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
502 self.tr("Export Certificate"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
503 self.tr(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
504 """<p>The certificate could not be read from file"""
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
505 """ <b>{0}</b></p><p>Error: {1}</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
506 .format(fname, f.errorString()))
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 return []
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509 crt = f.readAll()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 f.close()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 cert = QSslCertificate.fromData(crt, QSsl.Pem)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 if not cert:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 cert = QSslCertificate.fromData(crt, QSsl.Der)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515 return cert
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
516
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 return []

eric ide

mercurial