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

tdeio/kssl

  • tdeio
  • kssl
ksslinfodlg.cc
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
4  * Copyright (C) 2000 Malte Starostik <malte@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "ksslinfodlg.h"
23 
24 #include <kssl.h>
25 
26 #include <tqlayout.h>
27 #include <kpushbutton.h>
28 #include <tqframe.h>
29 #include <tqlabel.h>
30 #include <tqscrollview.h>
31 #include <tqfile.h>
32 
33 #include <tdeapplication.h>
34 #include <tdeglobal.h>
35 #include <tdelocale.h>
36 #include <kprocess.h>
37 #include <kiconloader.h>
38 #include <tdeglobalsettings.h>
39 #include <ksqueezedtextlabel.h>
40 #include <kurllabel.h>
41 #include <kstdguiitem.h>
42 //#include <kstandarddirs.h>
43 //#include <krun.h>
44 #include <kcombobox.h>
45 #include "ksslcertificate.h"
46 #include "ksslcertchain.h"
47 #include "ksslsigners.h"
48 
49 
50 class KSSLInfoDlg::KSSLInfoDlgPrivate {
51  private:
52  friend class KSSLInfoDlg;
53  bool m_secCon;
54  TQGridLayout *m_layout;
55  KComboBox *_chain;
56  KSSLCertificate *_cert;
57  KSSLCertificate::KSSLValidationList _cert_ksvl;
58 
59  bool inQuestion;
60 
61  TQLabel *_serialNum;
62  TQLabel *_csl;
63  TQLabel *_validFrom;
64  TQLabel *_validUntil;
65  TQLabel *_digest;
66 
67  TQLabel *pixmap;
68  TQLabel *info;
69 
70  KSSLCertBox *_subject, *_issuer;
71 };
72 
73 
74 
75 KSSLInfoDlg::KSSLInfoDlg(bool secureConnection, TQWidget *parent, const char *name, bool modal)
76  : KDialog(parent, name, modal, (WFlags)TQt::WDestructiveClose), d(new KSSLInfoDlgPrivate) {
77  TQVBoxLayout *topLayout = new TQVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
78  d->m_secCon = secureConnection;
79  d->m_layout = new TQGridLayout(topLayout, 3, 3, KDialog::spacingHint());
80  d->m_layout->setColStretch(1, 1);
81  d->m_layout->setColStretch(2, 1);
82 
83  d->pixmap = new TQLabel(this);
84  d->m_layout->addWidget(d->pixmap, 0, 0);
85 
86  d->info = new TQLabel(this);
87  d->m_layout->addWidget(d->info, 0, 1);
88 
89  if (KSSL::doesSSLWork()) {
90  if (d->m_secCon) {
91  d->pixmap->setPixmap(BarIcon("encrypted"));
92  d->info->setText(i18n("Current connection is secured with SSL."));
93  } else {
94  d->pixmap->setPixmap(BarIcon("decrypted"));
95  d->info->setText(i18n("Current connection is not secured with SSL."));
96  }
97  } else {
98  d->pixmap->setPixmap(BarIcon("decrypted"));
99  d->info->setText(i18n("SSL support is not available in this build of TDE."));
100  }
101  d->m_layout->addRowSpacing( 0, 50 ); // give minimum height to look better
102 
103  TQHBoxLayout *buttonLayout = new TQHBoxLayout(topLayout, KDialog::spacingHint());
104  buttonLayout->addStretch( 1 );
105 
106  KPushButton *button;
107 
108  if (KSSL::doesSSLWork()) {
109  button = new KPushButton(KGuiItem(i18n("C&ryptography Configuration..."),"configure"), this);
110  connect(button, TQT_SIGNAL(clicked()), TQT_SLOT(launchConfig()));
111  buttonLayout->addWidget( button );
112  }
113 
114  button = new KPushButton(KStdGuiItem::close(), this);
115  connect(button, TQT_SIGNAL(clicked()), TQT_SLOT(close()));
116  buttonLayout->addWidget( button );
117 
118  button->setFocus();
119 
120  setCaption(i18n("TDE SSL Information"));
121  d->inQuestion = false;
122  }
123 
124 
125 KSSLInfoDlg::~KSSLInfoDlg() {
126  delete d;
127 }
128 
129 void KSSLInfoDlg::launchConfig() {
130  TDEProcess p;
131  p << "tdecmshell" << "crypto";
132  p.start(TDEProcess::DontCare);
133 }
134 
135 
136 void KSSLInfoDlg::setSecurityInQuestion(bool isIt) {
137  d->inQuestion = isIt;
138  if (KSSL::doesSSLWork())
139  if (isIt) {
140  d->pixmap->setPixmap(BarIcon("halfencrypted"));
141  if (d->m_secCon) {
142  d->info->setText(i18n("The main part of this document is secured with SSL, but some parts are not."));
143  } else {
144  d->info->setText(i18n("Some of this document is secured with SSL, but the main part is not."));
145  }
146  } else {
147  if (d->m_secCon) {
148  d->pixmap->setPixmap(BarIcon("encrypted"));
149  d->info->setText(i18n("Current connection is secured with SSL."));
150  } else {
151  d->pixmap->setPixmap(BarIcon("decrypted"));
152  d->info->setText(i18n("Current connection is not secured with SSL."));
153  }
154  }
155 }
156 
157 
158 void KSSLInfoDlg::setup( KSSL & ssl, const TQString & ip, const TQString & url )
159 {
160  setup(
161  &ssl.peerInfo().getPeerCertificate(),
162  ip,
163  url,
164  ssl.connectionInfo().getCipher(),
165  ssl.connectionInfo().getCipherDescription(),
166  ssl.connectionInfo().getCipherVersion(),
167  ssl.connectionInfo().getCipherUsedBits(),
168  ssl.connectionInfo().getCipherBits(),
169  ssl.peerInfo().getPeerCertificate().validate()
170  );
171 }
172 
173 void KSSLInfoDlg::setup(KSSLCertificate *cert,
174  const TQString& ip, const TQString& url,
175  const TQString& cipher, const TQString& cipherdesc,
176  const TQString& sslversion, int usedbits, int bits,
177  KSSLCertificate::KSSLValidation /*certState*/) {
178  // Needed to put the GUI stuff here to get the layouting right
179 
180  d->_cert = cert;
181 
182  TQGridLayout *layout = new TQGridLayout(4, 2, KDialog::spacingHint());
183 
184  layout->addWidget(new TQLabel(i18n("Chain:"), this), 0, 0);
185  d->_chain = new KComboBox(this);
186  layout->addMultiCellWidget(d->_chain, 1, 1, 0, 1);
187  connect(d->_chain, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotChain(int)));
188 
189  d->_chain->clear();
190 
191  if (cert->chain().isValid() && cert->chain().depth() > 1) {
192  d->_chain->setEnabled(true);
193  d->_chain->insertItem(i18n("0 - Site Certificate"));
194  int cnt = 0;
195  TQPtrList<KSSLCertificate> cl = cert->chain().getChain();
196  cl.setAutoDelete(true);
197  for (KSSLCertificate *c = cl.first(); c != 0; c = cl.next()) {
198  KSSLX509Map map(c->getSubject());
199  TQString id;
200  id = map.getValue("CN");
201  if (id.length() == 0)
202  id = map.getValue("O");
203  if (id.length() == 0)
204  id = map.getValue("OU");
205  d->_chain->insertItem(TQString::number(++cnt)+" - "+id);
206  }
207  d->_chain->setCurrentItem(0);
208  } else d->_chain->setEnabled(false);
209 
210  layout->addWidget(new TQLabel(i18n("Peer certificate:"), this), 2, 0);
211  layout->addWidget(d->_subject = static_cast<KSSLCertBox*>(buildCertInfo(cert->getSubject())), 3, 0);
212  layout->addWidget(new TQLabel(i18n("Issuer:"), this), 2, 1);
213  layout->addWidget(d->_issuer = static_cast<KSSLCertBox*>(buildCertInfo(cert->getIssuer())), 3, 1);
214  d->m_layout->addMultiCell(layout, 1, 1, 0, 2);
215 
216  layout = new TQGridLayout(11, 2, KDialog::spacingHint());
217  layout->setColStretch(1, 1);
218  TQLabel *ipl = new TQLabel(i18n("IP address:"), this);
219  layout->addWidget(ipl, 0, 0);
220  if (ip.isEmpty()) {
221  ipl->hide();
222  }
223  layout->addWidget(ipl = new TQLabel(ip, this), 0, 1);
224  if (ip.isEmpty()) {
225  ipl->hide();
226  }
227  layout->addWidget(new TQLabel(i18n("URL:"), this), 1, 0);
228  KSqueezedTextLabel *urlLabel = new KSqueezedTextLabel(url, this);
229  layout->addWidget(urlLabel, 1, 1);
230  layout->addWidget(new TQLabel(i18n("Certificate state:"), this), 2, 0);
231 
232  layout->addWidget(d->_csl = new TQLabel("", this), 2, 1);
233 
234  update();
235 
236  layout->addWidget(new TQLabel(i18n("Valid from:"), this), 3, 0);
237  layout->addWidget(d->_validFrom = new TQLabel("", this), 3, 1);
238  layout->addWidget(new TQLabel(i18n("Valid until:"), this), 4, 0);
239  layout->addWidget(d->_validUntil = new TQLabel("", this), 4, 1);
240 
241  layout->addWidget(new TQLabel(i18n("Serial number:"), this), 5, 0);
242  layout->addWidget(d->_serialNum = new TQLabel("", this), 5, 1);
243  layout->addWidget(new TQLabel(i18n("MD5 digest:"), this), 6, 0);
244  layout->addWidget(d->_digest = new TQLabel("", this), 6, 1);
245 
246  layout->addWidget(new TQLabel(i18n("Cipher in use:"), this), 7, 0);
247  layout->addWidget(new TQLabel(cipher, this), 7, 1);
248  layout->addWidget(new TQLabel(i18n("Details:"), this), 8, 0);
249  layout->addWidget(new TQLabel(cipherdesc.simplifyWhiteSpace(), this), 8, 1);
250  layout->addWidget(new TQLabel(i18n("SSL version:"), this), 9, 0);
251  layout->addWidget(new TQLabel(sslversion, this), 9, 1);
252  layout->addWidget(new TQLabel(i18n("Cipher strength:"), this), 10, 0);
253  layout->addWidget(new TQLabel(i18n("%1 bits used of a %2 bit cipher").arg(usedbits).arg(bits), this), 10, 1);
254  d->m_layout->addMultiCell(layout, 2, 2, 0, 2);
255 
256  displayCert(cert);
257 }
258 
259 void KSSLInfoDlg::setCertState(const TQString &errorNrs)
260 {
261  d->_cert_ksvl.clear();
262  TQStringList errors = TQStringList::split(':', errorNrs);
263  for(TQStringList::ConstIterator it = errors.begin();
264  it != errors.end(); ++it)
265  {
266  d->_cert_ksvl << (KSSLCertificate::KSSLValidation) (*it).toInt();
267  }
268 }
269 
270 void KSSLInfoDlg::displayCert(KSSLCertificate *x) {
271  TQPalette cspl;
272 
273  d->_serialNum->setText(x->getSerialNumber());
274 
275  cspl = d->_validFrom->palette();
276  if (x->getQDTNotBefore() > TQDateTime::currentDateTime(Qt::UTC))
277  cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
278  else cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
279  d->_validFrom->setPalette(cspl);
280  d->_validFrom->setText(x->getNotBefore());
281 
282  cspl = d->_validUntil->palette();
283  if (x->getQDTNotAfter() < TQDateTime::currentDateTime(Qt::UTC))
284  cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
285  else cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
286  d->_validUntil->setPalette(cspl);
287  d->_validUntil->setText(x->getNotAfter());
288 
289  cspl = palette();
290 
291  KSSLCertificate::KSSLValidation ksv;
292  KSSLCertificate::KSSLValidationList ksvl;
293  if ((x == d->_cert) && !d->_cert_ksvl.isEmpty()) {
294  ksvl = d->_cert_ksvl;
295  ksv = ksvl.first();
296  } else {
297  if (x == d->_cert)
298  ksvl = d->_cert->validateVerbose(KSSLCertificate::SSLServer);
299  else
300  ksvl = d->_cert->validateVerbose(KSSLCertificate::SSLServer, x);
301 
302  if (ksvl.isEmpty())
303  ksvl << KSSLCertificate::Ok;
304 
305  ksv = ksvl.first();
306 
307  if (ksv == KSSLCertificate::SelfSigned) {
308  if (x->getQDTNotAfter() > TQDateTime::currentDateTime(Qt::UTC) &&
309  x->getQDTNotBefore() < TQDateTime::currentDateTime(Qt::UTC)) {
310  if (KSSLSigners().useForSSL(*x))
311  ksv = KSSLCertificate::Ok;
312  } else {
313  ksv = KSSLCertificate::Expired;
314  }
315  }
316  }
317 
318  if (ksv == KSSLCertificate::Ok) {
319  cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
320  } else if (ksv != KSSLCertificate::Irrelevant) {
321  cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
322  }
323  d->_csl->setPalette(cspl);
324 
325  TQString errorStr;
326  for(KSSLCertificate::KSSLValidationList::ConstIterator it = ksvl.begin();
327  it != ksvl.end(); ++it) {
328  if (!errorStr.isEmpty())
329  errorStr.append('\n');
330  errorStr += KSSLCertificate::verifyText(*it);
331  }
332 
333  d->_csl->setText(errorStr);
334  d->_csl->setMinimumSize(d->_csl->sizeHint());
335 
336  d->_subject->setValues(x->getSubject());
337  d->_issuer->setValues(x->getIssuer());
338 
339  d->_digest->setText(x->getMD5DigestText());
340 }
341 
342 
343 void KSSLInfoDlg::slotChain(int x) {
344  if (x == 0) {
345  displayCert(d->_cert);
346  } else {
347  TQPtrList<KSSLCertificate> cl = d->_cert->chain().getChain();
348  cl.setAutoDelete(true);
349  for (int i = 0; i < x-1; i++)
350  cl.remove((unsigned int)0);
351  KSSLCertificate thisCert = *(cl.at(0));
352  cl.remove((unsigned int)0);
353  thisCert.chain().setChain(cl);
354  displayCert(&thisCert);
355  }
356 }
357 
358 
359 KSSLCertBox *KSSLInfoDlg::certInfoWidget(TQWidget *parent, const TQString &certName, TQWidget *mailCatcher) {
360  KSSLCertBox *result = new KSSLCertBox(parent);
361  if (!certName.isEmpty()) {
362  result->setValues(certName, mailCatcher);
363  }
364  return result;
365 }
366 
367 
368 KSSLCertBox::KSSLCertBox(TQWidget *parent, const char *name, WFlags f)
369 : TQScrollView(parent, name, f)
370 {
371  _frame = 0L;
372  setBackgroundMode(TQWidget::PaletteButton);
373  setValues(TQString::null, 0L);
374 }
375 
376 
377 void KSSLCertBox::setValues(TQString certName, TQWidget *mailCatcher) {
378  if (_frame) {
379  removeChild(_frame);
380  delete _frame;
381  }
382 
383  if (certName.isEmpty()) {
384  _frame = new TQFrame(this);
385  addChild(_frame);
386  viewport()->setBackgroundMode(_frame->backgroundMode());
387  _frame->show();
388  updateScrollBars();
389  show();
390  return;
391  }
392 
393  KSSLX509Map cert(certName);
394  TQString tmp;
395  viewport()->setBackgroundMode(TQWidget::PaletteButton);
396  _frame = new TQFrame(this);
397  TQGridLayout *grid = new TQGridLayout(_frame, 1, 2, KDialog::marginHint(), KDialog::spacingHint());
398  grid->setAutoAdd(true);
399  TQLabel *label = 0L;
400  if (!(tmp = cert.getValue("O")).isEmpty()) {
401  label = new TQLabel(i18n("Organization:"), _frame);
402  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
403  new TQLabel(tmp, _frame);
404  }
405  if (!(tmp = cert.getValue("OU")).isEmpty()) {
406  label = new TQLabel(i18n("Organizational unit:"), _frame);
407  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
408  new TQLabel(tmp, _frame);
409  }
410  if (!(tmp = cert.getValue("L")).isEmpty()) {
411  label = new TQLabel(i18n("Locality:"), _frame);
412  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
413  new TQLabel(tmp, _frame);
414  }
415  if (!(tmp = cert.getValue("ST")).isEmpty()) {
416  label = new TQLabel(i18n("Federal State","State:"), _frame);
417  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
418  new TQLabel(tmp, _frame);
419  }
420  if (!(tmp = cert.getValue("C")).isEmpty()) {
421  label = new TQLabel(i18n("Country:"), _frame);
422  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
423  new TQLabel(tmp, _frame);
424  }
425  if (!(tmp = cert.getValue("CN")).isEmpty()) {
426  label = new TQLabel(i18n("Common name:"), _frame);
427  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
428  new TQLabel(tmp, _frame);
429  }
430  if (!(tmp = cert.getValue("Email")).isEmpty()) {
431  label = new TQLabel(i18n("Email:"), _frame);
432  label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
433  if (mailCatcher) {
434  KURLLabel *mail = new KURLLabel(tmp, tmp, _frame);
435  connect(mail, TQT_SIGNAL(leftClickedURL(const TQString &)), mailCatcher, TQT_SLOT(mailClicked(const TQString &)));
436  } else {
437  label = new TQLabel(tmp, _frame);
438  }
439  }
440  if (label && viewport()) {
441  viewport()->setBackgroundMode(label->backgroundMode());
442  }
443  addChild(_frame);
444  updateScrollBars();
445  _frame->show();
446  show();
447 }
448 
449 
450 TQScrollView *KSSLInfoDlg::buildCertInfo(const TQString &certName) {
451  return KSSLInfoDlg::certInfoWidget(this, certName, this);
452 }
453 
454 void KSSLInfoDlg::urlClicked(const TQString &url) {
455  kapp->invokeBrowser(url);
456 }
457 
458 void KSSLInfoDlg::mailClicked(const TQString &url) {
459  kapp->invokeMailer(url, TQString::null);
460 }
461 
462 #include "ksslinfodlg.moc"
463 // vim: ts=4 sw=4 et

tdeio/kssl

Skip menu "tdeio/kssl"
  • Main Page
  • 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
  • knewstuff
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/kssl by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.