From c36f3b1351088b86845dd8981a7a9b13b971606e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 11 Jul 2011 10:06:41 +0200 Subject: SSL rewamp, one step to finish! These are last changes to clean up and improve SSL rekonq communications. It is yet missing a proper SSL errors API integration. You just need to wait for the next commit... --- src/sslinfo.ui | 9 +++- src/sslinfodialog.cpp | 25 +++++++++-- src/sslinfodialog.h | 2 +- src/urlbar/sslwidget.cpp | 111 +++++++++++++++++++++++++++++++++++------------ src/urlbar/urlbar.cpp | 5 ++- src/webpage.cpp | 12 +++++ src/webpage.h | 5 +-- 7 files changed, 130 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/sslinfo.ui b/src/sslinfo.ui index 97ca69d0..e31216b0 100644 --- a/src/sslinfo.ui +++ b/src/sslinfo.ui @@ -1,7 +1,7 @@ SslInfo - + 0 @@ -30,6 +30,13 @@ + + + + TextLabel + + + diff --git a/src/sslinfodialog.cpp b/src/sslinfodialog.cpp index cb60cef8..376480af 100644 --- a/src/sslinfodialog.cpp +++ b/src/sslinfodialog.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -72,12 +73,30 @@ SslInfoDialog::SslInfoDialog(const QString &host, const WebSslInfo &info, QWidge QSslCertificate subjectCert = caList.first(); - showCertificateInfo(subjectCert); + 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) ); + } } -void SslInfoDialog::showCertificateInfo(QSslCertificate subjectCert) +void SslInfoDialog::showCertificateInfo(QSslCertificate subjectCert, const QString &certErrors) { + ui.certInfoLabel->setText(certErrors); + ui.subjectCN->setText( subjectCert.subjectInfo(QSslCertificate::CommonName) ); ui.subjectO->setText( subjectCert.subjectInfo(QSslCertificate::Organization) ); ui.subjectOU->setText( subjectCert.subjectInfo(QSslCertificate::OrganizationalUnitName) ); @@ -99,7 +118,7 @@ void SslInfoDialog::displayFromChain(int i) { QList caList = m_info.certificateChain(); QSslCertificate cert = caList.at(i); - showCertificateInfo(cert); + showCertificateInfo(cert, QString()); } diff --git a/src/sslinfodialog.h b/src/sslinfodialog.h index c9b4c106..bed5a8b7 100644 --- a/src/sslinfodialog.h +++ b/src/sslinfodialog.h @@ -60,7 +60,7 @@ private Q_SLOTS: void exportCert(); private: - void showCertificateInfo(QSslCertificate); + void showCertificateInfo(QSslCertificate, const QString &certErrors); QString m_host; WebSslInfo m_info; diff --git a/src/urlbar/sslwidget.cpp b/src/urlbar/sslwidget.cpp index 862bdb3f..8507aa61 100644 --- a/src/urlbar/sslwidget.cpp +++ b/src/urlbar/sslwidget.cpp @@ -34,10 +34,11 @@ #include "sslinfodialog.h" // KDE Includes +#include // Qt Includes #include -#include +#include #include #include @@ -52,22 +53,28 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) QSslCertificate cert = info.certificateChain().first(); - QFormLayout *layout = new QFormLayout(this); + QGridLayout *layout = new QGridLayout(this); QLabel *label; - + QLabel *imageLabel; + + int rows = 0; // ------------------------------------------------------------------------------------------------------------------ + imageLabel = new QLabel(this); + layout->addWidget(imageLabel, rows , 0, Qt::AlignCenter); + label = new QLabel(this); label->setWordWrap(true); label->setText( i18n("

Identity

") ); - layout->addRow(label); - + layout->addWidget(label, rows++, 1); + if (cert.isNull()) { label = new QLabel(this); label->setWordWrap(true); - label->setText( i18n("Warning: this site is carrying a NULL certificate") ); - layout->addRow(label); + label->setText( i18n("Warning: this site is carrying a NULL certificate!") ); + + imageLabel->setPixmap(KIcon("security-low").pixmap(32)); } else { @@ -75,50 +82,92 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) { label = new QLabel(this); label->setWordWrap(true); - label->setText( i18n("This certificate for this site is Valid and has been verified by ") - + cert.issuerInfo(QSslCertificate::CommonName) ); - layout->addRow(label); + label->setText( i18n("This certificate for this site is valid and has been verified by:\n%1.", + cert.issuerInfo(QSslCertificate::CommonName)) ); + + + imageLabel->setPixmap(KIcon("security-high").pixmap(32)); } else { + QString errors; + QStringList sl = m_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"); + } + } label = new QLabel(this); label->setWordWrap(true); - label->setText( i18n("Warning: The certificate for this site is NOT valid!") ); - layout->addRow(label); + 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)); } } - + + layout->addWidget(label, rows++, 1); + label = new QLabel(this); label->setWordWrap(true); label->setText("Certificate Information"); connect(label, SIGNAL(linkActivated(const QString &)), this, SLOT(showMoreSslInfos(const QString &))); - layout->addRow(label); + layout->addWidget(label, rows++, 1); // ------------------------------------------------------------------------------------------------------------------ label = new QLabel(this); label->setWordWrap(true); - label->setText( QL1S("

Encryption

") ); // ----------------------------------------------- // - layout->addRow(label); + label->setText( QL1S("

