Extended the check for acceptable SSL certificates for indication via the URL entry field.

Sun, 15 Jan 2012 16:42:56 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 15 Jan 2012 16:42:56 +0100
changeset 1558
754120837dd8
parent 1557
4831bab2b94e
child 1559
a28a552ba2e2

Extended the check for acceptable SSL certificates for indication via the URL entry field.

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Helpviewer.HelpBrowserWV.html file | annotate | diff | comparison | revisions
Helpviewer/HelpBrowserWV.py file | annotate | diff | comparison | revisions
Helpviewer/UrlBar/UrlBar.py file | annotate | diff | comparison | revisions
changelog file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Sun Jan 15 16:38:16 2012 +0100
+++ b/APIs/Python3/eric5.api	Sun Jan 15 16:42:56 2012 +0100
@@ -2043,6 +2043,7 @@
 eric5.Helpviewer.HelpBrowserWV.HelpWebPage.acceptNavigationRequest?4(frame, request, type_)
 eric5.Helpviewer.HelpBrowserWV.HelpWebPage.extension?4(extension, option, output)
 eric5.Helpviewer.HelpBrowserWV.HelpWebPage.getSslInfo?4()
+eric5.Helpviewer.HelpBrowserWV.HelpWebPage.hasValidSslInfo?4()
 eric5.Helpviewer.HelpBrowserWV.HelpWebPage.pageAttributeId?4()
 eric5.Helpviewer.HelpBrowserWV.HelpWebPage.populateNetworkRequest?4(request)
 eric5.Helpviewer.HelpBrowserWV.HelpWebPage.setUserAgent?4(agent)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Jan 15 16:38:16 2012 +0100
+++ b/Documentation/Help/source.qhp	Sun Jan 15 16:42:56 2012 +0100
@@ -4429,6 +4429,7 @@
       <keyword name="HelpWebPage.acceptNavigationRequest" id="HelpWebPage.acceptNavigationRequest" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.acceptNavigationRequest" />
       <keyword name="HelpWebPage.extension" id="HelpWebPage.extension" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.extension" />
       <keyword name="HelpWebPage.getSslInfo" id="HelpWebPage.getSslInfo" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.getSslInfo" />
+      <keyword name="HelpWebPage.hasValidSslInfo" id="HelpWebPage.hasValidSslInfo" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.hasValidSslInfo" />
       <keyword name="HelpWebPage.pageAttributeId" id="HelpWebPage.pageAttributeId" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.pageAttributeId" />
       <keyword name="HelpWebPage.populateNetworkRequest" id="HelpWebPage.populateNetworkRequest" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.populateNetworkRequest" />
       <keyword name="HelpWebPage.setUserAgent" id="HelpWebPage.setUserAgent" ref="eric5.Helpviewer.HelpBrowserWV.html#HelpWebPage.setUserAgent" />
--- a/Documentation/Source/eric5.Helpviewer.HelpBrowserWV.html	Sun Jan 15 16:38:16 2012 +0100
+++ b/Documentation/Source/eric5.Helpviewer.HelpBrowserWV.html	Sun Jan 15 16:42:56 2012 +0100
@@ -962,6 +962,9 @@
 <td><a href="#HelpWebPage.getSslInfo">getSslInfo</a></td>
 <td>Public method to get a reference to the SSL info object.</td>
 </tr><tr>
+<td><a href="#HelpWebPage.hasValidSslInfo">hasValidSslInfo</a></td>
+<td>Public method to check, if the page has a valid SSL certificate.</td>
+</tr><tr>
 <td><a href="#HelpWebPage.pageAttributeId">pageAttributeId</a></td>
 <td>Public method to get the attribute id of the page attribute.</td>
 </tr><tr>
@@ -1062,6 +1065,16 @@
 <dd>
 reference to the SSL info (QSslCertificate)
 </dd>
+</dl><a NAME="HelpWebPage.hasValidSslInfo" ID="HelpWebPage.hasValidSslInfo"></a>
+<h4>HelpWebPage.hasValidSslInfo</h4>
+<b>hasValidSslInfo</b>(<i></i>)
+<p>
+        Public method to check, if the page has a valid SSL certificate.
+</p><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating a valid SSL certificate (boolean)
+</dd>
 </dl><a NAME="HelpWebPage.pageAttributeId" ID="HelpWebPage.pageAttributeId"></a>
 <h4>HelpWebPage.pageAttributeId</h4>
 <b>pageAttributeId</b>(<i></i>)
--- a/Helpviewer/HelpBrowserWV.py	Sun Jan 15 16:38:16 2012 +0100
+++ b/Helpviewer/HelpBrowserWV.py	Sun Jan 15 16:42:56 2012 +0100
@@ -32,6 +32,7 @@
 from .HTMLResources import notFoundPage_html
 try:
     from .SslInfoDialog import SslInfoDialog
+    from PyQt4.QtNetwork import QSslCertificate
     SSL_AVAILABLE = True
 except ImportError:
     SSL_AVAILABLE = False
