• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/kssl
 

tdeio/kssl

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

tdeio/kssl

Skip menu "tdeio/kssl"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/kssl

Skip menu "tdeio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/kssl by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.