Documentation/Source/eric6.WebBrowser.SafeBrowsing.SafeBrowsingCache.html

changeset 5832
28f36b9c925f
child 5855
726bfb11c1f4
equal deleted inserted replaced
5831:536d97e3f1a1 5832:28f36b9c925f
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.WebBrowser.SafeBrowsing.SafeBrowsingCache</title>
4 <meta charset="UTF-8">
5 <style>
6 body {
7 background: #EDECE6;
8 margin: 0em 1em 10em 1em;
9 color: black;
10 }
11
12 h1 { color: white; background: #85774A; }
13 h2 { color: white; background: #85774A; }
14 h3 { color: white; background: #9D936E; }
15 h4 { color: white; background: #9D936E; }
16
17 a { color: #BA6D36; }
18
19 </style>
20 </head>
21 <body><a NAME="top" ID="top"></a>
22 <h1>eric6.WebBrowser.SafeBrowsing.SafeBrowsingCache</h1>
23 <p>
24 Module implementing a cache for Google Safe Browsing.
25 </p>
26 <h3>Global Attributes</h3>
27 <table>
28 <tr><td>None</td></tr>
29 </table>
30 <h3>Classes</h3>
31 <table>
32 <tr>
33 <td><a href="#HashPrefixList">HashPrefixList</a></td>
34 <td>Class implementing a container for threat list data.</td>
35 </tr><tr>
36 <td><a href="#SafeBrowsingCache">SafeBrowsingCache</a></td>
37 <td>Class implementing a cache for Google Safe Browsing.</td>
38 </tr><tr>
39 <td><a href="#ThreatList">ThreatList</a></td>
40 <td>Class implementing the threat list info.</td>
41 </tr>
42 </table>
43 <h3>Functions</h3>
44 <table>
45 <tr><td>None</td></tr>
46 </table>
47 <hr /><hr />
48 <a NAME="HashPrefixList" ID="HashPrefixList"></a>
49 <h2>HashPrefixList</h2>
50 <p>
51 Class implementing a container for threat list data.
52 </p>
53 <h3>Derived from</h3>
54 object
55 <h3>Class Attributes</h3>
56 <table>
57 <tr><td>None</td></tr>
58 </table>
59 <h3>Class Methods</h3>
60 <table>
61 <tr><td>None</td></tr>
62 </table>
63 <h3>Methods</h3>
64 <table>
65 <tr>
66 <td><a href="#HashPrefixList.__init__">HashPrefixList</a></td>
67 <td>Constructor</td>
68 </tr><tr>
69 <td><a href="#HashPrefixList.__iter__">__iter__</a></td>
70 <td>Special method to iterate over the raw hashes.</td>
71 </tr><tr>
72 <td><a href="#HashPrefixList.__len__">__len__</a></td>
73 <td>Special method to calculate the number of entries.</td>
74 </tr>
75 </table>
76 <h3>Static Methods</h3>
77 <table>
78 <tr><td>None</td></tr>
79 </table>
80 <a NAME="HashPrefixList.__init__" ID="HashPrefixList.__init__"></a>
81 <h4>HashPrefixList (Constructor)</h4>
82 <b>HashPrefixList</b>(<i>prefixLength, rawHashes</i>)
83 <p>
84 Constructor
85 </p><dl>
86 <dt><i>prefixLength</i> (int)</dt>
87 <dd>
88 length of each hash prefix
89 </dd><dt><i>rawHashes</i> (str)</dt>
90 <dd>
91 raw hash prefixes of given length concatenated and
92 sorted in lexicographical order
93 </dd>
94 </dl><a NAME="HashPrefixList.__iter__" ID="HashPrefixList.__iter__"></a>
95 <h4>HashPrefixList.__iter__</h4>
96 <b>__iter__</b>(<i></i>)
97 <p>
98 Special method to iterate over the raw hashes.
99 </p><dl>
100 <dt>Returns:</dt>
101 <dd>
102 iterator object
103 </dd>
104 </dl><dl>
105 <dt>Return Type:</dt>
106 <dd>
107 iterator
108 </dd>
109 </dl><a NAME="HashPrefixList.__len__" ID="HashPrefixList.__len__"></a>
110 <h4>HashPrefixList.__len__</h4>
111 <b>__len__</b>(<i></i>)
112 <p>
113 Special method to calculate the number of entries.
114 </p><dl>
115 <dt>Returns:</dt>
116 <dd>
117 length
118 </dd>
119 </dl><dl>
120 <dt>Return Type:</dt>
121 <dd>
122 int
123 </dd>
124 </dl>
125 <div align="right"><a href="#top">Up</a></div>
126 <hr /><hr />
127 <a NAME="SafeBrowsingCache" ID="SafeBrowsingCache"></a>
128 <h2>SafeBrowsingCache</h2>
129 <p>
130 Class implementing a cache for Google Safe Browsing.
131 </p>
132 <h3>Derived from</h3>
133 QObject
134 <h3>Class Attributes</h3>
135 <table>
136 <tr><td>create_full_hash_cue_idx</td></tr><tr><td>create_full_hash_expires_idx</td></tr><tr><td>create_full_hash_value_idx</td></tr><tr><td>create_full_hashes_stmt</td></tr><tr><td>create_hash_prefix_stmt</td></tr><tr><td>create_threat_list_stmt</td></tr><tr><td>drop_full_hash_cue_idx</td></tr><tr><td>drop_full_hash_expires_idx</td></tr><tr><td>drop_full_hash_value_idx</td></tr><tr><td>drop_full_hashes_stmt</td></tr><tr><td>drop_hash_prefix_stmt</td></tr><tr><td>drop_threat_list_stmt</td></tr>
137 </table>
138 <h3>Class Methods</h3>
139 <table>
140 <tr><td>None</td></tr>
141 </table>
142 <h3>Methods</h3>
143 <table>
144 <tr>
145 <td><a href="#SafeBrowsingCache.__init__">SafeBrowsingCache</a></td>
146 <td>Constructor</td>
147 </tr><tr>
148 <td><a href="#SafeBrowsingCache.__openCacheDb">__openCacheDb</a></td>
149 <td>Private method to open the cache database.</td>
150 </tr><tr>
151 <td><a href="#SafeBrowsingCache.addThreatList">addThreatList</a></td>
152 <td>Public method to add a threat list to the cache.</td>
153 </tr><tr>
154 <td><a href="#SafeBrowsingCache.cleanupFullHashes">cleanupFullHashes</a></td>
155 <td>Public method to clean up full hash entries expired more than the given time.</td>
156 </tr><tr>
157 <td><a href="#SafeBrowsingCache.close">close</a></td>
158 <td>Public method to close the database.</td>
159 </tr><tr>
160 <td><a href="#SafeBrowsingCache.deleteHashPrefixList">deleteHashPrefixList</a></td>
161 <td>Public method to delete hash prefixes for a given threat list.</td>
162 </tr><tr>
163 <td><a href="#SafeBrowsingCache.deleteThreatList">deleteThreatList</a></td>
164 <td>Public method to delete a threat list from the cache.</td>
165 </tr><tr>
166 <td><a href="#SafeBrowsingCache.getHashPrefixValuesToRemove">getHashPrefixValuesToRemove</a></td>
167 <td>Public method to get the hash prefix values to be removed from the cache.</td>
168 </tr><tr>
169 <td><a href="#SafeBrowsingCache.getThreatLists">getThreatLists</a></td>
170 <td>Public method to get the available threat lists.</td>
171 </tr><tr>
172 <td><a href="#SafeBrowsingCache.hashPrefixListChecksum">hashPrefixListChecksum</a></td>
173 <td>Public method to calculate the SHA256 checksum for an alphabetically sorted concatenated list of hash prefixes.</td>
174 </tr><tr>
175 <td><a href="#SafeBrowsingCache.lookupFullHashes">lookupFullHashes</a></td>
176 <td>Public method to get a list of threat lists and expiration flag for the given hashes if a hash is blacklisted.</td>
177 </tr><tr>
178 <td><a href="#SafeBrowsingCache.lookupHashPrefix">lookupHashPrefix</a></td>
179 <td>Public method to look up hash prefixes in the local cache.</td>
180 </tr><tr>
181 <td><a href="#SafeBrowsingCache.populateHashPrefixList">populateHashPrefixList</a></td>
182 <td>Public method to populate the hash prefixes for a threat list.</td>
183 </tr><tr>
184 <td><a href="#SafeBrowsingCache.prepareCacheDb">prepareCacheDb</a></td>
185 <td>Public method to prepare the cache database.</td>
186 </tr><tr>
187 <td><a href="#SafeBrowsingCache.removeHashPrefixIndices">removeHashPrefixIndices</a></td>
188 <td>Public method to remove hash prefixes from the cache.</td>
189 </tr><tr>
190 <td><a href="#SafeBrowsingCache.storeFullHash">storeFullHash</a></td>
191 <td>Public method to store full hash data in the cache database.</td>
192 </tr><tr>
193 <td><a href="#SafeBrowsingCache.updateHashPrefixExpiration">updateHashPrefixExpiration</a></td>
194 <td>Public method to update the hash prefix expiration time.</td>
195 </tr><tr>
196 <td><a href="#SafeBrowsingCache.updateThreatListClientState">updateThreatListClientState</a></td>
197 <td>Public method to update the client state of a threat list.</td>
198 </tr>
199 </table>
200 <h3>Static Methods</h3>
201 <table>
202 <tr><td>None</td></tr>
203 </table>
204 <a NAME="SafeBrowsingCache.__init__" ID="SafeBrowsingCache.__init__"></a>
205 <h4>SafeBrowsingCache (Constructor)</h4>
206 <b>SafeBrowsingCache</b>(<i>dbPath, parent=None</i>)
207 <p>
208 Constructor
209 </p><dl>
210 <dt><i>dbPath</i> (str)</dt>
211 <dd>
212 path to store the cache DB into
213 </dd><dt><i>parent</i> (QObject)</dt>
214 <dd>
215 reference to the parent object
216 </dd>
217 </dl><a NAME="SafeBrowsingCache.__openCacheDb" ID="SafeBrowsingCache.__openCacheDb"></a>
218 <h4>SafeBrowsingCache.__openCacheDb</h4>
219 <b>__openCacheDb</b>(<i></i>)
220 <p>
221 Private method to open the cache database.
222 </p><dl>
223 <dt>Returns:</dt>
224 <dd>
225 flag indicating the open state
226 </dd>
227 </dl><dl>
228 <dt>Return Type:</dt>
229 <dd>
230 bool
231 </dd>
232 </dl><a NAME="SafeBrowsingCache.addThreatList" ID="SafeBrowsingCache.addThreatList"></a>
233 <h4>SafeBrowsingCache.addThreatList</h4>
234 <b>addThreatList</b>(<i>threatList</i>)
235 <p>
236 Public method to add a threat list to the cache.
237 </p><dl>
238 <dt><i>threatList</i> (ThreatList)</dt>
239 <dd>
240 threat list to be added
241 </dd>
242 </dl><a NAME="SafeBrowsingCache.cleanupFullHashes" ID="SafeBrowsingCache.cleanupFullHashes"></a>
243 <h4>SafeBrowsingCache.cleanupFullHashes</h4>
244 <b>cleanupFullHashes</b>(<i>keepExpiredFor=43200</i>)
245 <p>
246 Public method to clean up full hash entries expired more than the
247 given time.
248 </p><dl>
249 <dt><i>keepExpiredFor</i> (int or float)</dt>
250 <dd>
251 time period in seconds of entries to be expired
252 </dd>
253 </dl><a NAME="SafeBrowsingCache.close" ID="SafeBrowsingCache.close"></a>
254 <h4>SafeBrowsingCache.close</h4>
255 <b>close</b>(<i></i>)
256 <p>
257 Public method to close the database.
258 </p><a NAME="SafeBrowsingCache.deleteHashPrefixList" ID="SafeBrowsingCache.deleteHashPrefixList"></a>
259 <h4>SafeBrowsingCache.deleteHashPrefixList</h4>
260 <b>deleteHashPrefixList</b>(<i>threatList</i>)
261 <p>
262 Public method to delete hash prefixes for a given threat list.
263 </p><dl>
264 <dt><i>threatList</i> (ThreatList)</dt>
265 <dd>
266 threat list info object
267 </dd>
268 </dl><a NAME="SafeBrowsingCache.deleteThreatList" ID="SafeBrowsingCache.deleteThreatList"></a>
269 <h4>SafeBrowsingCache.deleteThreatList</h4>
270 <b>deleteThreatList</b>(<i>threatList</i>)
271 <p>
272 Public method to delete a threat list from the cache.
273 </p><dl>
274 <dt><i>threatList</i> (ThreatList)</dt>
275 <dd>
276 threat list to be deleted
277 </dd>
278 </dl><a NAME="SafeBrowsingCache.getHashPrefixValuesToRemove" ID="SafeBrowsingCache.getHashPrefixValuesToRemove"></a>
279 <h4>SafeBrowsingCache.getHashPrefixValuesToRemove</h4>
280 <b>getHashPrefixValuesToRemove</b>(<i>threatList, indexes</i>)
281 <p>
282 Public method to get the hash prefix values to be removed from the
283 cache.
284 </p><dl>
285 <dt><i>threatList</i> (ThreatList)</dt>
286 <dd>
287 threat list to remove prefixes from
288 </dd><dt><i>indexes</i> (list of int)</dt>
289 <dd>
290 list of indexes of prefixes to be removed
291 </dd>
292 </dl><dl>
293 <dt>Returns:</dt>
294 <dd>
295 list of hash prefixes to be removed
296 </dd>
297 </dl><dl>
298 <dt>Return Type:</dt>
299 <dd>
300 list of bytes
301 </dd>
302 </dl><a NAME="SafeBrowsingCache.getThreatLists" ID="SafeBrowsingCache.getThreatLists"></a>
303 <h4>SafeBrowsingCache.getThreatLists</h4>
304 <b>getThreatLists</b>(<i></i>)
305 <p>
306 Public method to get the available threat lists.
307 </p><dl>
308 <dt>Returns:</dt>
309 <dd>
310 list of available threat lists
311 </dd>
312 </dl><dl>
313 <dt>Return Type:</dt>
314 <dd>
315 list of tuples of (ThreatList, str)
316 </dd>
317 </dl><a NAME="SafeBrowsingCache.hashPrefixListChecksum" ID="SafeBrowsingCache.hashPrefixListChecksum"></a>
318 <h4>SafeBrowsingCache.hashPrefixListChecksum</h4>
319 <b>hashPrefixListChecksum</b>(<i>threatList</i>)
320 <p>
321 Public method to calculate the SHA256 checksum for an alphabetically
322 sorted concatenated list of hash prefixes.
323 </p><dl>
324 <dt><i>threatList</i> (ThreatList)</dt>
325 <dd>
326 threat list to calculate checksum for
327 </dd>
328 </dl><dl>
329 <dt>Returns:</dt>
330 <dd>
331 SHA256 checksum
332 </dd>
333 </dl><dl>
334 <dt>Return Type:</dt>
335 <dd>
336 bytes
337 </dd>
338 </dl><a NAME="SafeBrowsingCache.lookupFullHashes" ID="SafeBrowsingCache.lookupFullHashes"></a>
339 <h4>SafeBrowsingCache.lookupFullHashes</h4>
340 <b>lookupFullHashes</b>(<i>hashValues</i>)
341 <p>
342 Public method to get a list of threat lists and expiration flag
343 for the given hashes if a hash is blacklisted.
344 </p><dl>
345 <dt><i>hashValues</i> (list of bytes)</dt>
346 <dd>
347 list of hash values to look up
348 </dd>
349 </dl><dl>
350 <dt>Returns:</dt>
351 <dd>
352 list of tuples containing the threat list info and the
353 expiration flag
354 </dd>
355 </dl><dl>
356 <dt>Return Type:</dt>
357 <dd>
358 list of tuple of (ThreatList, bool)
359 </dd>
360 </dl><a NAME="SafeBrowsingCache.lookupHashPrefix" ID="SafeBrowsingCache.lookupHashPrefix"></a>
361 <h4>SafeBrowsingCache.lookupHashPrefix</h4>
362 <b>lookupHashPrefix</b>(<i>prefixes</i>)
363 <p>
364 Public method to look up hash prefixes in the local cache.
365 </p><dl>
366 <dt><i>prefixes</i> (list of bytes)</dt>
367 <dd>
368 list of hash prefixes to look up
369 </dd>
370 </dl><dl>
371 <dt>Returns:</dt>
372 <dd>
373 list of tuples containing the threat list, full hash and
374 negative cache expiration flag
375 </dd>
376 </dl><dl>
377 <dt>Return Type:</dt>
378 <dd>
379 list of tuple of (ThreatList, bytes, bool)
380 </dd>
381 </dl><a NAME="SafeBrowsingCache.populateHashPrefixList" ID="SafeBrowsingCache.populateHashPrefixList"></a>
382 <h4>SafeBrowsingCache.populateHashPrefixList</h4>
383 <b>populateHashPrefixList</b>(<i>threatList, prefixes</i>)
384 <p>
385 Public method to populate the hash prefixes for a threat list.
386 </p><dl>
387 <dt><i>threatList</i> (ThreatList)</dt>
388 <dd>
389 threat list of the hash prefixes
390 </dd><dt><i>prefixes</i> (HashPrefixList)</dt>
391 <dd>
392 list of hash prefixes to be inserted
393 </dd>
394 </dl><a NAME="SafeBrowsingCache.prepareCacheDb" ID="SafeBrowsingCache.prepareCacheDb"></a>
395 <h4>SafeBrowsingCache.prepareCacheDb</h4>
396 <b>prepareCacheDb</b>(<i></i>)
397 <p>
398 Public method to prepare the cache database.
399 </p><a NAME="SafeBrowsingCache.removeHashPrefixIndices" ID="SafeBrowsingCache.removeHashPrefixIndices"></a>
400 <h4>SafeBrowsingCache.removeHashPrefixIndices</h4>
401 <b>removeHashPrefixIndices</b>(<i>threatList, indexes</i>)
402 <p>
403 Public method to remove hash prefixes from the cache.
404 </p><dl>
405 <dt><i>threatList</i> (ThreatList)</dt>
406 <dd>
407 threat list to delete hash prefixes of
408 </dd><dt><i>indexes</i> (list of int)</dt>
409 <dd>
410 list of indexes of prefixes to be removed
411 </dd>
412 </dl><a NAME="SafeBrowsingCache.storeFullHash" ID="SafeBrowsingCache.storeFullHash"></a>
413 <h4>SafeBrowsingCache.storeFullHash</h4>
414 <b>storeFullHash</b>(<i>threatList, hashValue, cacheDuration, malwareThreatType</i>)
415 <p>
416 Public method to store full hash data in the cache database.
417 </p><dl>
418 <dt><i>threatList</i> (ThreatList)</dt>
419 <dd>
420 threat list info object
421 </dd><dt><i>hashValue</i> (bytes)</dt>
422 <dd>
423 hash to be stored
424 </dd><dt><i>cacheDuration</i> (int or float)</dt>
425 <dd>
426 duration the data should remain in the cache
427 </dd><dt><i>malwareThreatType</i> (str)</dt>
428 <dd>
429 threat type of the malware
430 </dd>
431 </dl><a NAME="SafeBrowsingCache.updateHashPrefixExpiration" ID="SafeBrowsingCache.updateHashPrefixExpiration"></a>
432 <h4>SafeBrowsingCache.updateHashPrefixExpiration</h4>
433 <b>updateHashPrefixExpiration</b>(<i>threatList, hashPrefix, negativeCacheDuration</i>)
434 <p>
435 Public method to update the hash prefix expiration time.
436 </p><dl>
437 <dt><i>threatList</i> (ThreatList)</dt>
438 <dd>
439 threat list info object
440 </dd><dt><i>hashPrefix</i> (bytes)</dt>
441 <dd>
442 hash prefix
443 </dd><dt><i>negativeCacheDuration</i> (int or float)</dt>
444 <dd>
445 time in seconds the entry should remain
446 in the cache
447 </dd>
448 </dl><a NAME="SafeBrowsingCache.updateThreatListClientState" ID="SafeBrowsingCache.updateThreatListClientState"></a>
449 <h4>SafeBrowsingCache.updateThreatListClientState</h4>
450 <b>updateThreatListClientState</b>(<i>threatList, clientState</i>)
451 <p>
452 Public method to update the client state of a threat list.
453 </p><dl>
454 <dt><i>threatList</i> (ThreatList)</dt>
455 <dd>
456 threat list to update the client state for
457 </dd><dt><i>clientState</i> (str)</dt>
458 <dd>
459 new client state
460 </dd>
461 </dl>
462 <div align="right"><a href="#top">Up</a></div>
463 <hr /><hr />
464 <a NAME="ThreatList" ID="ThreatList"></a>
465 <h2>ThreatList</h2>
466 <p>
467 Class implementing the threat list info.
468 </p>
469 <h3>Derived from</h3>
470 object
471 <h3>Class Attributes</h3>
472 <table>
473 <tr><td>None</td></tr>
474 </table>
475 <h3>Class Methods</h3>
476 <table>
477 <tr>
478 <td><a href="#ThreatList.fromApiEntry">fromApiEntry</a></td>
479 <td>Class method to instantiate a threat list given a threat list entry dictionary.</td>
480 </tr>
481 </table>
482 <h3>Methods</h3>
483 <table>
484 <tr>
485 <td><a href="#ThreatList.__init__">ThreatList</a></td>
486 <td>Constructor</td>
487 </tr><tr>
488 <td><a href="#ThreatList.__repr__">__repr__</a></td>
489 <td>Special method to generate a printable representation.</td>
490 </tr><tr>
491 <td><a href="#ThreatList.asTuple">asTuple</a></td>
492 <td>Public method to convert the object to a tuple.</td>
493 </tr>
494 </table>
495 <h3>Static Methods</h3>
496 <table>
497 <tr><td>None</td></tr>
498 </table>
499 <a NAME="ThreatList.fromApiEntry" ID="ThreatList.fromApiEntry"></a>
500 <h4>ThreatList.fromApiEntry (class method)</h4>
501 <b>fromApiEntry</b>(<i>entry</i>)
502 <p>
503 Class method to instantiate a threat list given a threat list entry
504 dictionary.
505 </p><dl>
506 <dt><i>entry</i> (dict)</dt>
507 <dd>
508 threat list entry dictionary
509 </dd>
510 </dl><dl>
511 <dt>Returns:</dt>
512 <dd>
513 instantiated object
514 </dd>
515 </dl><dl>
516 <dt>Return Type:</dt>
517 <dd>
518 ThreatList
519 </dd>
520 </dl><a NAME="ThreatList.__init__" ID="ThreatList.__init__"></a>
521 <h4>ThreatList (Constructor)</h4>
522 <b>ThreatList</b>(<i>threatType, platformType, threatEntryType</i>)
523 <p>
524 Constructor
525 </p><dl>
526 <dt><i>threatType</i> (str)</dt>
527 <dd>
528 threat type
529 </dd><dt><i>platformType</i> (str)</dt>
530 <dd>
531 platform type
532 </dd><dt><i>threatEntryType</i> (str)</dt>
533 <dd>
534 threat entry type
535 </dd>
536 </dl><a NAME="ThreatList.__repr__" ID="ThreatList.__repr__"></a>
537 <h4>ThreatList.__repr__</h4>
538 <b>__repr__</b>(<i></i>)
539 <p>
540 Special method to generate a printable representation.
541 </p><dl>
542 <dt>Returns:</dt>
543 <dd>
544 printable representation
545 </dd>
546 </dl><dl>
547 <dt>Return Type:</dt>
548 <dd>
549 str
550 </dd>
551 </dl><a NAME="ThreatList.asTuple" ID="ThreatList.asTuple"></a>
552 <h4>ThreatList.asTuple</h4>
553 <b>asTuple</b>(<i></i>)
554 <p>
555 Public method to convert the object to a tuple.
556 </p><dl>
557 <dt>Returns:</dt>
558 <dd>
559 tuple containing the threat list info
560 </dd>
561 </dl><dl>
562 <dt>Return Type:</dt>
563 <dd>
564 tuple of (str, str, str)
565 </dd>
566 </dl>
567 <div align="right"><a href="#top">Up</a></div>
568 <hr />
569 </body></html>

eric ide

mercurial