From 130ed6c522a148c8bb98a2ece22a3d64be06df7d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 11 Jul 2011 12:45:20 +0200 Subject: Last fixes for the SSL dialog improvements Now we are ready for the fight... --- src/sslinfo.ui | 69 ++++++++++++++++++++++++++++++++++++++++---- src/sslinfodialog.cpp | 74 +++++++++++++++++++++++++++++++++--------------- src/sslinfodialog.h | 6 ++-- src/urlbar/sslwidget.cpp | 34 ++++++++++++---------- 4 files changed, 137 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/sslinfo.ui b/src/sslinfo.ui index e31216b0..84d3f4b2 100644 --- a/src/sslinfo.ui +++ b/src/sslinfo.ui @@ -6,8 +6,8 @@ 0 0 - 460 - 432 + 427 + 481 @@ -28,7 +28,51 @@ - + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Certificate Chain: + + + + + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + @@ -37,6 +81,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -118,7 +175,7 @@ 20 - 40 + 20 @@ -184,7 +241,7 @@ 20 - 40 + 20 @@ -236,7 +293,7 @@ 20 - 40 + 20 diff --git a/src/sslinfodialog.cpp b/src/sslinfodialog.cpp index 376480af..dc55e95a 100644 --- a/src/sslinfodialog.cpp +++ b/src/sslinfodialog.cpp @@ -70,32 +70,22 @@ SslInfoDialog::SslInfoDialog(const QString &host, const WebSslInfo &info, QWidge ui.comboBox->addItem( cert.subjectInfo(QSslCertificate::CommonName) ); } connect(ui.comboBox, SIGNAL(activated(int)), this, SLOT(displayFromChain(int))); - - QSslCertificate subjectCert = caList.first(); - - if (subjectCert.isValid()) - showCertificateInfo(subjectCert, i18n("The Certificate is Valid!") ); - else - { - QString errors; - QStringList sl = info.certificateErrors().split("\t", QString::SkipEmptyParts); - Q_FOREACH(const QString &s, sl) - { - bool didConvert; - QSslError::SslError error = static_cast(s.trimmed().toInt(&didConvert)); - if (didConvert) - { - errors += QSslError(error).errorString() + QL1S("\n"); - } - } - showCertificateInfo(subjectCert, i18n("The certificate for this site is NOT valid for the following reasons:\n%1", errors) ); - } + + displayFromChain(0); } -void SslInfoDialog::showCertificateInfo(QSslCertificate subjectCert, const QString &certErrors) +void SslInfoDialog::showCertificateInfo(QSslCertificate subjectCert, const QStringList &certErrors) { - ui.certInfoLabel->setText(certErrors); + QStringList sl = certErrors; + QString c = sl.takeFirst(); + c += QL1S("
    "); + Q_FOREACH(const QString &s, sl) + { + c += QL1S("
  • ") + s + QL1S("
  • "); + } + c += QL1S("
"); + ui.certInfoLabel->setText(c); ui.subjectCN->setText( subjectCert.subjectInfo(QSslCertificate::CommonName) ); ui.subjectO->setText( subjectCert.subjectInfo(QSslCertificate::Organization) ); @@ -118,7 +108,19 @@ void SslInfoDialog::displayFromChain(int i) { QList caList = m_info.certificateChain(); QSslCertificate cert = caList.at(i); - showCertificateInfo(cert, QString()); + + if (cert.isValid()) + { + QStringList certInfo; + certInfo << i18n("The Certificate is Valid!"); + showCertificateInfo(cert, certInfo ); + } + else + { + QStringList errors = SslInfoDialog::errorsFromString(m_info.certificateErrors()).at(i); + errors.prepend( i18n("The certificate for this site is NOT valid for the following reasons:") ); + showCertificateInfo(cert, errors ); + } } @@ -139,3 +141,29 @@ void SslInfoDialog::exportCert() QTextStream out(&file); out << cert.toPem(); } + + +// static ------------------------------------------------------------------------------------------- +QList SslInfoDialog::errorsFromString(const QString &s) +{ + QList resultList; + + QStringList sl1 = s.split('\n', QString::KeepEmptyParts); + + Q_FOREACH(const QString &certErrors, sl1) + { + QStringList errors; + QStringList sl = certErrors.split("\t", QString::SkipEmptyParts); + Q_FOREACH(const QString &s, sl) + { + bool didConvert; + QSslError::SslError error = static_cast(s.trimmed().toInt(&didConvert)); + if (didConvert) + { + errors << QSslError(error).errorString(); + } + } + resultList << errors; + } + return resultList; +} diff --git a/src/sslinfodialog.h b/src/sslinfodialog.h index bed5a8b7..c993e134 100644 --- a/src/sslinfodialog.h +++ b/src/sslinfodialog.h @@ -55,12 +55,14 @@ class SslInfoDialog : public KDialog public: explicit SslInfoDialog(const QString &host, const WebSslInfo &info, QWidget *parent = 0); + static QList errorsFromString(const QString &s); + private Q_SLOTS: void displayFromChain(int); void exportCert(); - + private: - void showCertificateInfo(QSslCertificate, const QString &certErrors); + void showCertificateInfo(QSslCertificate, const QStringList &certErrors); QString m_host; WebSslInfo m_info; diff --git a/src/urlbar/sslwidget.cpp b/src/urlbar/sslwidget.cpp index 8507aa61..b1819700 100644 --- a/src/urlbar/sslwidget.cpp +++ b/src/urlbar/sslwidget.cpp @@ -33,9 +33,6 @@ #include "historymanager.h" #include "sslinfodialog.h" -// KDE Includes -#include - // Qt Includes #include #include @@ -90,22 +87,29 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) } else { - QString errors; - QStringList sl = m_info.certificateErrors().split("\t", QString::SkipEmptyParts); - Q_FOREACH(const QString &s, sl) + label = new QLabel(this); + label->setWordWrap(true); + + QList errorList = SslInfoDialog::errorsFromString(m_info.certificateErrors()); + if (errorList.at(0).isEmpty()) + { + label->setText( i18n("The certificate for this site is valid, but some on the certificate chain are not!") ); + imageLabel->setPixmap(KIcon("security-medium").pixmap(32)); + } + else { - bool didConvert; - QSslError::SslError error = static_cast(s.trimmed().toInt(&didConvert)); - if (didConvert) + QStringList sl = errorList.at(0); + QString c = QL1S("
    "); + Q_FOREACH(const QString &s, sl) { - errors += QSslError(error).errorString() + QL1S("\n"); + c += QL1S("
  • ") + s + QL1S("
  • "); } + c += QL1S("
"); + + label->setText( i18n("The certificate for this site is NOT valid, for the following reasons:\n%1", c) ); + label->setTextFormat(Qt::RichText); + imageLabel->setPixmap(KIcon("security-low").pixmap(32)); } - label = new QLabel(this); - label->setWordWrap(true); - label->setText( i18n("The certificate for this site is NOT valid for the following reasons:\n%1", errors) ); - - imageLabel->setPixmap(KIcon("security-medium").pixmap(32)); } } -- cgit v1.2.1