Encryption

") ); // ----------------------------------------------- // + layout->addWidget(label, rows, 1); + + imageLabel = new QLabel(this); + layout->addWidget(imageLabel, rows++ , 0, Qt::AlignCenter); if (cert.isNull()) { label = new QLabel(this); label->setWordWrap(true); label->setText( i18n("Your connection to %1 is NOT encrypted!!\n\n", m_url.host()) ); - layout->addRow(label); + layout->addWidget(label, rows++ , 1); + + imageLabel->setPixmap(KIcon("security-low").pixmap(32)); } else { label = new QLabel(this); label->setWordWrap(true); - label->setText( i18n("Your connection to %1 is encrypted with %2 encryption\n\n", m_url.host(), m_info.supportedChiperBits()) ); - layout->addRow(label); + label->setText( i18n("Your connection to %1 is encrypted with %2-bit encryption.\n\n", m_url.host(), m_info.supportedChiperBits()) ); + layout->addWidget(label, rows++, 1); - QString sslVersion = QL1S("SSLv") + cert.version(); + int vers = cert.version().toInt(); + QString sslVersion; + switch(vers) + { + case 0: + sslVersion = QL1S("SSL 3.0"); + imageLabel->setPixmap(KIcon("security-high").pixmap(32)); + break; + case 1: + sslVersion = QL1S("SSL 2.0"); + imageLabel->setPixmap(KIcon("security-medium").pixmap(32)); + break; + case 2: + case 3: + sslVersion = QL1S("TLS 1.0"); + imageLabel->setPixmap(KIcon("security-high").pixmap(32)); + break; + default: + sslVersion = QL1S("Unknown"); + imageLabel->setPixmap(KIcon("security-medium").pixmap(32)); + } + label = new QLabel(this); label->setWordWrap(true); - label->setText( i18n("The connection uses %1\n\n", sslVersion) ); - layout->addRow(label); + label->setText( i18n("The connection uses %1.\n\n", sslVersion) ); + layout->addWidget(label, rows++, 1); const QStringList cipherInfo = m_info.ciphers().split('\n', QString::SkipEmptyParts); label = new QLabel(this); @@ -129,14 +178,18 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) m_info.usedChiperBits(), cipherInfo[3], cipherInfo[1]) ); - layout->addRow(label); + layout->addWidget(label, rows++, 1); + } // ------------------------------------------------------------------------------------------------------------------ + imageLabel = new QLabel(this); + layout->addWidget(imageLabel, rows , 0, Qt::AlignCenter); + label = new QLabel(this); label->setWordWrap(true); - label->setText( i18n("

Site Information

") ); - layout->addRow(label); + label->setText( i18n("

Site Information

") ); + layout->addWidget(label, rows++, 1); label = new QLabel(this); label->setWordWrap(true); @@ -145,13 +198,15 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) if (firstVisit.visitCount == 1) { - label->setText( i18n("It's your first time visiting this site") ); + label->setText( i18n("It's your first time visiting this site!") ); + imageLabel->setPixmap(KIcon("security-medium").pixmap(32)); } else { - label->setText( i18n("You just visited this site!\nYour first visit was on %1", firstVisit.firstDateTimeVisit.toString()) ); + label->setText( i18n("You just visited this site!\nYour first visit was on %1.\n", firstVisit.firstDateTimeVisit.toString()) ); + imageLabel->setPixmap(KIcon("security-high").pixmap(32)); } - layout->addRow(label); + layout->addWidget(label, rows++, 1); // ----------------------------------------------------------------------------------- setLayout(layout); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index fa23b6c6..8b3dac65 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -356,6 +356,7 @@ void UrlBar::loadFinished() // show SSL if(_tab->url().scheme() == QL1S("https")) { + // NOTE: the choice for the right SSL icon is done in the addRightIcon method IconButton *bt = addRightIcon(UrlBar::SSL); connect(bt, SIGNAL(clicked(QPoint)), _tab->page(), SLOT(showSSLInfo(QPoint))); } @@ -465,8 +466,8 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) break; case UrlBar::SSL: _tab->page()->hasSslValid() - ? rightIcon->setIcon(KIcon("security-high")) - : rightIcon->setIcon(KIcon("security-low")); + ? rightIcon->setIcon(KIcon("object-locked")) + : rightIcon->setIcon(KIcon("object-unlocked")); rightIcon->setToolTip(i18n("Show SSL Info")); break; case UrlBar::BK: diff --git a/src/webpage.cpp b/src/webpage.cpp index 9185a25b..95d7b6ae 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -763,3 +763,15 @@ void WebPage::copyToTempFileResult(KJob* job) else (void)KRun::runUrl(static_cast(job)->destUrl(), _mimeType, rApp->mainWindow()); } + + +bool WebPage::hasSslValid() +{ + bool v = true; + QList certList = _sslInfo.certificateChain(); + Q_FOREACH(const QSslCertificate &cert, certList) + { + v &= cert.isValid(); + } + return v; +} diff --git a/src/webpage.h b/src/webpage.h index 86355395..cc407016 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -80,10 +80,7 @@ public: return _suggestedFileName; }; - inline bool hasSslValid() - { - return _sslInfo.isValid(); - } + bool hasSslValid(); public Q_SLOTS: void downloadAllContentsWithKGet(QPoint); -- cgit v1.2.1