Verify the hash of the fetched blob

This commit is contained in:
Cheng Guo 2018-05-09 21:18:44 +02:00 committed by Pedro Ferreira
parent b26b56632f
commit 166914144d
2 changed files with 6 additions and 1 deletions

View File

@ -10,6 +10,9 @@ from ssb.muxrpc import MuxRPCAPI, MuxRPCAPIException
from ssb.packet_stream import PacketStream, PSMessageType from ssb.packet_stream import PacketStream, PSMessageType
from ssb.util import load_ssb_secret from ssb.util import load_ssb_secret
import hashlib
import base64
api = MuxRPCAPI() api = MuxRPCAPI()
@ -52,6 +55,9 @@ async def test_client():
if msg.type.name == 'BUFFER': if msg.type.name == 'BUFFER':
img_data += msg.data img_data += msg.data
if msg.type.name == 'JSON' and msg.data == b'true': if msg.type.name == 'JSON' and msg.data == b'true':
print(base64.b64encode(hashlib.sha256(img_data).digest()))
assert base64.b64encode(hashlib.sha256(img_data).digest()
) == b'H4MFPEWh7gAbZG/4TaSsaJI6Hi8lh7PItrHTnaxoSfg='
with open('./Autonomouscar1956.jpg', 'wb') as f: with open('./Autonomouscar1956.jpg', 'wb') as f:
f.write(img_data) f.write(img_data)

View File

@ -135,7 +135,6 @@ class PacketStream(object):
if not header or header == b'\x00' * 9: if not header or header == b'\x00' * 9:
return return
flags, length, req = struct.unpack('>BIi', header) flags, length, req = struct.unpack('>BIi', header)
logger.debug('flags=%s length=%s req=%s', flags, length, req)
n_packets = ceil(length / 4096) n_packets = ceil(length / 4096)