From d1711fffc795d925d89980f56cd02b767e871c59 Mon Sep 17 00:00:00 2001
From: Andrea Diamantini <adjam7@gmail.com>
Date: Mon, 25 Jul 2011 19:01:24 +0200
Subject: Last SSL fixes

- strings
- bool WebPage::hasSslValid() const
- check all the certificate chain
---
 src/urlbar/sslwidget.cpp | 31 ++++++++++++++++++++-----------
 src/urlbar/urlbar.cpp    |  3 ---
 src/webpage.cpp          | 21 ++++++++++++++-------
 src/webpage.h            |  2 +-
 4 files changed, 35 insertions(+), 22 deletions(-)

(limited to 'src')

diff --git a/src/urlbar/sslwidget.cpp b/src/urlbar/sslwidget.cpp
index a86151a9..ce08e974 100644
--- a/src/urlbar/sslwidget.cpp
+++ b/src/urlbar/sslwidget.cpp
@@ -49,8 +49,15 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent)
     setAttribute(Qt::WA_DeleteOnClose);
     setMinimumWidth(400);
 
-    QSslCertificate cert = m_info.certificateChain().first();
-    QStringList firstCertErrorList = SslInfoDialog::errorsFromString(m_info.certificateErrors()).first();
+    QList<QSslCertificate> certList = m_info.certificateChain();
+    QSslCertificate cert;
+    if (!certList.isEmpty())
+         cert = certList.first();
+
+    QList<QStringList> certErrorList = SslInfoDialog::errorsFromString(m_info.certificateErrors());
+    QStringList firstCertErrorList;
+    if (!certErrorList.isEmpty())
+        firstCertErrorList = certErrorList.first();
     
     QGridLayout *layout = new QGridLayout(this);
 
@@ -77,12 +84,14 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent)
         label->setText(i18n("Warning: this site is NOT carrying a certificate!"));
 
         imageLabel->setPixmap(KIcon("security-low").pixmap(32));
+
+        layout->addWidget(label, rows++, 1);
     }
     else
     {
         if(cert.isValid() && firstCertErrorList.isEmpty())
         {
-            label->setText(i18n("This certificate for this site is valid and has been verified by:\n%1.",
+            label->setText(i18n("The certificate for this site is valid and has been verified by:\n%1.",
                                 Qt::escape(cert.issuerInfo(QSslCertificate::CommonName)) ));
 
             imageLabel->setPixmap(KIcon("security-high").pixmap(32));
@@ -100,15 +109,15 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent)
             label->setTextFormat(Qt::RichText);
             imageLabel->setPixmap(KIcon("security-low").pixmap(32));
         }
-    }
 
-    layout->addWidget(label, rows++, 1);
+        layout->addWidget(label, rows++, 1);
 
-    label = new QLabel(this);
-    label->setWordWrap(true);
-    label->setText("<a href=\"moresslinfos\">Certificate Information</a>");
-    connect(label, SIGNAL(linkActivated(const QString &)), this, SLOT(showMoreSslInfos(const QString &)));
-    layout->addWidget(label, rows++, 1);
+        label = new QLabel(this);
+        label->setWordWrap(true);
+        label->setText("<a href=\"moresslinfos\">Certificate Information</a>");
+        connect(label, SIGNAL(linkActivated(const QString &)), this, SLOT(showMoreSslInfos(const QString &)));
+        layout->addWidget(label, rows++, 1);
+    }
 
     // ------------------------------------------------------------------------------------------------------------------
     label = new QLabel(this);
@@ -171,7 +180,7 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent)
         label = new QLabel(this);
         label->setWordWrap(true);
         label->setText(
-            i18n("It is encrypted using %1 at %2 bits\nMessage authentication: %3\nKey exchange mechanism: %4, with Auth %5.\n\n",
+            i18n("It is encrypted using %1 at %2 bits, with %3 for message authentication and %4 with Auth %5 as key exchange mechanism.\n\n",
                  cipherInfo[0],
                  m_info.usedChiperBits(),
                  cipherInfo[3],
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index 8dd4f092..a5d225dd 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -338,9 +338,6 @@ void UrlBar::loadFinished()
         return;
     }
 
-    kDebug() << ReKonfig::previewUrls();
-    kDebug() << _tab->url().url();
-
     // show Favorite Icon
     if(ReKonfig::previewUrls().contains(_tab->url().url()))
     {
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 3f4b4e1f..3986fafb 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -545,7 +545,7 @@ void WebPage::manageNetworkErrors(QNetworkReply *reply)
 
     QWebFrame* frame = qobject_cast<QWebFrame *>(reply->request().originatingObject());
     const bool isMainFrameRequest = (frame == mainFrame());
-    const bool isLoadingUrlReply = (_loadingUrl == reply->url());
+    const bool isLoadingUrlReply = (mainFrame()->url() == reply->url());
 
     if(isMainFrameRequest
             && _sslInfo.isValid()
@@ -753,17 +753,24 @@ void WebPage::copyToTempFileResult(KJob* job)
 }
 
 
-bool WebPage::hasSslValid()
+bool WebPage::hasSslValid() const
 {
     QList<QSslCertificate> certList = _sslInfo.certificateChain();
 
     if (certList.isEmpty())
         return false;
 
-    QSslCertificate firstCert = certList.at(0);
-    if (!firstCert.isValid())
-        return false;
+    Q_FOREACH(const QSslCertificate &cert, certList)
+    {
+        if (!cert.isValid())
+            return false;
+    }
 
-    QStringList firstCertErrorsList = SslInfoDialog::errorsFromString(_sslInfo.certificateErrors()).at(0);
-    return firstCertErrorsList.isEmpty();
+    QList<QStringList> errorList = SslInfoDialog::errorsFromString(_sslInfo.certificateErrors());
+    Q_FOREACH(const QStringList & list, errorList)
+    {
+        if (!list.isEmpty())
+            return false;
+    }
+    return true;
 }
diff --git a/src/webpage.h b/src/webpage.h
index b0081e6e..609141fb 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -80,7 +80,7 @@ public:
         return _suggestedFileName;
     };
 
-    bool hasSslValid();
+    bool hasSslValid() const;
 
 public Q_SLOTS:
     void downloadAllContentsWithKGet(QPoint);
-- 
cgit v1.2.1