eric6/E5Network/E5SslCertificatesInfoWidget.py

Wed, 07 Oct 2020 19:14:36 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 07 Oct 2020 19:14:36 +0200
changeset 7766
0af772bc14c4
parent 7360
9190402e4505
child 7780
41420f82c0ac
permissions
-rw-r--r--

Web Browser
-- added a SSL information page to the site info dialog
-- added a clickable SSL info label to the URL entry

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: 7229
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 widget to show SSL certificate infos.
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
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
11 from PyQt5.QtCore import pyqtSlot, QCryptographicHash, QDateTime
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
12 from PyQt5.QtWidgets import QWidget
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
13 try:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
14 from PyQt5.QtNetwork import QSslCertificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
15 except ImportError:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
16 QSslCertificate = None
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
18 from .Ui_E5SslCertificatesInfoWidget import Ui_E5SslCertificatesInfoWidget
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import Utilities
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
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
23 class E5SslCertificatesInfoWidget(QWidget, Ui_E5SslCertificatesInfoWidget):
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing a widget to show SSL certificate infos.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 def __init__(self, parent=None):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
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 @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
32 """
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
33 super(E5SslCertificatesInfoWidget, self).__init__(parent)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.setupUi(self)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
36 self.__chain = []
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
37
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
38 def showCertificateChain(self, certificateChain):
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
39 """
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
40 Public method to show the SSL certificates of a certificate chain.
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
41
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2578
diff changeset
42 @param certificateChain list od SSL certificates
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2578
diff changeset
43 (list of QSslCertificate)
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
44 """
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
45 if QSslCertificate:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
46 self.chainLabel.show()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
47 self.chainComboBox.show()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
48 self.chainComboBox.clear()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
49
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
50 self.__chain = certificateChain[:]
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
51
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
52 for cert in self.__chain:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
53 name = ", ".join(cert.subjectInfo(QSslCertificate.CommonName))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
54 if not name:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
55 name = ", ".join(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
56 cert.subjectInfo(QSslCertificate.Organization))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
57 if not name:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
58 name = cert.serialNumber()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
59 self.chainComboBox.addItem(name)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
60
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
61 self.on_chainComboBox_activated(0)
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
62
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def showCertificate(self, certificate):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
65 Public method to show the SSL certificate information.
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
66
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
67 @param certificate reference to the SSL certificate (QSslCertificate)
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
68 """
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
69 self.chainLabel.hide()
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
70 self.chainComboBox.hide()
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
71 self.chainComboBox.clear()
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
72
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
73 self.__chain = []
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
74
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
75 if QSslCertificate:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
76 self.__showCertificate(certificate)
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
77
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
78 def __showCertificate(self, certificate):
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
79 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
80 Private method to show the SSL certificate information.
2359
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 @param certificate reference to the SSL certificate (QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
84 if QSslCertificate:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
85 self.blacklistedLabel.setVisible(False)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
86 self.blacklistedLabel.setStyleSheet(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
87 "QLabel { color : white; background-color : red; }")
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
88 self.expiredLabel.setVisible(False)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
89 self.expiredLabel.setStyleSheet(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
90 "QLabel { color : white; background-color : red; }")
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
91
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
92 self.subjectCommonNameLabel.setText(self.__certificateString(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
93 ", ".join(certificate.subjectInfo(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
94 QSslCertificate.CommonName))))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
95 self.subjectOrganizationLabel.setText(self.__certificateString(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
96 ", ".join(certificate.subjectInfo(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
97 QSslCertificate.Organization))))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
98 self.subjectOrganizationalUnitLabel.setText(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
99 self.__certificateString(", ".join(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
100 certificate.subjectInfo(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
101 QSslCertificate.OrganizationalUnitName))))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
102 self.issuerCommonNameLabel.setText(self.__certificateString(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
103 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
104 self.issuerOrganizationLabel.setText(self.__certificateString(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
105 ", ".join(certificate.issuerInfo(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
106 QSslCertificate.Organization))))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
107 self.issuerOrganizationalUnitLabel.setText(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
108 self.__certificateString(", ".join(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
109 certificate.issuerInfo(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
110 QSslCertificate.OrganizationalUnitName))))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
111 self.serialNumberLabel.setText(self.__serialNumber(certificate))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
112 self.effectiveLabel.setText(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
113 certificate.effectiveDate().toString("yyyy-MM-dd"))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
114 self.expiresLabel.setText(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
115 certificate.expiryDate().toString("yyyy-MM-dd"))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
116 self.sha1Label.setText(self.__formatHexString(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
117 str(certificate.digest(QCryptographicHash.Sha1).toHex(),
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
118 encoding="ascii")))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
119 self.md5Label.setText(self.__formatHexString(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
120 str(certificate.digest(QCryptographicHash.Md5).toHex(),
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
121 encoding="ascii")))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
122
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
123 if certificate.isBlacklisted():
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
124 # something is wrong; indicate it to the user
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
125 if self.__hasExpired(certificate.effectiveDate(),
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
126 certificate.expiryDate()):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
127 self.expiredLabel.setVisible(True)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
128 else:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
129 self.blacklistedLabel.setVisible(True)
2359
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 def __certificateString(self, txt):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 Private method to prepare some text for display.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @param txt text to be displayed (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @return prepared text (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 if txt is None or txt == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
139 return self.tr("<not part of the certificate>")
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 return Utilities.decodeString(txt)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 def __serialNumber(self, cert):
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 Private slot to format the certificate serial number.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 @param cert reference to the SSL certificate (QSslCertificate)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 @return formated serial number (string)
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 serial = cert.serialNumber()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if serial == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
152 return self.tr("<not part of the certificate>")
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
4326
e52318f11812 Change code to make eric compatible to PyQt 5.5 (QByteArry issue).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
154 if b':' in serial:
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 return str(serial, encoding="ascii").upper()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 hexString = hex(int(serial))[2:]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 return self.__formatHexString(hexString)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 def __formatHexString(self, hexString):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 Private method to format a hex string for display.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 @param hexString hex string to be formatted (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @return formatted string (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 hexString = hexString.upper()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 if len(hexString) % 2 == 1:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 hexString = '0' + hexString
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 hexList = []
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 while hexString:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 hexList.append(hexString[:2])
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 hexString = hexString[2:]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 return ':'.join(hexList)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 def __hasExpired(self, effectiveDate, expiryDate):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 Private method to check for a certificate expiration.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @param effectiveDate date the certificate becomes effective (QDateTime)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @param expiryDate date the certificate expires (QDateTime)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 @return flag indicating the expiration status (boolean)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 now = QDateTime.currentDateTime()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 return now < effectiveDate or now >= expiryDate
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
190
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
191 @pyqtSlot(int)
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
192 def on_chainComboBox_activated(self, index):
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
193 """
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
194 Private slot to show the certificate info for the selected entry.
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
195
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2578
diff changeset
196 @param index number of the certificate in the certificate chain
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2578
diff changeset
197 (integer)
2432
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
198 """
b1a2f9054b28 Reworked the various SSL info widgets of the web browser to show more info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2359
diff changeset
199 self.__showCertificate(self.__chain[index])

eric ide

mercurial