@@ -172,7 +173,7 @@
             Helpviewer.HelpWindow.HelpWindow.networkAccessManager())
         self.setNetworkAccessManager(self.__proxy)
         
-        self.__sslInfo = None
+        self.__sslConfiguration = None
         self.__proxy.finished.connect(self.__managerFinished)
     
     def acceptNavigationRequest(self, frame, request, type_):
@@ -336,17 +337,17 @@
         mainFrameRequest = frame == self.mainFrame()
         
         if mainFrameRequest and \
-           self.__sslInfo is not None and \
+           self.__sslConfiguration is not None and \
            reply.url() == self.mainFrame().url():
-            self.__sslInfo = None
+            self.__sslConfiguration = None
         
         if reply.error() == QNetworkReply.NoError and \
            mainFrameRequest and \
-           self.__sslInfo is None and \
+           self.__sslConfiguration is None and \
            reply.url().scheme().lower() == "https" and \
            reply.url() == self.mainFrame().url():
-            self.__sslInfo = reply.sslConfiguration().peerCertificate()
-            self.__sslInfo.url = QUrl(reply.url())
+            self.__sslConfiguration = reply.sslConfiguration()
+            self.__sslConfiguration.url = QUrl(reply.url())
     
     def getSslInfo(self):
         """
@@ -354,19 +355,48 @@
         
         @return reference to the SSL info (QSslCertificate)
         """
-        return self.__sslInfo
+        sslInfo = self.__sslConfiguration.peerCertificate()
+        sslInfo.url = QUrl(self.__sslConfiguration.url)
+        return sslInfo
     
     def showSslInfo(self):
         """
         Public slot to show some SSL information for the loaded page.
         """
-        if SSL_AVAILABLE and self.__sslInfo is not None:
-            dlg = SslInfoDialog(self.__sslInfo, self.view())
+        if SSL_AVAILABLE and self.__sslConfiguration is not None:
+            dlg = SslInfoDialog(self.getSslInfo(), self.view())
             dlg.exec_()
         else:
             E5MessageBox.warning(self.view(),
                 self.trUtf8("SSL Certificate Info"),
                 self.trUtf8("""There is no SSL Certificate Info available."""))
+    
+    def hasValidSslInfo(self):
+        """
+        Public method to check, if the page has a valid SSL certificate.
+        
+        @return flag indicating a valid SSL certificate (boolean)
+        """
+        if self.__sslConfiguration is None:
+            return False
+        
+        certList = self.__sslConfiguration.peerCertificateChain()
+        if not certList:
+            return False
+        
+        certificateDict = Preferences.toDict(
+                Preferences.Prefs.settings.value("Help/CaCertificatesDict"))
+        for server in certificateDict:
+            localCAList = QSslCertificate.fromData(certificateDict[server])
+            for cert in certList:
+                if cert in localCAList:
+                    return True
+        
+        for cert in certList:
+            if not cert.isValid():
+                return False
+        
+        return True
 
 ##########################################################################################
 
--- a/Helpviewer/UrlBar/UrlBar.py	Sun Jan 15 16:38:16 2012 +0100
+++ b/Helpviewer/UrlBar/UrlBar.py	Sun Jan 15 16:42:56 2012 +0100
@@ -243,14 +243,22 @@
         if self.__browser is not None:
             p = self.palette()
             progress = self.__browser.progress()
-            if progress == 0:
+            if progress == 0 or progress == 100:
                 if self.__browser.url().scheme() == "https":
-                    backgroundColor = Preferences.getHelp("SaveUrlColor")
+                    if QSslCertificate is not None:
+                        if self.__browser.page().hasValidSslInfo():
+                            backgroundColor = Preferences.getHelp("SaveUrlColor")
+                    else:
+                        backgroundColor = Preferences.getHelp("SaveUrlColor")
                 p.setBrush(QPalette.Base, backgroundColor)
                 p.setBrush(QPalette.Text, foregroundColor)
             else:
                 if self.__browser.url().scheme() == "https":
-                    backgroundColor = Preferences.getHelp("SaveUrlColor")
+                    if QSslCertificate is not None:
+                        if self.__browser.page().hasValidSslInfo():
+                            backgroundColor = Preferences.getHelp("SaveUrlColor")
+                    else:
+                        backgroundColor = Preferences.getHelp("SaveUrlColor")
                 highlight = QApplication.palette().color(QPalette.Highlight)
                 r = (highlight.red() + 2 * backgroundColor.red()) // 3
                 g = (highlight.green() + 2 * backgroundColor.green()) // 3
--- a/changelog	Sun Jan 15 16:38:16 2012 +0100
+++ b/changelog	Sun Jan 15 16:42:56 2012 +0100
@@ -1,6 +1,12 @@
 Change Log
 ----------
-Version 5.2-snapshot-2011mmdd:
+Version 5.3.0:
+- bug fixes
+- Web Browser
+  -- extended the check for acceptable SSL certificates for indication via the
+     URL entry field
+
+Version 5.2.0:
 - bug fixes
 - Cooperation Functions
   -- added code to the cooperation functions to support IPv6

eric ide

mercurial