--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Documentation/Source/eric6.WebBrowser.SafeBrowsing.SafeBrowsingCache.html Fri Aug 04 19:43:32 2017 +0200 @@ -0,0 +1,569 @@ +<!DOCTYPE html> +<html><head> +<title>eric6.WebBrowser.SafeBrowsing.SafeBrowsingCache</title> +<meta charset="UTF-8"> +<style> +body { + background: #EDECE6; + margin: 0em 1em 10em 1em; + color: black; +} + +h1 { color: white; background: #85774A; } +h2 { color: white; background: #85774A; } +h3 { color: white; background: #9D936E; } +h4 { color: white; background: #9D936E; } + +a { color: #BA6D36; } + +</style> +</head> +<body><a NAME="top" ID="top"></a> +<h1>eric6.WebBrowser.SafeBrowsing.SafeBrowsingCache</h1> +<p> +Module implementing a cache for Google Safe Browsing. +</p> +<h3>Global Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Classes</h3> +<table> +<tr> +<td><a href="#HashPrefixList">HashPrefixList</a></td> +<td>Class implementing a container for threat list data.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache">SafeBrowsingCache</a></td> +<td>Class implementing a cache for Google Safe Browsing.</td> +</tr><tr> +<td><a href="#ThreatList">ThreatList</a></td> +<td>Class implementing the threat list info.</td> +</tr> +</table> +<h3>Functions</h3> +<table> +<tr><td>None</td></tr> +</table> +<hr /><hr /> +<a NAME="HashPrefixList" ID="HashPrefixList"></a> +<h2>HashPrefixList</h2> +<p> + Class implementing a container for threat list data. +</p> +<h3>Derived from</h3> +object +<h3>Class Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#HashPrefixList.__init__">HashPrefixList</a></td> +<td>Constructor</td> +</tr><tr> +<td><a href="#HashPrefixList.__iter__">__iter__</a></td> +<td>Special method to iterate over the raw hashes.</td> +</tr><tr> +<td><a href="#HashPrefixList.__len__">__len__</a></td> +<td>Special method to calculate the number of entries.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="HashPrefixList.__init__" ID="HashPrefixList.__init__"></a> +<h4>HashPrefixList (Constructor)</h4> +<b>HashPrefixList</b>(<i>prefixLength, rawHashes</i>) +<p> + Constructor +</p><dl> +<dt><i>prefixLength</i> (int)</dt> +<dd> +length of each hash prefix +</dd><dt><i>rawHashes</i> (str)</dt> +<dd> +raw hash prefixes of given length concatenated and + sorted in lexicographical order +</dd> +</dl><a NAME="HashPrefixList.__iter__" ID="HashPrefixList.__iter__"></a> +<h4>HashPrefixList.__iter__</h4> +<b>__iter__</b>(<i></i>) +<p> + Special method to iterate over the raw hashes. +</p><dl> +<dt>Returns:</dt> +<dd> +iterator object +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +iterator +</dd> +</dl><a NAME="HashPrefixList.__len__" ID="HashPrefixList.__len__"></a> +<h4>HashPrefixList.__len__</h4> +<b>__len__</b>(<i></i>) +<p> + Special method to calculate the number of entries. +</p><dl> +<dt>Returns:</dt> +<dd> +length +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +int +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="SafeBrowsingCache" ID="SafeBrowsingCache"></a> +<h2>SafeBrowsingCache</h2> +<p> + Class implementing a cache for Google Safe Browsing. +</p> +<h3>Derived from</h3> +QObject +<h3>Class Attributes</h3> +<table> +<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> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#SafeBrowsingCache.__init__">SafeBrowsingCache</a></td> +<td>Constructor</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.__openCacheDb">__openCacheDb</a></td> +<td>Private method to open the cache database.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.addThreatList">addThreatList</a></td> +<td>Public method to add a threat list to the cache.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.cleanupFullHashes">cleanupFullHashes</a></td> +<td>Public method to clean up full hash entries expired more than the given time.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.close">close</a></td> +<td>Public method to close the database.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.deleteHashPrefixList">deleteHashPrefixList</a></td> +<td>Public method to delete hash prefixes for a given threat list.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.deleteThreatList">deleteThreatList</a></td> +<td>Public method to delete a threat list from the cache.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.getHashPrefixValuesToRemove">getHashPrefixValuesToRemove</a></td> +<td>Public method to get the hash prefix values to be removed from the cache.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.getThreatLists">getThreatLists</a></td> +<td>Public method to get the available threat lists.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.hashPrefixListChecksum">hashPrefixListChecksum</a></td> +<td>Public method to calculate the SHA256 checksum for an alphabetically sorted concatenated list of hash prefixes.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.lookupFullHashes">lookupFullHashes</a></td> +<td>Public method to get a list of threat lists and expiration flag for the given hashes if a hash is blacklisted.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.lookupHashPrefix">lookupHashPrefix</a></td> +<td>Public method to look up hash prefixes in the local cache.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.populateHashPrefixList">populateHashPrefixList</a></td> +<td>Public method to populate the hash prefixes for a threat list.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.prepareCacheDb">prepareCacheDb</a></td> +<td>Public method to prepare the cache database.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.removeHashPrefixIndices">removeHashPrefixIndices</a></td> +<td>Public method to remove hash prefixes from the cache.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.storeFullHash">storeFullHash</a></td> +<td>Public method to store full hash data in the cache database.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.updateHashPrefixExpiration">updateHashPrefixExpiration</a></td> +<td>Public method to update the hash prefix expiration time.</td> +</tr><tr> +<td><a href="#SafeBrowsingCache.updateThreatListClientState">updateThreatListClientState</a></td> +<td>Public method to update the client state of a threat list.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="SafeBrowsingCache.__init__" ID="SafeBrowsingCache.__init__"></a> +<h4>SafeBrowsingCache (Constructor)</h4> +<b>SafeBrowsingCache</b>(<i>dbPath, parent=None</i>) +<p> + Constructor +</p><dl> +<dt><i>dbPath</i> (str)</dt> +<dd> +path to store the cache DB into +</dd><dt><i>parent</i> (QObject)</dt> +<dd> +reference to the parent object +</dd> +</dl><a NAME="SafeBrowsingCache.__openCacheDb" ID="SafeBrowsingCache.__openCacheDb"></a> +<h4>SafeBrowsingCache.__openCacheDb</h4> +<b>__openCacheDb</b>(<i></i>) +<p> + Private method to open the cache database. +</p><dl> +<dt>Returns:</dt> +<dd> +flag indicating the open state +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +bool +</dd> +</dl><a NAME="SafeBrowsingCache.addThreatList" ID="SafeBrowsingCache.addThreatList"></a> +<h4>SafeBrowsingCache.addThreatList</h4> +<b>addThreatList</b>(<i>threatList</i>) +<p> + Public method to add a threat list to the cache. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list to be added +</dd> +</dl><a NAME="SafeBrowsingCache.cleanupFullHashes" ID="SafeBrowsingCache.cleanupFullHashes"></a> +<h4>SafeBrowsingCache.cleanupFullHashes</h4> +<b>cleanupFullHashes</b>(<i>keepExpiredFor=43200</i>) +<p> + Public method to clean up full hash entries expired more than the + given time. +</p><dl> +<dt><i>keepExpiredFor</i> (int or float)</dt> +<dd> +time period in seconds of entries to be expired +</dd> +</dl><a NAME="SafeBrowsingCache.close" ID="SafeBrowsingCache.close"></a> +<h4>SafeBrowsingCache.close</h4> +<b>close</b>(<i></i>) +<p> + Public method to close the database. +</p><a NAME="SafeBrowsingCache.deleteHashPrefixList" ID="SafeBrowsingCache.deleteHashPrefixList"></a> +<h4>SafeBrowsingCache.deleteHashPrefixList</h4> +<b>deleteHashPrefixList</b>(<i>threatList</i>) +<p> + Public method to delete hash prefixes for a given threat list. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list info object +</dd> +</dl><a NAME="SafeBrowsingCache.deleteThreatList" ID="SafeBrowsingCache.deleteThreatList"></a> +<h4>SafeBrowsingCache.deleteThreatList</h4> +<b>deleteThreatList</b>(<i>threatList</i>) +<p> + Public method to delete a threat list from the cache. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list to be deleted +</dd> +</dl><a NAME="SafeBrowsingCache.getHashPrefixValuesToRemove" ID="SafeBrowsingCache.getHashPrefixValuesToRemove"></a> +<h4>SafeBrowsingCache.getHashPrefixValuesToRemove</h4> +<b>getHashPrefixValuesToRemove</b>(<i>threatList, indexes</i>) +<p> + Public method to get the hash prefix values to be removed from the + cache. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list to remove prefixes from +</dd><dt><i>indexes</i> (list of int)</dt> +<dd> +list of indexes of prefixes to be removed +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +list of hash prefixes to be removed +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +list of bytes +</dd> +</dl><a NAME="SafeBrowsingCache.getThreatLists" ID="SafeBrowsingCache.getThreatLists"></a> +<h4>SafeBrowsingCache.getThreatLists</h4> +<b>getThreatLists</b>(<i></i>) +<p> + Public method to get the available threat lists. +</p><dl> +<dt>Returns:</dt> +<dd> +list of available threat lists +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +list of tuples of (ThreatList, str) +</dd> +</dl><a NAME="SafeBrowsingCache.hashPrefixListChecksum" ID="SafeBrowsingCache.hashPrefixListChecksum"></a> +<h4>SafeBrowsingCache.hashPrefixListChecksum</h4> +<b>hashPrefixListChecksum</b>(<i>threatList</i>) +<p> + Public method to calculate the SHA256 checksum for an alphabetically + sorted concatenated list of hash prefixes. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list to calculate checksum for +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +SHA256 checksum +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +bytes +</dd> +</dl><a NAME="SafeBrowsingCache.lookupFullHashes" ID="SafeBrowsingCache.lookupFullHashes"></a> +<h4>SafeBrowsingCache.lookupFullHashes</h4> +<b>lookupFullHashes</b>(<i>hashValues</i>) +<p> + Public method to get a list of threat lists and expiration flag + for the given hashes if a hash is blacklisted. +</p><dl> +<dt><i>hashValues</i> (list of bytes)</dt> +<dd> +list of hash values to look up +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +list of tuples containing the threat list info and the + expiration flag +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +list of tuple of (ThreatList, bool) +</dd> +</dl><a NAME="SafeBrowsingCache.lookupHashPrefix" ID="SafeBrowsingCache.lookupHashPrefix"></a> +<h4>SafeBrowsingCache.lookupHashPrefix</h4> +<b>lookupHashPrefix</b>(<i>prefixes</i>) +<p> + Public method to look up hash prefixes in the local cache. +</p><dl> +<dt><i>prefixes</i> (list of bytes)</dt> +<dd> +list of hash prefixes to look up +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +list of tuples containing the threat list, full hash and + negative cache expiration flag +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +list of tuple of (ThreatList, bytes, bool) +</dd> +</dl><a NAME="SafeBrowsingCache.populateHashPrefixList" ID="SafeBrowsingCache.populateHashPrefixList"></a> +<h4>SafeBrowsingCache.populateHashPrefixList</h4> +<b>populateHashPrefixList</b>(<i>threatList, prefixes</i>) +<p> + Public method to populate the hash prefixes for a threat list. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list of the hash prefixes +</dd><dt><i>prefixes</i> (HashPrefixList)</dt> +<dd> +list of hash prefixes to be inserted +</dd> +</dl><a NAME="SafeBrowsingCache.prepareCacheDb" ID="SafeBrowsingCache.prepareCacheDb"></a> +<h4>SafeBrowsingCache.prepareCacheDb</h4> +<b>prepareCacheDb</b>(<i></i>) +<p> + Public method to prepare the cache database. +</p><a NAME="SafeBrowsingCache.removeHashPrefixIndices" ID="SafeBrowsingCache.removeHashPrefixIndices"></a> +<h4>SafeBrowsingCache.removeHashPrefixIndices</h4> +<b>removeHashPrefixIndices</b>(<i>threatList, indexes</i>) +<p> + Public method to remove hash prefixes from the cache. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list to delete hash prefixes of +</dd><dt><i>indexes</i> (list of int)</dt> +<dd> +list of indexes of prefixes to be removed +</dd> +</dl><a NAME="SafeBrowsingCache.storeFullHash" ID="SafeBrowsingCache.storeFullHash"></a> +<h4>SafeBrowsingCache.storeFullHash</h4> +<b>storeFullHash</b>(<i>threatList, hashValue, cacheDuration, malwareThreatType</i>) +<p> + Public method to store full hash data in the cache database. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list info object +</dd><dt><i>hashValue</i> (bytes)</dt> +<dd> +hash to be stored +</dd><dt><i>cacheDuration</i> (int or float)</dt> +<dd> +duration the data should remain in the cache +</dd><dt><i>malwareThreatType</i> (str)</dt> +<dd> +threat type of the malware +</dd> +</dl><a NAME="SafeBrowsingCache.updateHashPrefixExpiration" ID="SafeBrowsingCache.updateHashPrefixExpiration"></a> +<h4>SafeBrowsingCache.updateHashPrefixExpiration</h4> +<b>updateHashPrefixExpiration</b>(<i>threatList, hashPrefix, negativeCacheDuration</i>) +<p> + Public method to update the hash prefix expiration time. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list info object +</dd><dt><i>hashPrefix</i> (bytes)</dt> +<dd> +hash prefix +</dd><dt><i>negativeCacheDuration</i> (int or float)</dt> +<dd> +time in seconds the entry should remain + in the cache +</dd> +</dl><a NAME="SafeBrowsingCache.updateThreatListClientState" ID="SafeBrowsingCache.updateThreatListClientState"></a> +<h4>SafeBrowsingCache.updateThreatListClientState</h4> +<b>updateThreatListClientState</b>(<i>threatList, clientState</i>) +<p> + Public method to update the client state of a threat list. +</p><dl> +<dt><i>threatList</i> (ThreatList)</dt> +<dd> +threat list to update the client state for +</dd><dt><i>clientState</i> (str)</dt> +<dd> +new client state +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="ThreatList" ID="ThreatList"></a> +<h2>ThreatList</h2> +<p> + Class implementing the threat list info. +</p> +<h3>Derived from</h3> +object +<h3>Class Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr> +<td><a href="#ThreatList.fromApiEntry">fromApiEntry</a></td> +<td>Class method to instantiate a threat list given a threat list entry dictionary.</td> +</tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#ThreatList.__init__">ThreatList</a></td> +<td>Constructor</td> +</tr><tr> +<td><a href="#ThreatList.__repr__">__repr__</a></td> +<td>Special method to generate a printable representation.</td> +</tr><tr> +<td><a href="#ThreatList.asTuple">asTuple</a></td> +<td>Public method to convert the object to a tuple.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="ThreatList.fromApiEntry" ID="ThreatList.fromApiEntry"></a> +<h4>ThreatList.fromApiEntry (class method)</h4> +<b>fromApiEntry</b>(<i>entry</i>) +<p> + Class method to instantiate a threat list given a threat list entry + dictionary. +</p><dl> +<dt><i>entry</i> (dict)</dt> +<dd> +threat list entry dictionary +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +instantiated object +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +ThreatList +</dd> +</dl><a NAME="ThreatList.__init__" ID="ThreatList.__init__"></a> +<h4>ThreatList (Constructor)</h4> +<b>ThreatList</b>(<i>threatType, platformType, threatEntryType</i>) +<p> + Constructor +</p><dl> +<dt><i>threatType</i> (str)</dt> +<dd> +threat type +</dd><dt><i>platformType</i> (str)</dt> +<dd> +platform type +</dd><dt><i>threatEntryType</i> (str)</dt> +<dd> +threat entry type +</dd> +</dl><a NAME="ThreatList.__repr__" ID="ThreatList.__repr__"></a> +<h4>ThreatList.__repr__</h4> +<b>__repr__</b>(<i></i>) +<p> + Special method to generate a printable representation. +</p><dl> +<dt>Returns:</dt> +<dd> +printable representation +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +str +</dd> +</dl><a NAME="ThreatList.asTuple" ID="ThreatList.asTuple"></a> +<h4>ThreatList.asTuple</h4> +<b>asTuple</b>(<i></i>) +<p> + Public method to convert the object to a tuple. +</p><dl> +<dt>Returns:</dt> +<dd> +tuple containing the threat list info +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +tuple of (str, str, str) +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +</body></html> \ No newline at end of file