KIO

ksslinfodialog.cpp
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2000, 2001 George Staikos <staikos@kde.org>
4 SPDX-FileCopyrightText: 2000 Malte Starostik <malte@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "ksslinfodialog.h"
10#include "ksslcertificatebox.h"
11#include "ui_sslinfo.h"
12
13#include <QDialogButtonBox>
14
15#include <QSslCertificate>
16
17#include <KIconLoader> // BarIcon
18#include <KLocalizedString>
19
20class Q_DECL_HIDDEN KSslInfoDialog::KSslInfoDialogPrivate
21{
22public:
23 QList<QSslCertificate> certificateChain;
24 QList<QList<QSslError::SslError>> certificateErrors;
25
26 bool isMainPartEncrypted;
27 bool auxPartsEncrypted;
28
29 Ui::SslInfo ui;
30 KSslCertificateBox *subject;
31 KSslCertificateBox *issuer;
32};
33
35 : QDialog(parent)
36 , d(new KSslInfoDialogPrivate)
37{
38 setWindowTitle(i18n("KDE SSL Information"));
40
41 QVBoxLayout *layout = new QVBoxLayout(this);
42
43 QWidget *mainWidget = new QWidget(this);
44 d->ui.setupUi(mainWidget);
45 layout->addWidget(mainWidget);
46
47 d->subject = new KSslCertificateBox(d->ui.certParties);
48 d->issuer = new KSslCertificateBox(d->ui.certParties);
49 d->ui.certParties->addTab(d->subject, i18nc("The receiver of the SSL certificate", "Subject"));
50 d->ui.certParties->addTab(d->issuer, i18nc("The authority that issued the SSL certificate", "Issuer"));
51
52 d->isMainPartEncrypted = true;
53 d->auxPartsEncrypted = true;
54 updateWhichPartsEncrypted();
55
56 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
60 layout->addWidget(buttonBox);
61}
62
64
65void KSslInfoDialog::setMainPartEncrypted(bool mainEncrypted)
66{
67 d->isMainPartEncrypted = mainEncrypted;
68 updateWhichPartsEncrypted();
69}
70
71void KSslInfoDialog::setAuxiliaryPartsEncrypted(bool auxEncrypted)
72{
73 d->auxPartsEncrypted = auxEncrypted;
74 updateWhichPartsEncrypted();
75}
76
77void KSslInfoDialog::updateWhichPartsEncrypted()
78{
79 if (d->isMainPartEncrypted) {
80 if (d->auxPartsEncrypted) {
81 d->ui.encryptionIndicator->setPixmap(QIcon::fromTheme(QStringLiteral("security-high")).pixmap(KIconLoader::SizeSmallMedium));
82 d->ui.explanation->setText(i18n("Current connection is secured with SSL."));
83 } else {
84 d->ui.encryptionIndicator->setPixmap(QIcon::fromTheme(QStringLiteral("security-medium")).pixmap(KIconLoader::SizeSmallMedium));
85 d->ui.explanation->setText(
86 i18n("The main part of this document is secured "
87 "with SSL, but some parts are not."));
88 }
89 } else {
90 if (d->auxPartsEncrypted) {
91 d->ui.encryptionIndicator->setPixmap(QIcon::fromTheme(QStringLiteral("security-medium")).pixmap(KIconLoader::SizeSmallMedium));
92 d->ui.explanation->setText(
93 i18n("Some of this document is secured with SSL, "
94 "but the main part is not."));
95 } else {
96 d->ui.encryptionIndicator->setPixmap(QIcon::fromTheme(QStringLiteral("security-low")).pixmap(KIconLoader::SizeSmallMedium));
97 d->ui.explanation->setText(i18n("Current connection is not secured with SSL."));
98 }
99 }
100}
101
103 const QString &ip,
104 const QString &host,
105 const QString &sslProtocol,
106 const QString &cipher,
107 int usedBits,
108 int bits,
109 const QList<QList<QSslError::SslError>> &validationErrors)
110{
111 d->certificateChain = certificateChain;
112 d->certificateErrors = validationErrors;
113
114 d->ui.certSelector->clear();
115 for (const QSslCertificate &cert : certificateChain) {
116 QString name;
118 for (int j = 0; j < 3 && name.isEmpty(); j++) {
119 name = cert.subjectInfo(si[j]).join(QLatin1String(", "));
120 }
121 d->ui.certSelector->addItem(name);
122 }
123 if (certificateChain.size() < 2) {
124 d->ui.certSelector->setEnabled(false);
125 }
126 connect(d->ui.certSelector, &QComboBox::currentIndexChanged, this, &KSslInfoDialog::displayFromChain);
127 if (d->certificateChain.isEmpty()) {
128 d->certificateChain.append(QSslCertificate());
129 }
130 displayFromChain(0);
131
132 d->ui.ip->setText(ip);
133 d->ui.address->setText(host);
134 d->ui.sslVersion->setText(sslProtocol);
135
136 const QStringList cipherInfo = cipher.split(QLatin1Char('\n'), Qt::SkipEmptyParts);
137 if (cipherInfo.size() >= 4) {
138 d->ui.encryption->setText(i18nc("%1, using %2 bits of a %3 bit key",
139 "%1, %2 %3",
140 cipherInfo[0],
141 i18ncp("Part of: %1, using %2 bits of a %3 bit key", "using %1 bit", "using %1 bits", usedBits),
142 i18ncp("Part of: %1, using %2 bits of a %3 bit key", "of a %1 bit key", "of a %1 bit key", bits)));
143 d->ui.details->setText(QStringLiteral("Auth = %1, Kx = %2, MAC = %3").arg(cipherInfo[1], cipherInfo[2], cipherInfo[3]));
144 } else {
145 d->ui.encryption->setText(QString());
146 d->ui.details->setText(QString());
147 }
148}
149
150void KSslInfoDialog::displayFromChain(int i)
151{
152 const QSslCertificate &cert = d->certificateChain[i];
153
154 QString trusted;
155 const QList<QSslError::SslError> errorsList = d->certificateErrors[i];
156 if (!errorsList.isEmpty()) {
157 trusted = i18nc("The certificate is not trusted", "NO, there were errors:");
158 for (QSslError::SslError e : errorsList) {
159 QSslError classError(e);
160 trusted += QLatin1Char('\n') + classError.errorString();
161 }
162 } else {
163 trusted = i18nc("The certificate is trusted", "Yes");
164 }
165 d->ui.trusted->setText(trusted);
166
167 QString vp =
168 i18nc("%1 is the effective date of the certificate, %2 is the expiry date", "%1 to %2", cert.effectiveDate().toString(), cert.expiryDate().toString());
169 d->ui.validityPeriod->setText(vp);
170
171 d->ui.serial->setText(QString::fromUtf8(cert.serialNumber()));
172 d->ui.digest->setText(QString::fromUtf8(cert.digest().toHex()));
173 d->ui.sha1Digest->setText(QString::fromUtf8(cert.digest(QCryptographicHash::Sha1).toHex()));
174
175 d->subject->setCertificate(cert, KSslCertificateBox::Subject);
176 d->issuer->setCertificate(cert, KSslCertificateBox::Issuer);
177}
178
179// static
181{
182 const QStringList sl = errorsString.split(QLatin1Char('\n'), Qt::KeepEmptyParts);
184 ret.reserve(sl.size());
185 for (const QString &s : sl) {
187 const QStringList sl2 = s.split(QLatin1Char('\t'), Qt::SkipEmptyParts);
188 for (const QString &s2 : sl2) {
189 bool didConvert;
190 QSslError::SslError error = static_cast<QSslError::SslError>(s2.toInt(&didConvert));
191 if (didConvert) {
192 certErrors.append(error);
193 }
194 }
195 ret.append(certErrors);
196 }
197 return ret;
198}
199
200#include "moc_ksslinfodialog.cpp"
KDE SSL Information Dialog.
void setSslInfo(const QList< QSslCertificate > &certificateChain, const QString &ip, const QString &host, const QString &sslProtocol, const QString &cipher, int usedBits, int bits, const QList< QList< QSslError::SslError > > &validationErrors)
Set information to display about the SSL connection.
~KSslInfoDialog() override
Destroy this dialog.
static QList< QList< QSslError::SslError > > certificateErrorsFromString(const QString &errorsString)
Converts certificate errors as provided in the "ssl_cert_errors" meta data to a list of QSslError::Ss...
KSslInfoDialog(QWidget *parent=nullptr)
Construct a KSSL Information Dialog.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString i18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
QByteArray toHex(char separator) const const
void currentIndexChanged(int index)
QString toString(QStringView format, QCalendar cal) const const
virtual void accept()
virtual void reject()
void setStandardButtons(StandardButtons buttons)
QIcon fromTheme(const QString &name)
void addWidget(QWidget *w)
void append(QList< T > &&value)
bool isEmpty() const const
void reserve(qsizetype size)
qsizetype size() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QByteArray digest(QCryptographicHash::Algorithm algorithm) const const
QDateTime effectiveDate() const const
QDateTime expiryDate() const const
QByteArray serialNumber() const const
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
SkipEmptyParts
WA_DeleteOnClose
QWidget(QWidget *parent, Qt::WindowFlags f)
QLayout * layout() const const
void setAttribute(Qt::WidgetAttribute attribute, bool on)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.