def get_json_signed(asn_metadata): json_signed = {'_type': 'Snapshot'} asn_signed = asn_metadata['signed'] json_signed['expires'] = metadata.epoch_to_iso8601(asn_signed['expires']) json_signed['version'] = int(asn_signed['version']) snapshotMetadata = asn_signed['body']['snapshotMetadata'] numberOfSnapshotMetadataFiles = \ int(snapshotMetadata['numberOfSnapshotMetadataFiles']) snapshotMetadataFiles = snapshotMetadata['snapshotMetadataFiles'] json_meta = {} for i in range(numberOfSnapshotMetadataFiles): snapshotMetadataFile = snapshotMetadataFiles[i] filename = str(snapshotMetadataFile['filename']) filemeta = {'version': int(snapshotMetadataFile['version'])} if filename == 'root.json': filemeta['length'] = int(snapshotMetadataFile['length']) filemeta['hashes'] = { 'sha256': str(snapshotMetadataFile['hashes'][0]['digest']['hexString']) } json_meta[filename] = filemeta json_signed['meta'] = json_meta return json_signed
def get_json_signed(asn_metadata): json_signed = { '_type': 'Root', 'compression_algorithms': ['gz'], 'consistent_snapshot': False } asn_signed = asn_metadata['signed'] json_signed['expires'] = metadata.epoch_to_iso8601(asn_signed['expires']) json_signed['version'] = int(asn_signed['version']) rootMetadata = asn_signed['body']['rootMetadata'] assert rootMetadata['numberOfKeys'] == 4 keys = rootMetadata['keys'] json_keys = {} for i in range(4): publicKey = keys[i] publicKeyid = str(publicKey['publicKeyid']) # Only ed25519 keys allowed for now. publicKeyType = int(publicKey['publicKeyType']) assert publicKeyType == 1 publicKeyType = 'ed25519' publicKeyValue = str(publicKey['publicKeyValue']['hexString']) json_keys[publicKeyid] = { 'keyid_hash_algorithms': ['sha256', 'sha512'], 'keytype': publicKeyType, 'keyval': { 'public': publicKeyValue } } json_signed['keys'] = json_keys assert rootMetadata['numberOfRoles'] == 4 roles = rootMetadata['roles'] json_roles = {} # Quick workaround for now. roletype_to_rolename = { 0: 'root', 1: 'targets', 2: 'snapshot', 3: 'timestamp' } for i in range(4): topLevelRole = roles[i] rolename = roletype_to_rolename[int(topLevelRole['role'])] assert topLevelRole['numberOfKeyids'] == 1 keyids = [str(topLevelRole['keyids'][0])] threshold = int(topLevelRole['threshold']) assert threshold == 1 json_roles[rolename] = { 'keyids': keyids, 'threshold': threshold } json_signed['roles'] = json_roles return json_signed
def get_json_signed(asn_metadata): asn_signed = asn_metadata['signed'] timeserver_time = metadata.epoch_to_iso8601(asn_signed['currentTime']) previous_timeserver_time = \ metadata.epoch_to_iso8601(asn_signed['previousTime']) ecu_serial = str(asn_signed['ecuIdentifier']) target = asn_signed['installedImage'] filepath = str(target['filename']) fileinfo = {'length': int(target['length'])} numberOfHashes = int(target['numberOfHashes']) # Quick workaround for now. hashenum_to_hashfunction = {1: 'sha256', 3: 'sha512'} hashes = target['hashes'] json_hashes = {} for j in range(numberOfHashes): hash = hashes[j] hash_function = hashenum_to_hashfunction[int(hash['function'])] hash_value = hash['digest']['octetString'].prettyPrint() assert hash_value.startswith('0x') hash_value = hash_value[2:] json_hashes[hash_function] = hash_value fileinfo['hashes'] = json_hashes installed_image = {'filepath': filepath, 'fileinfo': fileinfo} json_signed = { 'ecu_serial': ecu_serial, 'installed_image': installed_image, 'previous_timeserver_time': previous_timeserver_time, 'timeserver_time': timeserver_time } # Optional bit. attacks_detected = asn_signed['securityAttack'] if attacks_detected: json_signed['attacks_detected'] = str(attacks_detected) return json_signed
def get_json_signed(asn_metadata): asn_signed = asn_metadata['signed'] json_signed = { 'time': metadata.epoch_to_iso8601(asn_signed['timestamp']) } numberOfTokens = int(asn_signed['numberOfTokens']) tokens = asn_signed['tokens'] json_tokens = [] for i in range(numberOfTokens): json_tokens.append(int(tokens[i])) json_signed['tokens'] = json_tokens return json_signed
def get_json_signed(asn_metadata): json_signed = { '_type': 'Targets', 'delegations': { 'keys': {}, 'roles': [] }, } asn_signed = asn_metadata['signed'] json_signed['expires'] = metadata.epoch_to_iso8601(asn_signed['expires']) json_signed['version'] = int(asn_signed['version']) targetsMetadata = asn_signed['body']['targetsMetadata'] set_json_targets(json_signed, targetsMetadata) set_json_delegations(json_signed, targetsMetadata) return json_signed
def get_json_signed(asn_metadata): json_signed = {'_type': 'Timestamp'} asn_signed = asn_metadata['signed'] json_signed['expires'] = metadata.epoch_to_iso8601(asn_signed['expires']) json_signed['version'] = int(asn_signed['version']) timestampMetadata = asn_signed['body']['timestampMetadata'] json_signed['meta'] = { 'snapshot.json': { 'hashes': { 'sha256': str(timestampMetadata['hashes'][0]['digest']['hexString']) }, 'length': int(timestampMetadata['length']), 'version': int(timestampMetadata['version']) } } return json_signed
def get_json_signed(asn_metadata): json_signed = {'_type': 'Snapshot'} asn_signed = asn_metadata['signed'] json_signed['expires'] = metadata.epoch_to_iso8601(asn_signed['expires']) json_signed['version'] = int(asn_signed['version']) snapshotMetadata = asn_signed['body']['snapshotMetadata'] numberOfSnapshotMetadataFiles = \ int(snapshotMetadata['numberOfSnapshotMetadataFiles']) snapshotMetadataFiles = snapshotMetadata['snapshotMetadataFiles'] json_meta = {} for i in range(numberOfSnapshotMetadataFiles): snapshotMetadataFile = snapshotMetadataFiles[i] filename = str(snapshotMetadataFile['filename']) filemeta = {'version': int(snapshotMetadataFile['version'])} json_meta[filename] = filemeta json_signed['meta'] = json_meta return json_signed
def get_json_signed(asn_metadata): json_signed = { '_type': 'Timestamp' } asn_signed = asn_metadata['signed'] json_signed['expires'] = metadata.epoch_to_iso8601(asn_signed['expires']) json_signed['version'] = int(asn_signed['version']) timestampMetadata = asn_signed['body']['timestampMetadata'] sha256 = timestampMetadata['hashes'][0]['digest']['octetString'].prettyPrint() assert sha256.startswith('0x') sha256 = sha256[2:] json_signed['meta'] = { 'snapshot.json' : { 'hashes': { 'sha256': sha256 }, 'length': int(timestampMetadata['length']), 'version': int(timestampMetadata['version']) } } return json_signed