예제 #1
0
    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


if __name__ == '__main__':
    metadata.test('snapshot.json', 'snapshot.ber', get_asn_signed,
                  get_json_signed, metadata.identity_update_json_signature)
예제 #2
0
        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'])]
            octetString = hash['digest']['octetString'].prettyPrint()
            assert octetString.startswith('0x')
            hash_value = octetString[2:]
            json_hashes[hash_function] = hash_value
        filemeta['hashes'] = json_hashes

        # Optional bit.
        custom = targetAndCustom['custom']
        if custom:
            json_custom = {'ecu_serial': str(custom['ecuIdentifier'])}
            filemeta['custom'] = json_custom

        json_targets[filename] = filemeta

    json_signed['targets'] = json_targets


if __name__ == '__main__':
    metadata.test('targets.json', 'targets.der', get_asn_signed,
                  get_json_signed, metadata.identity_update_json_signature,
                  Metadata)
예제 #3
0
    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


if __name__ == '__main__':
    metadata.test('ecuversionmanifest.json', 'ecuversionmanifest.der',
                  get_asn_signed, get_json_signed,
                  metadata.identity_update_json_signature, ECUVersionManifest)
예제 #4
0
    # Some damned bug in pyasn1 I could not care less to fix right now.
    tokens.setComponentByPosition(numberOfTokens, token, False)
    numberOfTokens += 1
  signed['numberOfTokens'] = numberOfTokens
  signed['tokens'] = tokens
  signed['timestamp'] = metadata.iso8601_to_epoch(json_signed['time'])
  return 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


if __name__ == '__main__':
  metadata.test('timeserver.json', 'timeserver.der', get_asn_signed,
                get_json_signed, metadata.identity_update_json_signature,
                CurrentTime)
예제 #5
0
    signed['body'] = signedBody

    return 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


if __name__ == '__main__':
    metadata.test('timestamp.json', 'timestamp.ber', get_asn_signed,
                  get_json_signed, metadata.identity_update_json_signature)
예제 #6
0
  return signed


def get_json_signed(asn_metadata):
  asn_signed = asn_metadata['signed']

  json_signed = {
      'vin': str(asn_signed['vehicleIdentifier']),
      'primary_ecu_serial': str(asn_signed['primaryIdentifier'])
  }

  json_manifests = []
  numberOfECUVersionManifests = int(asn_signed['numberOfECUVersionManifests'])
  ecuVersionManifests = asn_signed['ecuVersionManifests']
  for i in range(numberOfECUVersionManifests):
    manifest = ecuVersionManifests[i]
    json_manifest = \
              metadata.asn_to_json_metadata(ecuversionmanifest.get_json_signed,
                                            manifest)
    json_manifests.append(json_manifest)
  json_signed['ecu_version_manifests'] = json_manifests

  return json_signed


if __name__ == '__main__':
  metadata.test('vehicleversionmanifest.json', 'vehicleversionmanifest.der',
                get_asn_signed, get_json_signed,
                metadata.identity_update_json_signature,
                VehicleVersionManifest)
예제 #7
0
        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 = str(hash['digest']['hexString'])
            json_hashes[hash_function] = hash_value
        filemeta['hashes'] = json_hashes

        # Optional bit.
        custom = targetAndCustom['custom']
        if custom:
            json_custom = {
                'ecu-serial-number': str(custom['ecuIdentifier']),
                # FIXME: Hard-coded for now!
                'type': 'application'
            }
            filemeta['custom'] = json_custom

        json_targets[filename] = filemeta

    json_signed['targets'] = json_targets


if __name__ == '__main__':
    metadata.test('supplier.json', 'targets.ber', get_asn_signed,
                  get_json_signed, metadata.identity_update_json_signature)