diff --git a/onionr/api.py b/onionr/api.py index 0490d5a7..d413c2d9 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -125,7 +125,7 @@ class API: except: data = '' startTime = math.floor(time.time()) - # we should keep a hash DB of requests (with hmac) to prevent replays + action = request.args.get('action') #if not self.debug: token = request.args.get('token') diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 19697f47..24529a2f 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import sys, os, core, config, onionrblockapi as block, requests, time, logger, threading, onionrplugins as plugins +import sys, os, core, config, onionrblockapi as block, requests, time, logger, threading, onionrplugins as plugins, base64 import onionrexceptions from defusedxml import minidom @@ -93,7 +93,16 @@ class OnionrCommunicatorDaemon: for blockHash in self.blockQueue: content = self.peerAction(self.pickOnlinePeer(), 'getData', data=blockHash) if content != False: - newBlock = block.Block() + try: + content = content.encode() + except AttributeError: + pass + content = base64.b64decode(content).decode() + if self._core._crypto.sha3Hash(content) == blockHash: + metas = self._core._utils.getBlockMetadataFromData(content) + metadata = metas[0] + meta = metas[1] + #if self._core._crypto.verifyPow(metas[2], metas[1]) return def pickOnlinePeer(self): diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 5246bb88..cf41c861 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -209,6 +209,22 @@ class OnionrUtils: return pass1 + def getBlockMetadataFromData(self, blockData): + ''' + accepts block contents as string and returns a tuple of metadata, meta (meta being internal metadata) + ''' + try: + blockData = blockData.encode() + except AttributeError: + pass + metadata = json.loads(blockData[:blockData.find(b'\n')].decode()) + data = blockData[blockData.find(b'\n'):].decode() + try: + meta = json.loads(metadata['meta']) + except KeyError: + meta = {} + return (metadata, meta, data) + def checkPort(self, port, host=''): ''' Checks if a port is available, returns bool