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

KIO

ksslinfodialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
00004  * Copyright (C) 2000 Malte Starostik <malte@kde.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include "ksslinfodialog.h"
00023 #include "ui_sslinfo.h"
00024 #include "ksslcertificatebox.h"
00025 
00026 #include <kssl.h>
00027 
00028 #include <QtGui/QFrame>
00029 #include <QtCore/QDate>
00030 #include <QtCore/QFile>
00031 #include <QtGui/QLabel>
00032 #include <QtGui/QLayout>
00033 #include <QtCore/Q_PID>
00034 #include <QtNetwork/QSslCertificate>
00035 
00036 #include <kcombobox.h>
00037 #include <kglobal.h>
00038 #include <kglobalsettings.h>
00039 #include <kguiitem.h>
00040 #include <kiconloader.h>
00041 #include <klocale.h>
00042 #include <kpushbutton.h>
00043 #include <ksqueezedtextlabel.h>
00044 #include <kstandardguiitem.h>
00045 #include <ktoolinvocation.h>
00046 
00047 #include "ksslcertificate.h"
00048 #include "ksslcertchain.h"
00049 #include "ksslsigners.h"
00050 #include "ktcpsocket.h"
00051 
00052 
00053 class KSslInfoDialog::KSslInfoDialogPrivate
00054 {
00055 public:
00056     QList<QSslCertificate> certificateChain;
00057     QList<QList<KSslError::Error> > certificateErrors;
00058 
00059     bool isMainPartEncrypted;
00060     bool auxPartsEncrypted;
00061 
00062     Ui::SslInfo ui;
00063     KSslCertificateBox *subject;
00064     KSslCertificateBox *issuer;
00065 };
00066 
00067 
00068 
00069 KSslInfoDialog::KSslInfoDialog(QWidget *parent)
00070  : KDialog(parent),
00071    d(new KSslInfoDialogPrivate)
00072 {
00073     setCaption(i18n("KDE SSL Information"));
00074     setAttribute(Qt::WA_DeleteOnClose);
00075 
00076     d->ui.setupUi(mainWidget());
00077     setButtons(KDialog::Close);
00078 
00079     d->subject = new KSslCertificateBox(d->ui.certParties);
00080     d->issuer = new KSslCertificateBox(d->ui.certParties);
00081     d->ui.certParties->addTab(d->subject, i18nc("The receiver of the SSL certificate", "Subject"));
00082     d->ui.certParties->addTab(d->issuer, i18nc("The authority that issued the SSL certificate", "Issuer"));
00083 
00084     d->isMainPartEncrypted = true;
00085     d->auxPartsEncrypted = true;
00086     updateWhichPartsEncrypted();
00087 
00088 #if 0
00089     if (KSSL::doesSSLWork()) {
00090         if (d->m_secCon) {
00091             d->pixmap->setPixmap(BarIcon("security-high"));
00092             d->info->setText(i18n("Current connection is secured with SSL."));
00093         } else {
00094             d->pixmap->setPixmap(BarIcon("security-low"));
00095             d->info->setText(i18n("Current connection is not secured with SSL."));
00096         }
00097     } else {
00098         d->pixmap->setPixmap(BarIcon("security-low"));
00099         d->info->setText(i18n("SSL support is not available in this build of KDE."));
00100     }
00101 #endif
00102 }
00103 
00104 
00105 KSslInfoDialog::~KSslInfoDialog()
00106 {
00107     delete d;
00108 }
00109 
00110 
00111 //slot
00112 void KSslInfoDialog::launchConfig()
00113 {
00114     QProcess::startDetached("kcmshell4", QStringList() << "crypto");
00115 }
00116 
00117 
00118 void KSslInfoDialog::setMainPartEncrypted(bool mainEncrypted)
00119 {
00120     d->isMainPartEncrypted = mainEncrypted;
00121     updateWhichPartsEncrypted();
00122 }
00123 
00124 
00125 void KSslInfoDialog::setAuxiliaryPartsEncrypted(bool auxEncrypted)
00126 {
00127     d->auxPartsEncrypted = auxEncrypted;
00128     updateWhichPartsEncrypted();
00129 }
00130 
00131 
00132 void KSslInfoDialog::updateWhichPartsEncrypted()
00133 {
00134     if (d->isMainPartEncrypted) {
00135         if (d->auxPartsEncrypted) {
00136             d->ui.encryptionIndicator->setPixmap(BarIcon("security-high"));
00137             d->ui.explanation->setText(i18n("Current connection is secured with SSL."));
00138         } else {
00139             d->ui.encryptionIndicator->setPixmap(BarIcon("security-medium"));
00140             d->ui.explanation->setText(i18n("The main part of this document is secured "
00141                                             "with SSL, but some parts are not."));
00142         }
00143     } else {
00144         if (d->auxPartsEncrypted) {
00145             d->ui.encryptionIndicator->setPixmap(BarIcon("security-medium"));
00146             d->ui.explanation->setText(i18n("Some of this document is secured with SSL, "
00147                                             "but the main part is not."));
00148         } else {
00149             d->ui.encryptionIndicator->setPixmap(BarIcon("security-low"));
00150             d->ui.explanation->setText(i18n("Current connection is not secured with SSL."));
00151         }
00152     }
00153 }
00154 
00155 
00156 void KSslInfoDialog::setSslInfo(const QList<QSslCertificate> &certificateChain,
00157                                 const QString &ip, const QString &host,
00158                                 const QString &sslProtocol, const QString &cipher,
00159                                 int usedBits, int bits,
00160                                 const QList<QList<KSslError::Error> > &validationErrors) {
00161 
00162     d->certificateChain = certificateChain;
00163     d->certificateErrors = validationErrors;
00164 
00165     d->ui.certSelector->clear();
00166     for (int i = 0; i < certificateChain.size(); i++) {
00167         const QSslCertificate &cert = certificateChain[i];
00168         QString name;
00169         static const QSslCertificate::SubjectInfo si[] = {
00170             QSslCertificate::CommonName,
00171             QSslCertificate::Organization,
00172             QSslCertificate::OrganizationalUnitName
00173         };
00174         for (int j = 0; j < 3 && name.isEmpty(); j++)
00175             name = cert.subjectInfo(si[j]);
00176         d->ui.certSelector->addItem(name);
00177     }
00178     if (certificateChain.size() < 2) {
00179         d->ui.certSelector->setEnabled(false);
00180     }
00181     connect(d->ui.certSelector, SIGNAL(currentIndexChanged(int)),
00182             this, SLOT(displayFromChain(int)));
00183     if (d->certificateChain.isEmpty())
00184         d->certificateChain.append(QSslCertificate());
00185     displayFromChain(0);
00186 
00187     d->ui.ip->setText(ip);
00188     d->ui.address->setText(host);
00189     d->ui.sslVersion->setText(sslProtocol);
00190 
00191     const QStringList cipherInfo = cipher.split('\n', QString::SkipEmptyParts);
00192     if (cipherInfo.size() >= 4) {
00193         d->ui.encryption->setText(i18n("%1, using %2 bits of a %3 bit key",
00194                                          cipherInfo[0], QString::number(usedBits),
00195                                               QString::number(bits)));
00196         d->ui.details->setText(QString("Auth = %1, Kx = %2, MAC = %3")
00197                                       .arg(cipherInfo[1], cipherInfo[2],
00198                                            cipherInfo[3]));
00199     } else {
00200         d->ui.encryption->setText("");
00201         d->ui.details->setText("");
00202     }
00203 }
00204 
00205 
00206 void KSslInfoDialog::displayFromChain(int i)
00207 {
00208     const QSslCertificate &cert = d->certificateChain[i];
00209 
00210     QString trusted;
00211     if (!d->certificateErrors[i].isEmpty()) {
00212         trusted = i18nc("The certificate is not trusted", "NO, there were errors:");
00213         foreach (KSslError::Error e, d->certificateErrors[i]) {
00214             KSslError classError(e);
00215             trusted.append('\n');
00216             trusted.append(classError.errorString());
00217         }
00218     } else {
00219         trusted = i18nc("The certificate is trusted", "Yes");
00220     }
00221     d->ui.trusted->setText(trusted);
00222 
00223     QString vp = "%1 to %2";
00224     vp = vp.arg(KGlobal::locale()->formatDateTime(cert.effectiveDate()));
00225     vp = vp.arg(KGlobal::locale()->formatDateTime(cert.expiryDate()));
00226     d->ui.validityPeriod->setText(vp);
00227 
00228     d->ui.serial->setText(cert.serialNumber());
00229     d->ui.digest->setText(cert.digest().toHex());
00230 
00231     d->subject->setCertificate(cert, KSslCertificateBox::Subject);
00232     d->issuer->setCertificate(cert, KSslCertificateBox::Issuer);
00233 }
00234 
00235 
00236 //static
00237 QList<QList<KSslError::Error> > KSslInfoDialog::errorsFromString(const QString &es)
00238 {
00239     QStringList sl = es.split('\n', QString::KeepEmptyParts);
00240     QList<QList<KSslError::Error> > ret;
00241     foreach (const QString &s, sl) {
00242         QList<KSslError::Error> certErrors;
00243         QStringList sl2 = s.split('\t', QString::SkipEmptyParts);
00244         foreach (const QString &s2, sl2) {
00245             bool didConvert;
00246             KSslError::Error error = static_cast<KSslError::Error>(s2.toInt(&didConvert));
00247             if (didConvert) {
00248                 certErrors.append(error);
00249             }
00250         }
00251         ret.append(certErrors);
00252     }
00253     return ret;
00254 }
00255 
00256 #include "ksslinfodialog.moc"

KIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal