eric6/WebBrowser/SafeBrowsing/SafeBrowsingManager.py

Wed, 25 Sep 2019 18:52:40 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 25 Sep 2019 18:52:40 +0200
changeset 7269
0c63ea7f94bd
parent 7229
53054eb5b15a
child 7360
9190402e4505
permissions
-rw-r--r--

Continued to resolve code style issue M841.

5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6234
diff changeset
3 # Copyright (c) 2017 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the interface for Google Safe Browsing.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 #
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 # Some part of this code were ported from gglsbl.client and adapted
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 # to Qt.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 #
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 # https://github.com/afilipovich/gglsbl
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 #
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import os
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import base64
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
21 from PyQt5.QtCore import (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
22 pyqtSignal, pyqtSlot, QObject, QCoreApplication, QUrl, QDateTime, QTimer
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
23 )
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import Preferences
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 import Utilities
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
28 import UI.PixmapCache
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
29
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 from .SafeBrowsingAPIClient import SafeBrowsingAPIClient
6229
72b40274a3b6 Web Browser NG, Safe Browsing: refactored the code to prepare the implementation of the Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6187
diff changeset
31 from .SafeBrowsingCache import SafeBrowsingCache
72b40274a3b6 Web Browser NG, Safe Browsing: refactored the code to prepare the implementation of the Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6187
diff changeset
32 from .SafeBrowsingThreatList import ThreatList, HashPrefixList
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
33 from .SafeBrowsingUrl import SafeBrowsingUrl
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 class SafeBrowsingManager(QObject):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Class implementing the interface for Google Safe Browsing.
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
39
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
40 @signal progressMessage(message,maximum) emitted to give a message for the
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
41 action about to be performed and the maximum value
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
42 @signal progress(current) emitted to signal the current progress
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
44 progressMessage = pyqtSignal(str, int)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
45 progress = pyqtSignal(int)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
46
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
47 enabled = (
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
48 Preferences.getWebBrowser("SafeBrowsingEnabled") and
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
49 bool(Preferences.getWebBrowser("SafeBrowsingApiKey"))
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 )
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 def __init__(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Constructor
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 super(SafeBrowsingManager, self).__init__()
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__apiKey = Preferences.getWebBrowser("SafeBrowsingApiKey")
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 if self.__apiKey:
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
60 self.__apiClient = SafeBrowsingAPIClient(self.__apiKey,
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
61 parent=self)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 else:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.__apiClient = None
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 gsbCachePath = os.path.join(
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Utilities.getConfigDir(), "web_browser", "safe_browsing")
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__cache = SafeBrowsingCache(gsbCachePath, self)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.__gsbDialog = None
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
70 self.__setPlatforms()
6233
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
71 self.__setLookupMethod()
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
72
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
73 self.__updatingThreatLists = False
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
74 self.__threatListsUpdateTimer = QTimer(self)
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
75 self.__threatListsUpdateTimer.setSingleShot(True)
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
76 self.__threatListsUpdateTimer.timeout.connect(
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
77 self.__threatListsUpdateTimerTimeout)
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
78 self.__setAutoUpdateThreatLists()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 def configurationChanged(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 Public method to handle changes of the settings.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 apiKey = Preferences.getWebBrowser("SafeBrowsingApiKey")
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if apiKey != self.__apiKey:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__apiKey = apiKey
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if self.__apiKey:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if self.__apiClient:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__apiClient.setApiKey(self.__apiKey)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 else:
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
91 self.__apiClient = SafeBrowsingAPIClient(self.__apiKey,
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
92 parent=self)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
94 SafeBrowsingManager.enabled = (
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 Preferences.getWebBrowser("SafeBrowsingEnabled") and
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 bool(self.__apiKey))
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
97
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
98 self.__setPlatforms()
6233
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
99 self.__setLookupMethod()
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
100 self.__setAutoUpdateThreatLists()
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
101
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
102 def __setPlatforms(self):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
103 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
104 Private method to set the platforms to be checked against.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
105 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
106 self.__platforms = None
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
107 if Preferences.getWebBrowser("SafeBrowsingFilterPlatform"):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
108 if Utilities.isWindowsPlatform():
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
109 platform = "windows"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
110 elif Utilities.isMacPlatform():
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
111 platform = "macos"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
112 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
113 # treat all other platforms like linux
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
114 platform = "linux"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
115 self.__platforms = SafeBrowsingAPIClient.getPlatformTypes(platform)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
6233
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
117 def __setLookupMethod(self):
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
118 """
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
119 Private method to set the lookup method (Update API or Lookup API).
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
120 """
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
121 self.__useLookupApi = Preferences.getWebBrowser(
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
122 "SafeBrowsingUseLookupApi")
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
123
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
124 @classmethod
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
125 def isEnabled(cls):
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 """
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
127 Class method to check, if safe browsing is enabled.
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 @return flag indicating the enabled state
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @rtype bool
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
132 return cls.enabled
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 def close(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 Public method to close the safe browsing interface.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.__cache.close()
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 def fairUseDelayExpired(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 Public method to check, if the fair use wait period has expired.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 @return flag indicating expiration
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @rtype bool
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
147 return self.isEnabled() and self.__apiClient.fairUseDelayExpired()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
149 def __showNotificationMessage(self, message, timeout=5):
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
150 """
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
151 Private method to show some message in a notification widget.
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
152
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
153 If desktop notifications have been disabled, the message will
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
154 be shown in the status bar of the main window (either the main
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
155 web browser window or the eric main window)
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
156
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
157 @param message message to be shown
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
158 @type str
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
159 @param timeout amount of time in seconds the message should be shown
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
160 (0 = indefinitely)
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
161 @type int
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
162 """
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
163 from WebBrowser.WebBrowserWindow import WebBrowserWindow
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
164
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
165 if WebBrowserWindow.notificationsEnabled():
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
166 WebBrowserWindow.showNotification(
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
167 UI.PixmapCache.getPixmap("safeBrowsing48.png"),
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
168 self.tr("Google Safe Browsing"),
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
169 message,
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
170 timeout=timeout,
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
171 )
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
172 else:
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
173 statusBar = WebBrowserWindow.globalStatusBar()
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
174 if statusBar is not None:
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
175 statusBar.showMessage(message, timeout * 1000)
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
176
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
177 def __setAutoUpdateThreatLists(self):
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
178 """
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
179 Private method to set auto update for the threat lists.
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
180 """
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
181 autoUpdateEnabled = (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
182 Preferences.getWebBrowser("SafeBrowsingAutoUpdate") and
6233
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
183 not Preferences.getWebBrowser("SafeBrowsingUseLookupApi")
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
184 )
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
185 if autoUpdateEnabled and self.isEnabled():
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
186 nextUpdateDateTime = Preferences.getWebBrowser(
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
187 "SafeBrowsingUpdateDateTime")
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
188 if nextUpdateDateTime.isValid():
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
189 interval = (
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
190 QDateTime.currentDateTime().secsTo(nextUpdateDateTime) + 2
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
191 # 2 seconds extra wait time; interval in milliseconds
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
192 )
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
193
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
194 if interval < 5:
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
195 interval = 5
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
196 # minimum 5 seconds interval
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
197 else:
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
198 interval = 5
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
199 # just wait 5 seconds
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
200 self.__threatListsUpdateTimer.start(interval * 1000)
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
201 else:
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
202 if self.__threatListsUpdateTimer.isActive():
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
203 self.__threatListsUpdateTimer.stop()
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
204
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
205 @pyqtSlot()
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
206 def __threatListsUpdateTimerTimeout(self):
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
207 """
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
208 Private slot to perform the auto update of the threat lists.
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
209 """
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
210 ok = False
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
211 if self.isEnabled():
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
212 self.__showNotificationMessage(
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
213 self.tr("Updating threat lists..."), 0)
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
214 ok = self.updateHashPrefixCache()[0]
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
215 if ok:
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
216 self.__showNotificationMessage(
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
217 self.tr("Updating threat lists done"))
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
218 else:
5842
c3f41b959a65 Fine tuned the safe browsing update notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5839
diff changeset
219 self.__showNotificationMessage(
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
220 self.tr("Updating threat lists failed"))
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
221
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
222 if ok:
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
223 nextUpdateDateTime = (
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
224 self.__apiClient.getFairUseDelayExpirationDateTime()
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
225 )
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
226 Preferences.setWebBrowser("SafeBrowsingUpdateDateTime",
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
227 nextUpdateDateTime)
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
228 self.__threatListsUpdateTimer.start(
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
229 (QDateTime.currentDateTime().secsTo(nextUpdateDateTime) + 2) *
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
230 1000)
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
231 # 2 seconds extra wait time; interval in milliseconds
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
232 else:
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
233 Preferences.setWebBrowser("SafeBrowsingUpdateDateTime",
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
234 QDateTime())
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
235
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 def updateHashPrefixCache(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 Public method to load or update the locally cached threat lists.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 @return flag indicating success and an error message
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 @rtype tuple of (bool, str)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
243 if not self.isEnabled():
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 return False, self.tr("Safe Browsing is disabled.")
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 if not self.__apiClient.fairUseDelayExpired():
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
247 return (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
248 False,
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
249 self.tr("The fair use wait period has not expired yet."
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
250 "Expiration will be at {0}.").format(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
251 self.__apiClient.getFairUseDelayExpirationDateTime()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
252 .toString("yyyy-MM-dd, HH:mm:ss"))
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
253 )
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
255 self.__updatingThreatLists = True
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
256 ok = True
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
257 errorMessage = ""
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
258
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 # step 1: remove expired hashes
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 self.__cache.cleanupFullHashes()
5853
e45a570528a4 Changed the safe browsing code to be less interruptive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5842
diff changeset
261 QCoreApplication.processEvents()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 # step 2: update threat lists
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 threatListsForRemove = {}
6187
2cc7e3629784 Started to fix some unused loop variable warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
265 for threatList, _clientState in self.__cache.getThreatLists():
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 threatListsForRemove[repr(threatList)] = threatList
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
267 threatLists, error = self.__apiClient.getThreatLists()
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
268 if error:
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
269 return False, error
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
270
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
271 maximum = len(threatLists)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
272 current = 0
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
273 self.progressMessage.emit(self.tr("Updating threat lists"), maximum)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 for entry in threatLists:
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
275 current += 1
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
276 self.progress.emit(current)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
277 QCoreApplication.processEvents()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 threatList = ThreatList.fromApiEntry(entry)
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
279 if (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
280 self.__platforms is None or
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
281 threatList.platformType in self.__platforms
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
282 ):
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 self.__cache.addThreatList(threatList)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 key = repr(threatList)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 if key in threatListsForRemove:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 del threatListsForRemove[key]
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
287 maximum = len(threatListsForRemove.values())
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
288 current = 0
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
289 self.progressMessage.emit(self.tr("Deleting obsolete threat lists"),
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
290 maximum)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 for threatList in threatListsForRemove.values():
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
292 current += 1
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
293 self.progress.emit(current)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
294 QCoreApplication.processEvents()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 self.__cache.deleteHashPrefixList(threatList)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 self.__cache.deleteThreatList(threatList)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 del threatListsForRemove
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 # step 3: update threats
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 threatLists = self.__cache.getThreatLists()
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 clientStates = {}
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 for threatList, clientState in threatLists:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 clientStates[threatList.asTuple()] = clientState
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
304 threatsUpdateResponses, error = self.__apiClient.getThreatsUpdate(
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
305 clientStates)
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
306 if error:
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
307 return False, error
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
308
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
309 maximum = len(threatsUpdateResponses)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
310 current = 0
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
311 self.progressMessage.emit(self.tr("Updating hash prefixes"), maximum)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 for response in threatsUpdateResponses:
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
313 current += 1
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
314 self.progress.emit(current)
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
315 QCoreApplication.processEvents()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 responseThreatList = ThreatList.fromApiEntry(response)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 if response["responseType"] == "FULL_UPDATE":
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 self.__cache.deleteHashPrefixList(responseThreatList)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 for removal in response.get("removals", []):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 self.__cache.removeHashPrefixIndices(
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 responseThreatList, removal["rawIndices"]["indices"])
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
322 QCoreApplication.processEvents()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 for addition in response.get("additions", []):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 hashPrefixList = HashPrefixList(
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 addition["rawHashes"]["prefixSize"],
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 base64.b64decode(addition["rawHashes"]["rawHashes"]))
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 self.__cache.populateHashPrefixList(responseThreatList,
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 hashPrefixList)
5821
6c7766cde4c1 Added a progress bar to the management part and fine tuned the hash prefix update process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
329 QCoreApplication.processEvents()
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 expectedChecksum = base64.b64decode(response["checksum"]["sha256"])
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 if self.__verifyThreatListChecksum(responseThreatList,
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 expectedChecksum):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 self.__cache.updateThreatListClientState(
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 responseThreatList, response["newClientState"])
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 else:
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
336 ok = False
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
337 errorMessage = self.tr(
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
338 "Local cache checksum does not match the server. Consider"
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
339 " cleaning the cache. Threat update has been aborted.")
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
340
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
341 self.__updatingThreatLists = False
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
5839
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
343 return ok, errorMessage
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
344
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
345 def isUpdatingThreatLists(self):
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
346 """
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
347 Public method to check, if we are in the process of updating the
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
348 threat lists.
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
349
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
350 @return flag indicating an update process is active
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
351 @rtype bool
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
352 """
fe4d62e23908 Added an auto-update feature to the safe browsing manager of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5831
diff changeset
353 return self.__updatingThreatLists
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 def __verifyThreatListChecksum(self, threatList, remoteChecksum):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 Private method to verify the local checksum of a threat list with the
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 checksum of the safe browsing server.
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
359
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
360 @param threatList threat list to calculate checksum for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
361 @type ThreatList
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
362 @param remoteChecksum SHA256 checksum as reported by the Google server
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
363 @type bytes
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
364 @return flag indicating equality
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
365 @rtype bool
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 localChecksum = self.__cache.hashPrefixListChecksum(threatList)
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 return remoteChecksum == localChecksum
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 def fullCacheCleanup(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 Public method to clean up the cache completely.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 self.__cache.prepareCacheDb()
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 def showSafeBrowsingDialog(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 Public slot to show the safe browsing management dialog.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 if self.__gsbDialog is None:
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 from WebBrowser.WebBrowserWindow import WebBrowserWindow
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 from .SafeBrowsingDialog import SafeBrowsingDialog
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 self.__gsbDialog = SafeBrowsingDialog(
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self, parent=WebBrowserWindow.mainWindow())
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 self.__gsbDialog.show()
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
387
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
388 def lookupUrl(self, url):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
389 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
390 Public method to lookup an URL.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
391
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
392 @param url URL to be checked
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
393 @type str or QUrl
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
394 @return tuple containing the list of threat lists the URL was found in
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
395 and an error message
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
396 @rtype tuple of (list of ThreatList, str)
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
397 @exception ValueError raised for an invalid URL
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
398 """
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
399 if self.isEnabled():
6233
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
400 if self.__useLookupApi:
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
401 if isinstance(url, str):
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
402 url = QUrl(url.strip())
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
403
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
404 if url.isEmpty():
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
405 raise ValueError("Empty URL given.")
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
406
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
407 listNames, error = self.__apiClient.lookupUrl(
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
408 url, self.__platforms)
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
409 return listNames, error
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
410 else:
6233
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
411 if isinstance(url, QUrl):
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
412 urlStr = url.toString().strip()
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
413 else:
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
414 urlStr = url.strip()
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
415
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
416 if not urlStr:
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
417 raise ValueError("Empty URL given.")
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
418
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
419 urlHashes = SafeBrowsingUrl(urlStr).hashes()
a64b986abb54 Web Browser (NG), Safe Browsing: added support for the Google Safe Browsing Lookup API (v4)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6230
diff changeset
420 listNames = self.__lookupHashes(urlHashes)
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
421
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
422 return listNames, ""
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
423
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
424 return None, ""
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
425
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
426 def __lookupHashes(self, fullHashes):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
427 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
428 Private method to lookup the given hashes.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
429
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
430 @param fullHashes list of hashes to lookup
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
431 @type list of bytes
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
432 @return names of threat lists hashes were found in
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
433 @rtype list of ThreatList
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
434 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
435 fullHashes = list(fullHashes)
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
436 cues = [fh[:4].hex() for fh in fullHashes]
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
437 result = []
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
438
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
439 matchingPrefixes = {}
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
440 matchingFullHashes = set()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
441 isPotentialThreat = False
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
442 # Lookup hash prefixes which match full URL hash
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
443 for _threatList, hashPrefix, negativeCacheExpired in (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
444 self.__cache.lookupHashPrefix(cues)
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
445 ):
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
446 for fullHash in fullHashes:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
447 if fullHash.startswith(hashPrefix):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
448 isPotentialThreat = True
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
449 # consider hash prefix negative cache as expired if it
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
450 # is expired in at least one threat list
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
451 matchingPrefixes[hashPrefix] = matchingPrefixes.get(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
452 hashPrefix, False) or negativeCacheExpired
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
453 matchingFullHashes.add(fullHash)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
454
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
455 # if none matches, url hash is clear
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
456 if not isPotentialThreat:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
457 return []
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
458
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
459 # if there is non-expired full hash, URL is blacklisted
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
460 matchingExpiredThreatLists = set()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
461 for threatList, hasExpired in self.__cache.lookupFullHashes(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
462 matchingFullHashes):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
463 if hasExpired:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
464 matchingExpiredThreatLists.add(threatList)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
465 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
466 result.append(threatList)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
467 if result:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
468 return result
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
469
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
470 # If there are no matching expired full hash entries and negative
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
471 # cache is still current for all prefixes, consider it safe.
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
472 if (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
473 len(matchingExpiredThreatLists) == 0 and
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
474 sum(map(int, matchingPrefixes.values())) == 0
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
475 ):
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
476 return []
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
477
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
478 # Now it can be assumed that there are expired matching full hash
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
479 # entries and/or cache prefix entries with expired negative cache.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
480 # Both require full hash synchronization.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
481 self.__syncFullHashes(matchingPrefixes.keys())
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
482
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
483 # Now repeat full hash lookup
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
484 for threatList, hasExpired in self.__cache.lookupFullHashes(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
485 matchingFullHashes):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
486 if not hasExpired:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
487 result.append(threatList)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
488
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
489 return result
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
490
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
491 def __syncFullHashes(self, hashPrefixes):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
492 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
493 Private method to download full hashes matching given prefixes.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
494
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
495 This also updates the cache expiration timestamps.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
496
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
497 @param hashPrefixes list of hash prefixes to get full hashes for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
498 @type list of bytes
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
499 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
500 threatLists = self.__cache.getThreatLists()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
501 clientStates = {}
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
502 for threatList, clientState in threatLists:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
503 clientStates[threatList.asTuple()] = clientState
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
504
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
505 fullHashResponses = self.__apiClient.getFullHashes(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
506 hashPrefixes, clientStates)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
507
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
508 # update negative cache for each hash prefix
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
509 # store full hash with positive cache bumped up
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
510 for match in fullHashResponses["matches"]:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
511 threatList = ThreatList.fromApiEntry(match)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
512 hashValue = base64.b64decode(match["threat"]["hash"])
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
513 cacheDuration = int(match["cacheDuration"].rstrip("s"))
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
514 malwareThreatType = None
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
515 for metadata in match["threatEntryMetadata"].get("entries", []):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
516 key = base64.b64decode(metadata["key"])
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
517 value = base64.b64decode(metadata["value"])
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
518 if key == b"malware_threat_type":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
519 malwareThreatType = value
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
520 if not isinstance(malwareThreatType, str):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
521 malwareThreatType = malwareThreatType.decode()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
522 self.__cache.storeFullHash(threatList, hashValue, cacheDuration,
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
523 malwareThreatType)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
524
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
525 negativeCacheDuration = int(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
526 fullHashResponses["negativeCacheDuration"].rstrip("s"))
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
527 for prefixValue in hashPrefixes:
6187
2cc7e3629784 Started to fix some unused loop variable warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
528 for threatList, _clientState in threatLists:
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
529 self.__cache.updateHashPrefixExpiration(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
530 threatList, prefixValue, negativeCacheDuration)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
531
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
532 @classmethod
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
533 def getIgnoreSchemes(cls):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
534 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
535 Class method to get the schemes not to be checked.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
536
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
537 @return list of schemes to be ignored
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
538 @rtype list of str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
539 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
540 return [
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
541 "about",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
542 "eric",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
543 "qrc",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
544 "qthelp",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
545 "chrome",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
546 "abp",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
547 "file",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
548 ]
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
549
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
550 def getThreatMessage(self, threatType):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
551 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
552 Public method to get a warning message for the given threat type.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
553
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
554 @param threatType threat type to get the message for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
555 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
556 @return threat message
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
557 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
558 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
559 if self.__apiClient:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
560 msg = self.__apiClient.getThreatMessage(threatType)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
561 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
562 msg = ""
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
563
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
564 return msg
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
565
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
566 def getThreatMessages(self, threatLists):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
567 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
568 Public method to get threat messages for the given threats.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
569
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
570 @param threatLists list of threat lists to get a message for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
571 @type list of ThreatList
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
572 @return list of threat messages, one per unique threat type
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
573 @rtype list of str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
574 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
575 threatTypes = set()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
576 for threatList in threatLists:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
577 threatTypes.add(threatList.threatType)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
578
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
579 messages = []
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
580 if self.__apiClient:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
581 for threatType in sorted(threatTypes):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
582 msg = self.__apiClient.getThreatMessage(threatType)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
583 messages.append(msg)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
584
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
585 return messages
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
586
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
587 def getThreatType(self, threatList):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
588 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
589 Public method to get a display string for a given threat type.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
590
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
591 @param threatList threat list to get display string for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
592 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
593 @return display string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
594 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
595 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
596 displayString = ""
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
597 if self.__apiClient:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
598 displayString = self.__apiClient.getThreatType(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
599 threatList.threatType)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
600 return displayString
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
601
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
602 def getPlatformString(self, platformType):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
603 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
604 Public method to get the platform string for a given platform type.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
605
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
606 @param platformType platform type as defined in the v4 API
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
607 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
608 @return platform string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
609 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
610 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
611 if self.__apiClient:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
612 return self.__apiClient.getPlatformString(platformType)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
613 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
614 return ""
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
615
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
616 def getThreatEntryString(self, threatEntry):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
617 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
618 Public method to get the threat entry string.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
619
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
620 @param threatEntry threat entry type as defined in the v4 API
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
621 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
622 @return threat entry string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
623 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
624 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
625 if self.__apiClient:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
626 return self.__apiClient.getThreatEntryString(threatEntry)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
627 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5821
diff changeset
628 return ""

eric ide

mercurial