E5Network/E5SslCertificatesInfoWidget.py

Mon, 25 Mar 2013 03:11:06 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 25 Mar 2013 03:11:06 +0100
branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2432
b1a2f9054b28
child 2677
3d4277929fb3
permissions
-rw-r--r--

Script changes: Future import added, super calls modified and unicode behavior for str.

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
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2010 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
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 from __future__ import unicode_literals # __IGNORE_WARNING__
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
11 try:
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
12 str = unicode
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
13 except (NameError):
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
14 pass
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
15
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
16 from PyQt4.QtCore import pyqtSlot, QCryptographicHash, QDateTime, qVersion
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from PyQt4.QtGui import QWidget
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from PyQt4.QtNetwork import QSslCertificate
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
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
20 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
21
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 import Utilities
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
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
25 class E5SslCertificatesInfoWidget(QWidget, Ui_E5SslCertificatesInfoWidget):
2359
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 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
28 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __init__(self, parent=None):
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 Constructor
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @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
34 """
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
35 super(E5SslCertificatesInfoWidget, self).__init__(parent)
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.setupUi(self)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
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
38 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
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 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
41 """
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
42 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
43
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 @param certificateChain list od SSL certificates (list of 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
45 """
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
46 self.chainLabel.show()
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
47 self.chainComboBox.show()
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
48 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
49
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
50 self.__chain = 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
51
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
52 for cert in 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
53 name = cert.subjectInfo(QSslCertificate.CommonName)
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
54 if not name:
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
55 name = cert.subjectInfo(QSslCertificate.Organization)
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
56 if not name:
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
57 name = cert.serialNumber()
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
58 self.chainComboBox.addItem(name)
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
59
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
60 self.on_chainComboBox_activated(0)
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
61
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 def showCertificate(self, certificate):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
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
64 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
65
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 @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
67 """
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 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
69 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
70 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
71
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 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
73
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 self.__showCertificate(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
75
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
76 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
77 """
2359
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 Public method to show the SSL certificate information.
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @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
81 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.blacklistedLabel.setVisible(False)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.blacklistedLabel.setStyleSheet(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 "QLabel { color : white; background-color : red; }")
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.expiredLabel.setVisible(False)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.expiredLabel.setStyleSheet(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 "QLabel { color : white; background-color : red; }")
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 if qVersion() >= "5.0.0":
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.subjectCommonNameLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 ", ".join(certificate.subjectInfo(QSslCertificate.CommonName))))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.subjectOrganizationLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 ", ".join(certificate.subjectInfo(QSslCertificate.Organization))))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.subjectOrganizationalUnitLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 ", ".join(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName))))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.issuerCommonNameLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 ", ".join(certificate.issuerInfo(QSslCertificate.CommonName))))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.issuerOrganizationLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 ", ".join(certificate.issuerInfo(QSslCertificate.Organization))))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.issuerOrganizationalUnitLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 ", ".join(certificate.issuerInfo(QSslCertificate.OrganizationalUnitName))))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.subjectCommonNameLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 certificate.subjectInfo(QSslCertificate.CommonName)))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.subjectOrganizationLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 certificate.subjectInfo(QSslCertificate.Organization)))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.subjectOrganizationalUnitLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 certificate.subjectInfo(QSslCertificate.OrganizationalUnitName)))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.issuerCommonNameLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 certificate.issuerInfo(QSslCertificate.CommonName)))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.issuerOrganizationLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 certificate.issuerInfo(QSslCertificate.Organization)))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.issuerOrganizationalUnitLabel.setText(self.__certificateString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 certificate.issuerInfo(QSslCertificate.OrganizationalUnitName)))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self.serialNumberLabel.setText(self.__serialNumber(certificate))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.effectiveLabel.setText(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 certificate.effectiveDate().toString("yyyy-MM-dd"))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.expiresLabel.setText(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 certificate.expiryDate().toString("yyyy-MM-dd"))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.sha1Label.setText(self.__formatHexString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 str(certificate.digest(QCryptographicHash.Sha1).toHex(), encoding="ascii")))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.md5Label.setText(self.__formatHexString(
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 str(certificate.digest(QCryptographicHash.Md5).toHex(), encoding="ascii")))
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if (qVersion() >= "5.0.0" and certificate.isBlacklisted()) or \
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 (qVersion() < "5.0.0" and not certificate.isValid()):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 # something is wrong; indicate it to the user
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 if self.__hasExpired(certificate.effectiveDate(), certificate.expiryDate()):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.expiredLabel.setVisible(True)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.blacklistedLabel.setVisible(True)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 def __certificateString(self, txt):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 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
137
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 @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
139 @return prepared text (string)
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 if txt is None or txt == "":
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 return self.trUtf8("<not part of the certificate>")
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 return Utilities.decodeString(txt)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def __serialNumber(self, cert):
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 format the certificate serial number.
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 @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
151 @return formated serial number (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 serial = cert.serialNumber()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 if serial == "":
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 return self.trUtf8("<not part of the certificate>")
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 if ':' in serial:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 return str(serial, encoding="ascii").upper()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 else:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 hexString = hex(int(serial))[2:]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 return self.__formatHexString(hexString)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 def __formatHexString(self, hexString):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 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
166
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 @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
168 @return formatted string (string)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 hexString = hexString.upper()
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 if len(hexString) % 2 == 1:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 hexString = '0' + hexString
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 hexList = []
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 while hexString:
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 hexList.append(hexString[:2])
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 hexString = hexString[2:]
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 return ':'.join(hexList)
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 def __hasExpired(self, effectiveDate, expiryDate):
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 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
185
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @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
187 @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
188 @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
189 """
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 now = QDateTime.currentDateTime()
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
ef81d2d0a031 Moved the SSL widgets to the E5Network package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 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
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 @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
195 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
196 """
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
197 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
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 @param index number of the certificate in the certificate chain (integer)
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
200 """
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
201 self.__showCertificate(self.__chain[index])

eric ide

mercurial