00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ksslinfodlg.h"
00023
00024 #include <kssl.h>
00025
00026 #include <qlayout.h>
00027 #include <kpushbutton.h>
00028 #include <qframe.h>
00029 #include <qlabel.h>
00030 #include <qscrollview.h>
00031 #include <qfile.h>
00032
00033 #include <kapplication.h>
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <kprocess.h>
00037 #include <kiconloader.h>
00038 #include <kglobalsettings.h>
00039 #include <ksqueezedtextlabel.h>
00040 #include <kurllabel.h>
00041 #include <kstdguiitem.h>
00042
00043
00044 #include <kcombobox.h>
00045 #include "ksslcertificate.h"
00046 #include "ksslcertchain.h"
00047 #include "ksslsigners.h"
00048
00049
00050 class KSSLInfoDlg::KSSLInfoDlgPrivate {
00051 private:
00052 friend class KSSLInfoDlg;
00053 bool m_secCon;
00054 QGridLayout *m_layout;
00055 KComboBox *_chain;
00056 KSSLCertificate *_cert;
00057 KSSLCertificate::KSSLValidationList _cert_ksvl;
00058
00059 bool inQuestion;
00060
00061 QLabel *_serialNum;
00062 QLabel *_csl;
00063 QLabel *_validFrom;
00064 QLabel *_validUntil;
00065 QLabel *_digest;
00066
00067 QLabel *pixmap;
00068 QLabel *info;
00069
00070 KSSLCertBox *_subject, *_issuer;
00071 };
00072
00073
00074
00075 KSSLInfoDlg::KSSLInfoDlg(bool secureConnection, QWidget *parent, const char *name, bool modal)
00076 : KDialog(parent, name, modal, Qt::WDestructiveClose), d(new KSSLInfoDlgPrivate) {
00077 QVBoxLayout *topLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
00078 d->m_secCon = secureConnection;
00079 d->m_layout = new QGridLayout(topLayout, 3, 3, KDialog::spacingHint());
00080 d->m_layout->setColStretch(1, 1);
00081 d->m_layout->setColStretch(2, 1);
00082
00083 d->pixmap = new QLabel(this);
00084 d->m_layout->addWidget(d->pixmap, 0, 0);
00085
00086 d->info = new QLabel(this);
00087 d->m_layout->addWidget(d->info, 0, 1);
00088
00089 if (KSSL::doesSSLWork()) {
00090 if (d->m_secCon) {
00091 d->pixmap->setPixmap(BarIcon("encrypted"));
00092 d->info->setText(i18n("Current connection is secured with SSL."));
00093 } else {
00094 d->pixmap->setPixmap(BarIcon("decrypted"));
00095 d->info->setText(i18n("Current connection is not secured with SSL."));
00096 }
00097 } else {
00098 d->pixmap->setPixmap(BarIcon("decrypted"));
00099 d->info->setText(i18n("SSL support is not available in this build of KDE."));
00100 }
00101 d->m_layout->addRowSpacing( 0, 50 );
00102
00103 QHBoxLayout *buttonLayout = new QHBoxLayout(topLayout, KDialog::spacingHint());
00104 buttonLayout->addStretch( 1 );
00105
00106 KPushButton *button;
00107
00108 if (KSSL::doesSSLWork()) {
00109 button = new KPushButton(KGuiItem(i18n("C&ryptography Configuration..."),"configure"), this);
00110 connect(button, SIGNAL(clicked()), SLOT(launchConfig()));
00111 buttonLayout->addWidget( button );
00112 }
00113
00114 button = new KPushButton(KStdGuiItem::close(), this);
00115 connect(button, SIGNAL(clicked()), SLOT(close()));
00116 buttonLayout->addWidget( button );
00117
00118 button->setFocus();
00119
00120 setCaption(i18n("KDE SSL Information"));
00121 d->inQuestion = false;
00122 }
00123
00124
00125 KSSLInfoDlg::~KSSLInfoDlg() {
00126 delete d;
00127 }
00128
00129 void KSSLInfoDlg::launchConfig() {
00130 KProcess p;
00131 p << "kcmshell" << "crypto";
00132 p.start(KProcess::DontCare);
00133 }
00134
00135
00136 void KSSLInfoDlg::setSecurityInQuestion(bool isIt) {
00137 d->inQuestion = isIt;
00138 if (KSSL::doesSSLWork())
00139 if (isIt) {
00140 d->pixmap->setPixmap(BarIcon("halfencrypted"));
00141 if (d->m_secCon) {
00142 d->info->setText(i18n("The main part of this document is secured with SSL, but some parts are not."));
00143 } else {
00144 d->info->setText(i18n("Some of this document is secured with SSL, but the main part is not."));
00145 }
00146 } else {
00147 if (d->m_secCon) {
00148 d->pixmap->setPixmap(BarIcon("encrypted"));
00149 d->info->setText(i18n("Current connection is secured with SSL."));
00150 } else {
00151 d->pixmap->setPixmap(BarIcon("decrypted"));
00152 d->info->setText(i18n("Current connection is not secured with SSL."));
00153 }
00154 }
00155 }
00156
00157
00158 void KSSLInfoDlg::setup( KSSL & ssl, const QString & ip, const QString & url )
00159 {
00160 setup(
00161 &ssl.peerInfo().getPeerCertificate(),
00162 ip,
00163 url,
00164 ssl.connectionInfo().getCipher(),
00165 ssl.connectionInfo().getCipherDescription(),
00166 ssl.connectionInfo().getCipherVersion(),
00167 ssl.connectionInfo().getCipherUsedBits(),
00168 ssl.connectionInfo().getCipherBits(),
00169 ssl.peerInfo().getPeerCertificate().validate()
00170 );
00171 }
00172
00173 void KSSLInfoDlg::setup(KSSLCertificate *cert,
00174 const QString& ip, const QString& url,
00175 const QString& cipher, const QString& cipherdesc,
00176 const QString& sslversion, int usedbits, int bits,
00177 KSSLCertificate::KSSLValidation ) {
00178
00179
00180 d->_cert = cert;
00181
00182 QGridLayout *layout = new QGridLayout(4, 2, KDialog::spacingHint());
00183
00184 layout->addWidget(new QLabel(i18n("Chain:"), this), 0, 0);
00185 d->_chain = new KComboBox(this);
00186 layout->addMultiCellWidget(d->_chain, 1, 1, 0, 1);
00187 connect(d->_chain, SIGNAL(activated(int)), this, SLOT(slotChain(int)));
00188
00189 d->_chain->clear();
00190
00191 if (cert->chain().isValid() && cert->chain().depth() > 1) {
00192 d->_chain->setEnabled(true);
00193 d->_chain->insertItem(i18n("0 - Site Certificate"));
00194 int cnt = 0;
00195 QPtrList<KSSLCertificate> cl = cert->chain().getChain();
00196 for (KSSLCertificate *c = cl.first(); c != 0; c = cl.next()) {
00197 KSSLX509Map map(c->getSubject());
00198 QString id;
00199 id = map.getValue("CN");
00200 if (id.length() == 0)
00201 id = map.getValue("O");
00202 if (id.length() == 0)
00203 id = map.getValue("OU");
00204 d->_chain->insertItem(QString::number(++cnt)+" - "+id);
00205 }
00206 d->_chain->setCurrentItem(0);
00207 } else d->_chain->setEnabled(false);
00208
00209 layout->addWidget(new QLabel(i18n("Peer certificate:"), this), 2, 0);
00210 layout->addWidget(d->_subject = static_cast<KSSLCertBox*>(buildCertInfo(cert->getSubject())), 3, 0);
00211 layout->addWidget(new QLabel(i18n("Issuer:"), this), 2, 1);
00212 layout->addWidget(d->_issuer = static_cast<KSSLCertBox*>(buildCertInfo(cert->getIssuer())), 3, 1);
00213 d->m_layout->addMultiCell(layout, 1, 1, 0, 2);
00214
00215 layout = new QGridLayout(11, 2, KDialog::spacingHint());
00216 layout->setColStretch(1, 1);
00217 QLabel *ipl = new QLabel(i18n("IP address:"), this);
00218 layout->addWidget(ipl, 0, 0);
00219 if (ip.isEmpty()) {
00220 ipl->hide();
00221 }
00222 layout->addWidget(ipl = new QLabel(ip, this), 0, 1);
00223 if (ip.isEmpty()) {
00224 ipl->hide();
00225 }
00226 layout->addWidget(new QLabel(i18n("URL:"), this), 1, 0);
00227 KSqueezedTextLabel *urlLabel = new KSqueezedTextLabel(url, this);
00228 layout->addWidget(urlLabel, 1, 1);
00229 layout->addWidget(new QLabel(i18n("Certificate state:"), this), 2, 0);
00230
00231 layout->addWidget(d->_csl = new QLabel("", this), 2, 1);
00232
00233 update();
00234
00235 layout->addWidget(new QLabel(i18n("Valid from:"), this), 3, 0);
00236 layout->addWidget(d->_validFrom = new QLabel("", this), 3, 1);
00237 layout->addWidget(new QLabel(i18n("Valid until:"), this), 4, 0);
00238 layout->addWidget(d->_validUntil = new QLabel("", this), 4, 1);
00239
00240 layout->addWidget(new QLabel(i18n("Serial number:"), this), 5, 0);
00241 layout->addWidget(d->_serialNum = new QLabel("", this), 5, 1);
00242 layout->addWidget(new QLabel(i18n("MD5 digest:"), this), 6, 0);
00243 layout->addWidget(d->_digest = new QLabel("", this), 6, 1);
00244
00245 layout->addWidget(new QLabel(i18n("Cipher in use:"), this), 7, 0);
00246 layout->addWidget(new QLabel(cipher, this), 7, 1);
00247 layout->addWidget(new QLabel(i18n("Details:"), this), 8, 0);
00248 layout->addWidget(new QLabel(cipherdesc.simplifyWhiteSpace(), this), 8, 1);
00249 layout->addWidget(new QLabel(i18n("SSL version:"), this), 9, 0);
00250 layout->addWidget(new QLabel(sslversion, this), 9, 1);
00251 layout->addWidget(new QLabel(i18n("Cipher strength:"), this), 10, 0);
00252 layout->addWidget(new QLabel(i18n("%1 bits used of a %2 bit cipher").arg(usedbits).arg(bits), this), 10, 1);
00253 d->m_layout->addMultiCell(layout, 2, 2, 0, 2);
00254
00255 ipl->setTextFormat(Qt::PlainText);
00256 urlLabel->setTextFormat(Qt::PlainText);
00257 d->_serialNum->setTextFormat(Qt::PlainText);
00258 d->_csl->setTextFormat(Qt::PlainText);
00259 d->_validFrom->setTextFormat(Qt::PlainText);
00260 d->_validUntil->setTextFormat(Qt::PlainText);
00261 d->_digest->setTextFormat(Qt::PlainText);
00262
00263 displayCert(cert);
00264 }
00265
00266 void KSSLInfoDlg::setCertState(const QString &errorNrs)
00267 {
00268 d->_cert_ksvl.clear();
00269 QStringList errors = QStringList::split(':', errorNrs);
00270 for(QStringList::ConstIterator it = errors.begin();
00271 it != errors.end(); ++it)
00272 {
00273 d->_cert_ksvl << (KSSLCertificate::KSSLValidation) (*it).toInt();
00274 }
00275 }
00276
00277 void KSSLInfoDlg::displayCert(KSSLCertificate *x) {
00278 QPalette cspl;
00279
00280 d->_serialNum->setText(x->getSerialNumber());
00281
00282 cspl = d->_validFrom->palette();
00283 if (x->getQDTNotBefore() > QDateTime::currentDateTime(Qt::UTC))
00284 cspl.setColor(QColorGroup::Foreground, QColor(196,33,21));
00285 else cspl.setColor(QColorGroup::Foreground, QColor(42,153,59));
00286 d->_validFrom->setPalette(cspl);
00287 d->_validFrom->setText(x->getNotBefore());
00288
00289 cspl = d->_validUntil->palette();
00290 if (x->getQDTNotAfter() < QDateTime::currentDateTime(Qt::UTC))
00291 cspl.setColor(QColorGroup::Foreground, QColor(196,33,21));
00292 else cspl.setColor(QColorGroup::Foreground, QColor(42,153,59));
00293 d->_validUntil->setPalette(cspl);
00294 d->_validUntil->setText(x->getNotAfter());
00295
00296 cspl = palette();
00297
00298 KSSLCertificate::KSSLValidation ksv;
00299 KSSLCertificate::KSSLValidationList ksvl;
00300 if ((x == d->_cert) && !d->_cert_ksvl.isEmpty()) {
00301 ksvl = d->_cert_ksvl;
00302 ksv = ksvl.first();
00303 } else {
00304 if (x == d->_cert)
00305 ksvl = d->_cert->validateVerbose(KSSLCertificate::SSLServer);
00306 else
00307 ksvl = d->_cert->validateVerbose(KSSLCertificate::SSLServer, x);
00308
00309 if (ksvl.isEmpty())
00310 ksvl << KSSLCertificate::Ok;
00311
00312 ksv = ksvl.first();
00313
00314 if (ksv == KSSLCertificate::SelfSigned) {
00315 if (x->getQDTNotAfter() > QDateTime::currentDateTime(Qt::UTC) &&
00316 x->getQDTNotBefore() < QDateTime::currentDateTime(Qt::UTC)) {
00317 if (KSSLSigners().useForSSL(*x))
00318 ksv = KSSLCertificate::Ok;
00319 } else {
00320 ksv = KSSLCertificate::Expired;
00321 }
00322 }
00323 }
00324
00325 if (ksv == KSSLCertificate::Ok) {
00326 cspl.setColor(QColorGroup::Foreground, QColor(42,153,59));
00327 } else if (ksv != KSSLCertificate::Irrelevant) {
00328 cspl.setColor(QColorGroup::Foreground, QColor(196,33,21));
00329 }
00330 d->_csl->setPalette(cspl);
00331
00332 QString errorStr;
00333 for(KSSLCertificate::KSSLValidationList::ConstIterator it = ksvl.begin();
00334 it != ksvl.end(); ++it) {
00335 if (!errorStr.isEmpty())
00336 errorStr.append('\n');
00337 errorStr += KSSLCertificate::verifyText(*it);
00338 }
00339
00340 d->_csl->setText(errorStr);
00341 d->_csl->setMinimumSize(d->_csl->sizeHint());
00342
00343 d->_subject->setValues(x->getSubject());
00344 d->_issuer->setValues(x->getIssuer());
00345
00346 d->_digest->setText(x->getMD5DigestText());
00347 }
00348
00349
00350 void KSSLInfoDlg::slotChain(int x) {
00351 if (x == 0) {
00352 displayCert(d->_cert);
00353 } else {
00354 QPtrList<KSSLCertificate> cl = d->_cert->chain().getChain();
00355 cl.setAutoDelete(true);
00356 for (int i = 0; i < x-1; i++)
00357 cl.remove((unsigned int)0);
00358 KSSLCertificate thisCert = *(cl.at(0));
00359 cl.remove((unsigned int)0);
00360 thisCert.chain().setChain(cl);
00361 displayCert(&thisCert);
00362 }
00363 }
00364
00365
00366 KSSLCertBox *KSSLInfoDlg::certInfoWidget(QWidget *parent, const QString &certName, QWidget *mailCatcher) {
00367 KSSLCertBox *result = new KSSLCertBox(parent);
00368 if (!certName.isEmpty()) {
00369 result->setValues(certName, mailCatcher);
00370 }
00371 return result;
00372 }
00373
00374
00375 KSSLCertBox::KSSLCertBox(QWidget *parent, const char *name, WFlags f)
00376 : QScrollView(parent, name, f)
00377 {
00378 _frame = 0L;
00379 setBackgroundMode(QWidget::PaletteButton);
00380 setValues(QString::null, 0L);
00381 }
00382
00383
00384 void KSSLCertBox::setValues(QString certName, QWidget *mailCatcher) {
00385 if (_frame) {
00386 removeChild(_frame);
00387 delete _frame;
00388 }
00389
00390 if (certName.isEmpty()) {
00391 _frame = new QFrame(this);
00392 addChild(_frame);
00393 viewport()->setBackgroundMode(_frame->backgroundMode());
00394 _frame->show();
00395 updateScrollBars();
00396 show();
00397 return;
00398 }
00399
00400 KSSLX509Map cert(certName);
00401 QString tmp;
00402 viewport()->setBackgroundMode(QWidget::PaletteButton);
00403 _frame = new QFrame(this);
00404 QGridLayout *grid = new QGridLayout(_frame, 1, 2, KDialog::marginHint(), KDialog::spacingHint());
00405 grid->setAutoAdd(true);
00406 QLabel *label = 0L;
00407 if (!(tmp = cert.getValue("O")).isEmpty()) {
00408 label = new QLabel(i18n("Organization:"), _frame);
00409 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00410 (new QLabel(tmp, _frame))->setTextFormat(Qt::PlainText);
00411 }
00412 if (!(tmp = cert.getValue("OU")).isEmpty()) {
00413 label = new QLabel(i18n("Organizational unit:"), _frame);
00414 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00415 (new QLabel(tmp, _frame))->setTextFormat(Qt::PlainText);
00416 }
00417 if (!(tmp = cert.getValue("L")).isEmpty()) {
00418 label = new QLabel(i18n("Locality:"), _frame);
00419 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00420 (new QLabel(tmp, _frame))->setTextFormat(Qt::PlainText);
00421 }
00422 if (!(tmp = cert.getValue("ST")).isEmpty()) {
00423 label = new QLabel(i18n("Federal State","State:"), _frame);
00424 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00425 (new QLabel(tmp, _frame))->setTextFormat(Qt::PlainText);
00426 }
00427 if (!(tmp = cert.getValue("C")).isEmpty()) {
00428 label = new QLabel(i18n("Country:"), _frame);
00429 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00430 (new QLabel(tmp, _frame))->setTextFormat(Qt::PlainText);
00431 }
00432 if (!(tmp = cert.getValue("CN")).isEmpty()) {
00433 label = new QLabel(i18n("Common name:"), _frame);
00434 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00435 (new QLabel(tmp, _frame))->setTextFormat(Qt::PlainText);
00436 }
00437 if (!(tmp = cert.getValue("Email")).isEmpty()) {
00438 label = new QLabel(i18n("Email:"), _frame);
00439 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00440 if (mailCatcher) {
00441 KURLLabel *mail = new KURLLabel(tmp, tmp, _frame);
00442 connect(mail, SIGNAL(leftClickedURL(const QString &)), mailCatcher, SLOT(mailClicked(const QString &)));
00443 } else {
00444 label = new QLabel(tmp, _frame);
00445 label->setTextFormat(Qt::PlainText);
00446 }
00447 }
00448 if (label && viewport()) {
00449 viewport()->setBackgroundMode(label->backgroundMode());
00450 }
00451 addChild(_frame);
00452 updateScrollBars();
00453 _frame->show();
00454 show();
00455 }
00456
00457
00458 QScrollView *KSSLInfoDlg::buildCertInfo(const QString &certName) {
00459 return KSSLInfoDlg::certInfoWidget(this, certName, this);
00460 }
00461
00462 void KSSLInfoDlg::urlClicked(const QString &url) {
00463 kapp->invokeBrowser(url);
00464 }
00465
00466 void KSSLInfoDlg::mailClicked(const QString &url) {
00467 kapp->invokeMailer(url, QString::null);
00468 }
00469
00470 #include "ksslinfodlg.moc"
00471