示例#1
0
async def test_group_of_devices_register_with_no_device_id_for_a_x509_ca_authentication_group_enrollment(
        protocol):
    group_id = "e2e-ca-ilvermorny" + str(uuid.uuid4())
    common_device_id = device_common_name
    devices_indices = type_to_device_indices.get("group_ca")
    device_count_in_group = len(devices_indices)
    reprovision_policy = ReprovisionPolicy(migrate_device_data=True)

    try:
        DPS_GROUP_CA_CERT = os.getenv("PROVISIONING_ROOT_CERT")
        attestation_mechanism = AttestationMechanism.create_with_x509_ca_refs(
            ref1=DPS_GROUP_CA_CERT)
        enrollment_group_provisioning_model = EnrollmentGroup.create(
            group_id,
            attestation=attestation_mechanism,
            reprovision_policy=reprovision_policy)

        service_client.create_or_update(enrollment_group_provisioning_model)

        count = 0
        intermediate_cert_filename = "demoCA/newcerts/intermediate_cert.pem"
        common_device_key_input_file = "demoCA/private/device_key"
        common_device_cert_input_file = "demoCA/newcerts/device_cert"
        common_device_inter_cert_chain_file = "demoCA/newcerts/out_inter_device_chain_cert"
        for index in devices_indices:
            count = count + 1
            device_id = common_device_id + str(index)
            device_key_input_file = common_device_key_input_file + str(
                index) + ".pem"
            device_cert_input_file = common_device_cert_input_file + str(
                index) + ".pem"
            device_inter_cert_chain_file = common_device_inter_cert_chain_file + str(
                index) + ".pem"
            filenames = [device_cert_input_file, intermediate_cert_filename]
            with open(device_inter_cert_chain_file, "w") as outfile:
                for fname in filenames:
                    with open(fname) as infile:
                        logging.debug("Filename is {}".format(fname))
                        content = infile.read()
                        logging.debug(content)
                        outfile.write(content)

            registration_result = await result_from_register(
                registration_id=device_id,
                device_cert_file=device_inter_cert_chain_file,
                device_key_file=device_key_input_file,
                protocol=protocol,
            )

            assert_device_provisioned(device_id=device_id,
                                      registration_result=registration_result)
            device_registry_helper.try_delete_device(device_id)

        # Make sure space is okay. The following line must be outside for loop.
        assert count == device_count_in_group
    finally:
        service_client.delete_enrollment_group_by_param(group_id)
示例#2
0
async def test_group_of_devices_register_with_no_device_id_for_a_x509_intermediate_authentication_group_enrollment(
        protocol):
    group_id = "e2e-intermediate-durmstrang" + str(uuid.uuid4())
    common_device_id = device_common_name
    devices_indices = type_to_device_indices.get("group_intermediate")
    device_count_in_group = len(devices_indices)
    reprovision_policy = ReprovisionPolicy(migrate_device_data=True)

    try:
        intermediate_cert_filename = "demoCA/newcerts/intermediate_cert.pem"
        with open(intermediate_cert_filename, "r") as intermediate_pem:
            intermediate_cert_content = intermediate_pem.read()

        attestation_mechanism = AttestationMechanism.create_with_x509_signing_certs(
            intermediate_cert_content)
        enrollment_group_provisioning_model = EnrollmentGroup.create(
            group_id,
            attestation=attestation_mechanism,
            reprovision_policy=reprovision_policy)

        service_client.create_or_update(enrollment_group_provisioning_model)

        count = 0
        common_device_key_input_file = "demoCA/private/device_key"
        common_device_cert_input_file = "demoCA/newcerts/device_cert"
        common_device_inter_cert_chain_file = "demoCA/newcerts/out_inter_device_chain_cert"
        for index in devices_indices:
            count = count + 1
            device_id = common_device_id + str(index)
            device_key_input_file = common_device_key_input_file + str(
                index) + ".pem"
            device_cert_input_file = common_device_cert_input_file + str(
                index) + ".pem"
            device_inter_cert_chain_file = common_device_inter_cert_chain_file + str(
                index) + ".pem"
            filenames = [device_cert_input_file, intermediate_cert_filename]
            with open(device_inter_cert_chain_file, "w") as outfile:
                for fname in filenames:
                    with open(fname) as infile:
                        outfile.write(infile.read())

            registration_result = await result_from_register(
                registration_id=device_id,
                device_cert_file=device_inter_cert_chain_file,
                device_key_file=device_key_input_file,
                protocol=protocol,
            )

            assert_device_provisioned(device_id=device_id,
                                      registration_result=registration_result)
            device_registry_helper.try_delete_device(device_id)

        # Make sure space is okay. The following line must be outside for loop.
        assert count == device_count_in_group

    finally:
        service_client.delete_enrollment_group_by_param(group_id)