22 #include "ksslinfodlg.h"
27 #include <kpushbutton.h>
30 #include <tqscrollview.h>
33 #include <tdeapplication.h>
34 #include <tdeglobal.h>
35 #include <tdelocale.h>
37 #include <kiconloader.h>
38 #include <tdeglobalsettings.h>
39 #include <ksqueezedtextlabel.h>
40 #include <kurllabel.h>
41 #include <kstdguiitem.h>
44 #include <kcombobox.h>
45 #include "ksslcertificate.h"
46 #include "ksslcertchain.h"
47 #include "ksslsigners.h"
50 class KSSLInfoDlg::KSSLInfoDlgPrivate {
54 TQGridLayout *m_layout;
57 KSSLCertificate::KSSLValidationList _cert_ksvl;
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);
83 d->pixmap =
new TQLabel(
this);
84 d->m_layout->addWidget(d->pixmap, 0, 0);
86 d->info =
new TQLabel(
this);
87 d->m_layout->addWidget(d->info, 0, 1);
91 d->pixmap->setPixmap(BarIcon(
"encrypted"));
92 d->info->setText(i18n(
"Current connection is secured with SSL."));
94 d->pixmap->setPixmap(BarIcon(
"decrypted"));
95 d->info->setText(i18n(
"Current connection is not secured with SSL."));
98 d->pixmap->setPixmap(BarIcon(
"decrypted"));
99 d->info->setText(i18n(
"SSL support is not available in this build of TDE."));
101 d->m_layout->addRowSpacing( 0, 50 );
103 TQHBoxLayout *buttonLayout =
new TQHBoxLayout(topLayout, KDialog::spacingHint());
104 buttonLayout->addStretch( 1 );
109 button =
new KPushButton(KGuiItem(i18n(
"C&ryptography Configuration..."),
"configure"),
this);
110 connect(button, TQT_SIGNAL(clicked()), TQT_SLOT(launchConfig()));
111 buttonLayout->addWidget( button );
114 button =
new KPushButton(KStdGuiItem::close(),
this);
115 connect(button, TQT_SIGNAL(clicked()), TQT_SLOT(close()));
116 buttonLayout->addWidget( button );
120 setCaption(i18n(
"TDE SSL Information"));
121 d->inQuestion =
false;
129 void KSSLInfoDlg::launchConfig() {
131 p <<
"tdecmshell" <<
"crypto";
132 p.start(TDEProcess::DontCare);
137 d->inQuestion = isIt;
140 d->pixmap->setPixmap(BarIcon(
"halfencrypted"));
142 d->info->setText(i18n(
"The main part of this document is secured with SSL, but some parts are not."));
144 d->info->setText(i18n(
"Some of this document is secured with SSL, but the main part is not."));
148 d->pixmap->setPixmap(BarIcon(
"encrypted"));
149 d->info->setText(i18n(
"Current connection is secured with SSL."));
151 d->pixmap->setPixmap(BarIcon(
"decrypted"));
152 d->info->setText(i18n(
"Current connection is not secured with SSL."));
174 const TQString& ip,
const TQString& url,
175 const TQString& cipher,
const TQString& cipherdesc,
176 const TQString& sslversion,
int usedbits,
int bits,
182 TQGridLayout *layout =
new TQGridLayout(4, 2, KDialog::spacingHint());
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)));
192 d->_chain->setEnabled(
true);
193 d->_chain->insertItem(i18n(
"0 - Site Certificate"));
196 cl.setAutoDelete(
true);
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);
207 d->_chain->setCurrentItem(0);
208 }
else d->_chain->setEnabled(
false);
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);
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);
223 layout->addWidget(ipl =
new TQLabel(ip,
this), 0, 1);
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);
232 layout->addWidget(d->_csl =
new TQLabel(
"",
this), 2, 1);
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);
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);
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);
256 ipl->setTextFormat(TQt::PlainText);
257 urlLabel->setTextFormat(TQt::PlainText);
258 d->_serialNum->setTextFormat(TQt::PlainText);
259 d->_csl->setTextFormat(TQt::PlainText);
260 d->_validFrom->setTextFormat(TQt::PlainText);
261 d->_validUntil->setTextFormat(TQt::PlainText);
262 d->_digest->setTextFormat(TQt::PlainText);
269 d->_cert_ksvl.clear();
270 TQStringList errors = TQStringList::split(
':', errorNrs);
271 for(TQStringList::ConstIterator it = errors.begin();
272 it != errors.end(); ++it)
283 cspl = d->_validFrom->palette();
285 cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
286 else cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
287 d->_validFrom->setPalette(cspl);
290 cspl = d->_validUntil->palette();
292 cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
293 else cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
294 d->_validUntil->setPalette(cspl);
300 KSSLCertificate::KSSLValidationList ksvl;
301 if ((x == d->_cert) && !d->_cert_ksvl.isEmpty()) {
302 ksvl = d->_cert_ksvl;
306 ksvl = d->_cert->validateVerbose(KSSLCertificate::SSLServer);
308 ksvl = d->_cert->validateVerbose(KSSLCertificate::SSLServer, x);
311 ksvl << KSSLCertificate::Ok;
315 if (ksv == KSSLCertificate::SelfSigned) {
319 ksv = KSSLCertificate::Ok;
321 ksv = KSSLCertificate::Expired;
326 if (ksv == KSSLCertificate::Ok) {
327 cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
328 }
else if (ksv != KSSLCertificate::Irrelevant) {
329 cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
331 d->_csl->setPalette(cspl);
334 for(KSSLCertificate::KSSLValidationList::ConstIterator it = ksvl.begin();
335 it != ksvl.end(); ++it) {
336 if (!errorStr.isEmpty())
337 errorStr.append(
'\n');
341 d->_csl->setText(errorStr);
342 d->_csl->setMinimumSize(d->_csl->sizeHint());
351 void KSSLInfoDlg::slotChain(
int x) {
353 displayCert(d->_cert);
355 TQPtrList<KSSLCertificate> cl = d->_cert->chain().getChain();
356 cl.setAutoDelete(
true);
357 for (
int i = 0; i < x-1; i++)
358 cl.remove((
unsigned int)0);
360 cl.remove((
unsigned int)0);
362 displayCert(&thisCert);
369 if (!certName.isEmpty()) {
370 result->
setValues(certName, mailCatcher);
377 : TQScrollView(parent, name, f)
380 setBackgroundMode(TQWidget::PaletteButton);
391 if (certName.isEmpty()) {
392 _frame =
new TQFrame(
this);
394 viewport()->setBackgroundMode(_frame->backgroundMode());
403 viewport()->setBackgroundMode(TQWidget::PaletteButton);
404 _frame =
new TQFrame(
this);
405 TQGridLayout *grid =
new TQGridLayout(_frame, 1, 2, KDialog::marginHint(), KDialog::spacingHint());
406 grid->setAutoAdd(
true);
408 if (!(tmp = cert.
getValue(
"O")).isEmpty()) {
409 label =
new TQLabel(i18n(
"Organization:"), _frame);
410 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
411 (
new TQLabel(tmp, _frame))->setTextFormat(TQt::PlainText);
413 if (!(tmp = cert.
getValue(
"OU")).isEmpty()) {
414 label =
new TQLabel(i18n(
"Organizational unit:"), _frame);
415 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
416 (
new TQLabel(tmp, _frame))->setTextFormat(TQt::PlainText);
418 if (!(tmp = cert.
getValue(
"L")).isEmpty()) {
419 label =
new TQLabel(i18n(
"Locality:"), _frame);
420 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
421 (
new TQLabel(tmp, _frame))->setTextFormat(TQt::PlainText);
423 if (!(tmp = cert.
getValue(
"ST")).isEmpty()) {
424 label =
new TQLabel(i18n(
"Federal State",
"State:"), _frame);
425 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
426 (
new TQLabel(tmp, _frame))->setTextFormat(TQt::PlainText);
428 if (!(tmp = cert.
getValue(
"C")).isEmpty()) {
429 label =
new TQLabel(i18n(
"Country:"), _frame);
430 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
431 (
new TQLabel(tmp, _frame))->setTextFormat(TQt::PlainText);
433 if (!(tmp = cert.
getValue(
"CN")).isEmpty()) {
434 label =
new TQLabel(i18n(
"Common name:"), _frame);
435 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
436 (
new TQLabel(tmp, _frame))->setTextFormat(TQt::PlainText);
438 if (!(tmp = cert.
getValue(
"Email")).isEmpty()) {
439 label =
new TQLabel(i18n(
"Email:"), _frame);
440 label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
442 KURLLabel *mail =
new KURLLabel(tmp, tmp, _frame);
443 connect(mail, TQT_SIGNAL(leftClickedURL(
const TQString &)), mailCatcher, TQT_SLOT(mailClicked(
const TQString &)));
445 label =
new TQLabel(tmp, _frame);
446 label->setTextFormat(TQt::PlainText);
449 if (label && viewport()) {
450 viewport()->setBackgroundMode(label->backgroundMode());
459 TQScrollView *KSSLInfoDlg::buildCertInfo(
const TQString &certName) {
463 void KSSLInfoDlg::urlClicked(
const TQString &url) {
464 kapp->invokeBrowser(url);
467 void KSSLInfoDlg::mailClicked(
const TQString &url) {
468 kapp->invokeMailer(url, TQString::null);
471 #include "ksslinfodlg.moc"
KDE SSL Information Dialog.
TQDateTime getQDTNotAfter() const
Get the date that the certificate is valid until.
TQString getIssuer() const
Get the issuer of the certificate (X.509 map).
static TQString verifyText(KSSLValidation x)
Obtain the localized message that corresponds to a validation result.
KSSLValidation validate()
Check if this is a valid certificate.
KSSLCertChain & chain()
Get a reference to the certificate chain.
const TQString & getCipher() const
Get the cipher in use.
int getCipherBits() const
Get bit-size of the cipher.
static KSSLCertBox * certInfoWidget(TQWidget *parent, const TQString &certName, TQWidget *mailCatcher=0)
Utility function to generate the widget which displays the detailed information about an X...
void setValues(TQString certName, TQWidget *mailCatcher=0L)
Change the contents of the widget.
TQString getSerialNumber() const
Get the serial number of the certificate.
void setCertState(const TQString &errorNrs)
Set the errors that were encountered while validating the site certificate.
const TQString & getCipherVersion() const
Get the version of the cipher in use.
void setup(KSSLCertificate *cert, const TQString &ip, const TQString &url, const TQString &cipher, const TQString &cipherdesc, const TQString &sslversion, int usedbits, int bits, KSSLCertificate::KSSLValidation certState)
Setup the dialog before showing it.
TQString getMD5DigestText() const
Get the MD5 digest of the certificate.
virtual ~KSSLInfoDlg()
Destroy this dialog.
TQString getNotAfter() const
Get the date that the certificate is valid until.
void setChain(void *stack_of_x509)
Set the raw chain from OpenSSL.
TQDateTime getQDTNotBefore() const
Get the date that the certificate becomes valid on.
TQString getValue(const TQString &key) const
Get the value of an entry in the map.
KSSLValidation
A CA certificate can be validated as Irrelevant when it was not used to sign any other relevant certi...
int getCipherUsedBits() const
Get the number of bits of the cipher that are actually used.
TQString getNotBefore() const
Get the date that the certificate becomes valid on.
KSSLInfoDlg(bool secureConnection, TQWidget *parent=0L, const char *name=0L, bool modal=false)
Construct a KSSL Information Dialog.
int depth()
Determine the number of entries (depth) of the chain.
void setSecurityInQuestion(bool isIt)
Tell the dialog if the connection has portions that may not be secure (ie.
KSSLPeerInfo & peerInfo()
Obtain a reference to the information about the peer.
bool isValid()
Determine if this represents a valid certificate chain.
TQString getSubject() const
Get the subject of the certificate (X.509 map).
static bool doesSSLWork()
Determine if SSL is available and works.
KSSLCertBox(TQWidget *parent=0L, const char *name=0L, WFlags f=0)
Construct a certificate box.
KSSLCertificate & getPeerCertificate()
Get a reference to the peer's certificate.
const TQString & getCipherDescription() const
Describe the cipher in use.
KSSLConnectionInfo & connectionInfo()
Obtain a reference to the connection information.
TQPtrList< KSSLCertificate > getChain()
Obtain a copy of the certificate chain.
bool useForSSL(KSSLCertificate &cert)
Determine if a certificate can be used for SSL certificate signing.