• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kssl
ksslinfodialog.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
4  * Copyright (C) 2000 Malte Starostik <malte@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "ksslinfodialog.h"
23 #include "ui_sslinfo.h"
24 #include "ksslcertificatebox.h"
25 
26 #include <kssl.h>
27 
28 #include <QtGui/QFrame>
29 #include <QtCore/QDate>
30 #include <QtCore/QFile>
31 #include <QtGui/QLabel>
32 #include <QtGui/QLayout>
33 #include <QtCore/Q_PID>
34 #include <QtNetwork/QSslCertificate>
35 
36 #include <kglobal.h>
37 #include <klocale.h>
38 
39 #include "ksslcertificate.h"
40 #include "ksslcertchain.h"
41 #include "ksslsigners.h"
42 #include "ktcpsocket.h"
43 
44 
45 class KSslInfoDialog::KSslInfoDialogPrivate
46 {
47 public:
48  QList<QSslCertificate> certificateChain;
49  QList<QList<KSslError::Error> > certificateErrors;
50 
51  bool isMainPartEncrypted;
52  bool auxPartsEncrypted;
53 
54  Ui::SslInfo ui;
55  KSslCertificateBox *subject;
56  KSslCertificateBox *issuer;
57 };
58 
59 
60 
61 KSslInfoDialog::KSslInfoDialog(QWidget *parent)
62  : KDialog(parent),
63  d(new KSslInfoDialogPrivate)
64 {
65  setCaption(i18n("KDE SSL Information"));
66  setAttribute(Qt::WA_DeleteOnClose);
67 
68  d->ui.setupUi(mainWidget());
69  setButtons(KDialog::Close);
70 
71  d->subject = new KSslCertificateBox(d->ui.certParties);
72  d->issuer = new KSslCertificateBox(d->ui.certParties);
73  d->ui.certParties->addTab(d->subject, i18nc("The receiver of the SSL certificate", "Subject"));
74  d->ui.certParties->addTab(d->issuer, i18nc("The authority that issued the SSL certificate", "Issuer"));
75 
76  d->isMainPartEncrypted = true;
77  d->auxPartsEncrypted = true;
78  updateWhichPartsEncrypted();
79 
80 #if 0
81  if (KSSL::doesSSLWork()) {
82  if (d->m_secCon) {
83  d->pixmap->setPixmap(BarIcon("security-high"));
84  d->info->setText(i18n("Current connection is secured with SSL."));
85  } else {
86  d->pixmap->setPixmap(BarIcon("security-low"));
87  d->info->setText(i18n("Current connection is not secured with SSL."));
88  }
89  } else {
90  d->pixmap->setPixmap(BarIcon("security-low"));
91  d->info->setText(i18n("SSL support is not available in this build of KDE."));
92  }
93 #endif
94 }
95 
96 
97 KSslInfoDialog::~KSslInfoDialog()
98 {
99  delete d;
100 }
101 
102 
103 //slot
104 void KSslInfoDialog::launchConfig()
105 {
106  QProcess::startDetached("kcmshell4", QStringList() << "crypto");
107 }
108 
109 
110 void KSslInfoDialog::setMainPartEncrypted(bool mainEncrypted)
111 {
112  d->isMainPartEncrypted = mainEncrypted;
113  updateWhichPartsEncrypted();
114 }
115 
116 
117 void KSslInfoDialog::setAuxiliaryPartsEncrypted(bool auxEncrypted)
118 {
119  d->auxPartsEncrypted = auxEncrypted;
120  updateWhichPartsEncrypted();
121 }
122 
123 
124 void KSslInfoDialog::updateWhichPartsEncrypted()
125 {
126  if (d->isMainPartEncrypted) {
127  if (d->auxPartsEncrypted) {
128  d->ui.encryptionIndicator->setPixmap(BarIcon("security-high"));
129  d->ui.explanation->setText(i18n("Current connection is secured with SSL."));
130  } else {
131  d->ui.encryptionIndicator->setPixmap(BarIcon("security-medium"));
132  d->ui.explanation->setText(i18n("The main part of this document is secured "
133  "with SSL, but some parts are not."));
134  }
135  } else {
136  if (d->auxPartsEncrypted) {
137  d->ui.encryptionIndicator->setPixmap(BarIcon("security-medium"));
138  d->ui.explanation->setText(i18n("Some of this document is secured with SSL, "
139  "but the main part is not."));
140  } else {
141  d->ui.encryptionIndicator->setPixmap(BarIcon("security-low"));
142  d->ui.explanation->setText(i18n("Current connection is not secured with SSL."));
143  }
144  }
145 }
146 
147 
148 void KSslInfoDialog::setSslInfo(const QList<QSslCertificate> &certificateChain,
149  const QString &ip, const QString &host,
150  const QString &sslProtocol, const QString &cipher,
151  int usedBits, int bits,
152  const QList<QList<KSslError::Error> > &validationErrors) {
153 
154  d->certificateChain = certificateChain;
155  d->certificateErrors = validationErrors;
156 
157  d->ui.certSelector->clear();
158  for (int i = 0; i < certificateChain.size(); i++) {
159  const QSslCertificate &cert = certificateChain[i];
160  QString name;
161  static const QSslCertificate::SubjectInfo si[] = {
162  QSslCertificate::CommonName,
163  QSslCertificate::Organization,
164  QSslCertificate::OrganizationalUnitName
165  };
166  for (int j = 0; j < 3 && name.isEmpty(); j++)
167  name = cert.subjectInfo(si[j]);
168  d->ui.certSelector->addItem(name);
169  }
170  if (certificateChain.size() < 2) {
171  d->ui.certSelector->setEnabled(false);
172  }
173  connect(d->ui.certSelector, SIGNAL(currentIndexChanged(int)),
174  this, SLOT(displayFromChain(int)));
175  if (d->certificateChain.isEmpty())
176  d->certificateChain.append(QSslCertificate());
177  displayFromChain(0);
178 
179  d->ui.ip->setText(ip);
180  d->ui.address->setText(host);
181  d->ui.sslVersion->setText(sslProtocol);
182 
183  const QStringList cipherInfo = cipher.split('\n', QString::SkipEmptyParts);
184  if (cipherInfo.size() >= 4) {
185  d->ui.encryption->setText(i18nc("%1, using %2 bits of a %3 bit key", "%1, %2 %3", cipherInfo[0],
186  i18ncp("Part of: %1, using %2 bits of a %3 bit key",
187  "using %1 bit", "using %1 bits", usedBits),
188  i18ncp("Part of: %1, using %2 bits of a %3 bit key",
189  "of a %1 bit key", "of a %1 bit key", bits)));
190  d->ui.details->setText(QString("Auth = %1, Kx = %2, MAC = %3")
191  .arg(cipherInfo[1], cipherInfo[2],
192  cipherInfo[3]));
193  } else {
194  d->ui.encryption->setText("");
195  d->ui.details->setText("");
196  }
197 }
198 
199 
200 void KSslInfoDialog::displayFromChain(int i)
201 {
202  const QSslCertificate &cert = d->certificateChain[i];
203 
204  QString trusted;
205  if (!d->certificateErrors[i].isEmpty()) {
206  trusted = i18nc("The certificate is not trusted", "NO, there were errors:");
207  foreach (KSslError::Error e, d->certificateErrors[i]) {
208  KSslError classError(e);
209  trusted.append('\n');
210  trusted.append(classError.errorString());
211  }
212  } else {
213  trusted = i18nc("The certificate is trusted", "Yes");
214  }
215  d->ui.trusted->setText(trusted);
216 
217  QString vp = i18nc("%1 is the effective date of the certificate, %2 is the expiry date", "%1 to %2",
218  KGlobal::locale()->formatDateTime(cert.effectiveDate()),
219  KGlobal::locale()->formatDateTime(cert.expiryDate()));
220  d->ui.validityPeriod->setText(vp);
221 
222  d->ui.serial->setText(cert.serialNumber());
223  d->ui.digest->setText(cert.digest().toHex());
224  d->ui.sha1Digest->setText(cert.digest(QCryptographicHash::Sha1).toHex());
225 
226  d->subject->setCertificate(cert, KSslCertificateBox::Subject);
227  d->issuer->setCertificate(cert, KSslCertificateBox::Issuer);
228 }
229 
230 
231 //static
232 QList<QList<KSslError::Error> > KSslInfoDialog::errorsFromString(const QString &es)
233 {
234  QStringList sl = es.split('\n', QString::KeepEmptyParts);
235  QList<QList<KSslError::Error> > ret;
236  foreach (const QString &s, sl) {
237  QList<KSslError::Error> certErrors;
238  QStringList sl2 = s.split('\t', QString::SkipEmptyParts);
239  foreach (const QString &s2, sl2) {
240  bool didConvert;
241  KSslError::Error error = static_cast<KSslError::Error>(s2.toInt(&didConvert));
242  if (didConvert) {
243  certErrors.append(error);
244  }
245  }
246  ret.append(certErrors);
247  }
248  return ret;
249 }
250 
251 #include "ksslinfodialog.moc"
QSslCertificate::effectiveDate
QDateTime effectiveDate() const
i18n
QString i18n(const char *text)
QWidget
QString::append
QString & append(QChar ch)
ksslinfodialog.h
KSslInfoDialog::errorsFromString
static QList< QList< KSslError::Error > > errorsFromString(const QString &s)
Definition: ksslinfodialog.cpp:232
QByteArray::toHex
QByteArray toHex() const
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
ksslcertificate.h
QProcess::startDetached
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
KSslError::Error
Error
QSslCertificate::subjectInfo
QString subjectInfo(SubjectInfo subject) const
KDialog
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
QList::size
int size() const
QObject::name
const char * name() const
kglobal.h
QList::append
void append(const T &value)
KSslInfoDialog::setAuxiliaryPartsEncrypted
void setAuxiliaryPartsEncrypted(bool)
Definition: ksslinfodialog.cpp:117
ksslcertificatebox.h
i18ncp
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
KSslInfoDialog::KSslInfoDialog
KSslInfoDialog(QWidget *parent=0)
Construct a KSSL Information Dialog.
Definition: ksslinfodialog.cpp:61
QString::toInt
int toInt(bool *ok, int base) const
QString::isEmpty
bool isEmpty() const
ip
static const char ip[]
Definition: des.cpp:56
QString
QList< QSslCertificate >
KSslCertificateBox
Definition: ksslcertificatebox.h:32
QStringList
si
static const char si[8][64]
Definition: des.cpp:127
KSslCertificateBox::Issuer
Definition: ksslcertificatebox.h:38
QSslCertificate::digest
QByteArray digest(QCryptographicHash::Algorithm algorithm) const
KLocale::formatDateTime
QString formatDateTime(const QDateTime &dateTime, DateFormat format=ShortDate, bool includeSecs=false) const
KGlobal::locale
KLocale * locale()
ktcpsocket.h
QSslCertificate::serialNumber
QByteArray serialNumber() const
QSslCertificate::expiryDate
QDateTime expiryDate() const
ksslsigners.h
KSslInfoDialog::~KSslInfoDialog
virtual ~KSslInfoDialog()
Destroy this dialog.
Definition: ksslinfodialog.cpp:97
KSSL::doesSSLWork
static bool doesSSLWork()
Determine if SSL is available and works.
Definition: kssl.cpp:209
BarIcon
QPixmap BarIcon(const QString &name, int force_size, int state, const QStringList &overlays)
QWidget::setCaption
void setCaption(const QString &c)
KSslInfoDialog::setMainPartEncrypted
void setMainPartEncrypted(bool)
Definition: ksslinfodialog.cpp:110
KSslCertificateBox::Subject
Definition: ksslcertificatebox.h:37
KSslError
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KSslInfoDialog::setSslInfo
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< KSslError::Error > > &validationErrors)
Set information to display about the SSL connection.
Definition: ksslinfodialog.cpp:148
ksslcertchain.h
kssl.h
QSslCertificate
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal