def testCmacComputation(self): key = bytearray([ 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78 ]) cmac = XTEA_CMAC(key) cmac.update(x2a('de ad be ef')) result = cmac.final() expectedResult = bytearray(x2a('b5 f3 eb 27 15 45 e5 55')) self.assertEqual(result, expectedResult)
def main(): parser = argparse.ArgumentParser( description='Decrypt dumps collected earlier') parser.add_argument('trackerId') args = parser.parse_args() dumpDir = '~/.galileo' db = LocalDatabase(dumpDir) trackerId = args.trackerId trackerDumpDir = db.getDeviceDirectoryName(trackerId) key = db.loadKey(trackerId) files = os.listdir(trackerDumpDir) files = [x for x in files if not 'dec' in x] for filename in files: dumpname = os.path.join(trackerDumpDir, filename) file = open(dumpname) data = file.read() pieces = data.split('\n\n') responsePresent = len(pieces) == 2 if responsePresent: [megadumpData, megadumpResponseData] = pieces else: [megadumpData] = pieces megadump = Dump(MEGADUMP) megadump.data = bytearray(x2a(megadumpData)) megadump.megadump() try: decrypt(megadump, key) except UnknownDumpTypeError: print('Encountered an UnknownDumpTypeError in the dump of file: ' + filename) megadump.toFile(dumpname.replace('.txt', '_dec.txt')) if responsePresent: CHUNK_LEN = 20 megadumpResponse = DumpResponse(x2a(megadumpResponseData), CHUNK_LEN) megadumpResponse.megadump() try: decrypt(megadumpResponse, key, offset=10) except UnknownDumpTypeError: print( 'Encountered an UnknownDumpTypeError in the responsedump of file: ' + filename) megadumpResponse.toFile(dumpname.replace('.txt', '_resp_dec.txt'))
def testParseProtocolHeader(self): block = TrackerBlock() block.data = bytearray(x2a('2E 02 00 00 01 00 D0 00 00 00')) self.assertEqual(block.megadumpType, '2E') self.assertEqual(block.encryption, 1) self.assertEqual(block.nonce, bytearray([0xD0, 0x00, 0x00, 0x00]))
def testDumpProperties(self): dump = Dump(13) dump.data = bytearray( x2a('2E 02 00 00 01 00 D0 00 00 00 AB CD EF 12 34 56')) self.assertEqual(dump.serial, 'ABCDEF123456') self.assertEqual(dump.trackerType, 86)
def testComputeCounter(self): key = bytearray([ 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78 ]) nonce = bytearray([0xDE, 0xAD, 0xBE, 0xEF]) counter = computeCounter(key, nonce) self.assertEqual(counter, bytearray(x2a('a9 3f 69 fc 60 eb 75 25')))
def testMultipleLines(self): self.assertEqual(x2a('00\n01\n02\n03'), [0, 1, 2, 3]) self.assertEqual(x2a('00 01\n02 03'), [0, 1, 2, 3])
def testSimple(self): self.assertEqual(x2a('2'), [2]) self.assertEqual(x2a('02'), [2]) self.assertEqual(x2a('2 3'), [2, 3])
def testDecrypt(self): z = xtea_decrypt(bytearray('0123456789012345', 'utf-8'), bytearray(x2a('B6 7C 01 66 2F F6 96 4A'))) self.assertEqual(a2s(z), 'ABCDEFGH')