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(i18nc("%1, using %2 bits of a %3 bit key", "%1, %2 %3", cipherInfo[0], 00194 i18ncp("Part of: %1, using %2 bits of a %3 bit key", 00195 "using %1 bit", "using %1 bits", QString::number(usedBits)), 00196 i18ncp("Part of: %1, using %2 bits of a %3 bit key", 00197 "of a %1 bit key", "of a %1 bit key", QString::number(bits)))); 00198 d->ui.details->setText(QString("Auth = %1, Kx = %2, MAC = %3") 00199 .arg(cipherInfo[1], cipherInfo[2], 00200 cipherInfo[3])); 00201 } else { 00202 d->ui.encryption->setText(""); 00203 d->ui.details->setText(""); 00204 } 00205 } 00206 00207 00208 void KSslInfoDialog::displayFromChain(int i) 00209 { 00210 const QSslCertificate &cert = d->certificateChain[i]; 00211 00212 QString trusted; 00213 if (!d->certificateErrors[i].isEmpty()) { 00214 trusted = i18nc("The certificate is not trusted", "NO, there were errors:"); 00215 foreach (KSslError::Error e, d->certificateErrors[i]) { 00216 KSslError classError(e); 00217 trusted.append('\n'); 00218 trusted.append(classError.errorString()); 00219 } 00220 } else { 00221 trusted = i18nc("The certificate is trusted", "Yes"); 00222 } 00223 d->ui.trusted->setText(trusted); 00224 00225 QString vp = i18nc("%1 is the effective date of the certificate, %2 is the expiry date", "%1 to %2", 00226 KGlobal::locale()->formatDateTime(cert.effectiveDate()), 00227 KGlobal::locale()->formatDateTime(cert.expiryDate())); 00228 d->ui.validityPeriod->setText(vp); 00229 00230 d->ui.serial->setText(cert.serialNumber()); 00231 d->ui.digest->setText(cert.digest().toHex()); 00232 d->ui.sha1Digest->setText(cert.digest(QCryptographicHash::Sha1).toHex()); 00233 00234 d->subject->setCertificate(cert, KSslCertificateBox::Subject); 00235 d->issuer->setCertificate(cert, KSslCertificateBox::Issuer); 00236 } 00237 00238 00239 //static 00240 QList<QList<KSslError::Error> > KSslInfoDialog::errorsFromString(const QString &es) 00241 { 00242 QStringList sl = es.split('\n', QString::KeepEmptyParts); 00243 QList<QList<KSslError::Error> > ret; 00244 foreach (const QString &s, sl) { 00245 QList<KSslError::Error> certErrors; 00246 QStringList sl2 = s.split('\t', QString::SkipEmptyParts); 00247 foreach (const QString &s2, sl2) { 00248 bool didConvert; 00249 KSslError::Error error = static_cast<KSslError::Error>(s2.toInt(&didConvert)); 00250 if (didConvert) { 00251 certErrors.append(error); 00252 } 00253 } 00254 ret.append(certErrors); 00255 } 00256 return ret; 00257 } 00258 00259 #include "ksslinfodialog.moc"
KDE 4.6 API Reference