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 <kglobal.h> 00037 #include <klocale.h> 00038 00039 #include "ksslcertificate.h" 00040 #include "ksslcertchain.h" 00041 #include "ksslsigners.h" 00042 #include "ktcpsocket.h" 00043 00044 00045 class KSslInfoDialog::KSslInfoDialogPrivate 00046 { 00047 public: 00048 QList<QSslCertificate> certificateChain; 00049 QList<QList<KSslError::Error> > certificateErrors; 00050 00051 bool isMainPartEncrypted; 00052 bool auxPartsEncrypted; 00053 00054 Ui::SslInfo ui; 00055 KSslCertificateBox *subject; 00056 KSslCertificateBox *issuer; 00057 }; 00058 00059 00060 00061 KSslInfoDialog::KSslInfoDialog(QWidget *parent) 00062 : KDialog(parent), 00063 d(new KSslInfoDialogPrivate) 00064 { 00065 setCaption(i18n("KDE SSL Information")); 00066 setAttribute(Qt::WA_DeleteOnClose); 00067 00068 d->ui.setupUi(mainWidget()); 00069 setButtons(KDialog::Close); 00070 00071 d->subject = new KSslCertificateBox(d->ui.certParties); 00072 d->issuer = new KSslCertificateBox(d->ui.certParties); 00073 d->ui.certParties->addTab(d->subject, i18nc("The receiver of the SSL certificate", "Subject")); 00074 d->ui.certParties->addTab(d->issuer, i18nc("The authority that issued the SSL certificate", "Issuer")); 00075 00076 d->isMainPartEncrypted = true; 00077 d->auxPartsEncrypted = true; 00078 updateWhichPartsEncrypted(); 00079 00080 #if 0 00081 if (KSSL::doesSSLWork()) { 00082 if (d->m_secCon) { 00083 d->pixmap->setPixmap(BarIcon("security-high")); 00084 d->info->setText(i18n("Current connection is secured with SSL.")); 00085 } else { 00086 d->pixmap->setPixmap(BarIcon("security-low")); 00087 d->info->setText(i18n("Current connection is not secured with SSL.")); 00088 } 00089 } else { 00090 d->pixmap->setPixmap(BarIcon("security-low")); 00091 d->info->setText(i18n("SSL support is not available in this build of KDE.")); 00092 } 00093 #endif 00094 } 00095 00096 00097 KSslInfoDialog::~KSslInfoDialog() 00098 { 00099 delete d; 00100 } 00101 00102 00103 //slot 00104 void KSslInfoDialog::launchConfig() 00105 { 00106 QProcess::startDetached("kcmshell4", QStringList() << "crypto"); 00107 } 00108 00109 00110 void KSslInfoDialog::setMainPartEncrypted(bool mainEncrypted) 00111 { 00112 d->isMainPartEncrypted = mainEncrypted; 00113 updateWhichPartsEncrypted(); 00114 } 00115 00116 00117 void KSslInfoDialog::setAuxiliaryPartsEncrypted(bool auxEncrypted) 00118 { 00119 d->auxPartsEncrypted = auxEncrypted; 00120 updateWhichPartsEncrypted(); 00121 } 00122 00123 00124 void KSslInfoDialog::updateWhichPartsEncrypted() 00125 { 00126 if (d->isMainPartEncrypted) { 00127 if (d->auxPartsEncrypted) { 00128 d->ui.encryptionIndicator->setPixmap(BarIcon("security-high")); 00129 d->ui.explanation->setText(i18n("Current connection is secured with SSL.")); 00130 } else { 00131 d->ui.encryptionIndicator->setPixmap(BarIcon("security-medium")); 00132 d->ui.explanation->setText(i18n("The main part of this document is secured " 00133 "with SSL, but some parts are not.")); 00134 } 00135 } else { 00136 if (d->auxPartsEncrypted) { 00137 d->ui.encryptionIndicator->setPixmap(BarIcon("security-medium")); 00138 d->ui.explanation->setText(i18n("Some of this document is secured with SSL, " 00139 "but the main part is not.")); 00140 } else { 00141 d->ui.encryptionIndicator->setPixmap(BarIcon("security-low")); 00142 d->ui.explanation->setText(i18n("Current connection is not secured with SSL.")); 00143 } 00144 } 00145 } 00146 00147 00148 void KSslInfoDialog::setSslInfo(const QList<QSslCertificate> &certificateChain, 00149 const QString &ip, const QString &host, 00150 const QString &sslProtocol, const QString &cipher, 00151 int usedBits, int bits, 00152 const QList<QList<KSslError::Error> > &validationErrors) { 00153 00154 d->certificateChain = certificateChain; 00155 d->certificateErrors = validationErrors; 00156 00157 d->ui.certSelector->clear(); 00158 for (int i = 0; i < certificateChain.size(); i++) { 00159 const QSslCertificate &cert = certificateChain[i]; 00160 QString name; 00161 static const QSslCertificate::SubjectInfo si[] = { 00162 QSslCertificate::CommonName, 00163 QSslCertificate::Organization, 00164 QSslCertificate::OrganizationalUnitName 00165 }; 00166 for (int j = 0; j < 3 && name.isEmpty(); j++) 00167 name = cert.subjectInfo(si[j]); 00168 d->ui.certSelector->addItem(name); 00169 } 00170 if (certificateChain.size() < 2) { 00171 d->ui.certSelector->setEnabled(false); 00172 } 00173 connect(d->ui.certSelector, SIGNAL(currentIndexChanged(int)), 00174 this, SLOT(displayFromChain(int))); 00175 if (d->certificateChain.isEmpty()) 00176 d->certificateChain.append(QSslCertificate()); 00177 displayFromChain(0); 00178 00179 d->ui.ip->setText(ip); 00180 d->ui.address->setText(host); 00181 d->ui.sslVersion->setText(sslProtocol); 00182 00183 const QStringList cipherInfo = cipher.split('\n', QString::SkipEmptyParts); 00184 if (cipherInfo.size() >= 4) { 00185 d->ui.encryption->setText(i18nc("%1, using %2 bits of a %3 bit key", "%1, %2 %3", cipherInfo[0], 00186 i18ncp("Part of: %1, using %2 bits of a %3 bit key", 00187 "using %1 bit", "using %1 bits", usedBits), 00188 i18ncp("Part of: %1, using %2 bits of a %3 bit key", 00189 "of a %1 bit key", "of a %1 bit key", bits))); 00190 d->ui.details->setText(QString("Auth = %1, Kx = %2, MAC = %3") 00191 .arg(cipherInfo[1], cipherInfo[2], 00192 cipherInfo[3])); 00193 } else { 00194 d->ui.encryption->setText(""); 00195 d->ui.details->setText(""); 00196 } 00197 } 00198 00199 00200 void KSslInfoDialog::displayFromChain(int i) 00201 { 00202 const QSslCertificate &cert = d->certificateChain[i]; 00203 00204 QString trusted; 00205 if (!d->certificateErrors[i].isEmpty()) { 00206 trusted = i18nc("The certificate is not trusted", "NO, there were errors:"); 00207 foreach (KSslError::Error e, d->certificateErrors[i]) { 00208 KSslError classError(e); 00209 trusted.append('\n'); 00210 trusted.append(classError.errorString()); 00211 } 00212 } else { 00213 trusted = i18nc("The certificate is trusted", "Yes"); 00214 } 00215 d->ui.trusted->setText(trusted); 00216 00217 QString vp = i18nc("%1 is the effective date of the certificate, %2 is the expiry date", "%1 to %2", 00218 KGlobal::locale()->formatDateTime(cert.effectiveDate()), 00219 KGlobal::locale()->formatDateTime(cert.expiryDate())); 00220 d->ui.validityPeriod->setText(vp); 00221 00222 d->ui.serial->setText(cert.serialNumber()); 00223 d->ui.digest->setText(cert.digest().toHex()); 00224 d->ui.sha1Digest->setText(cert.digest(QCryptographicHash::Sha1).toHex()); 00225 00226 d->subject->setCertificate(cert, KSslCertificateBox::Subject); 00227 d->issuer->setCertificate(cert, KSslCertificateBox::Issuer); 00228 } 00229 00230 00231 //static 00232 QList<QList<KSslError::Error> > KSslInfoDialog::errorsFromString(const QString &es) 00233 { 00234 QStringList sl = es.split('\n', QString::KeepEmptyParts); 00235 QList<QList<KSslError::Error> > ret; 00236 foreach (const QString &s, sl) { 00237 QList<KSslError::Error> certErrors; 00238 QStringList sl2 = s.split('\t', QString::SkipEmptyParts); 00239 foreach (const QString &s2, sl2) { 00240 bool didConvert; 00241 KSslError::Error error = static_cast<KSslError::Error>(s2.toInt(&didConvert)); 00242 if (didConvert) { 00243 certErrors.append(error); 00244 } 00245 } 00246 ret.append(certErrors); 00247 } 00248 return ret; 00249 } 00250 00251 #include "ksslinfodialog.moc"
KDE 4.7 API Reference