use of com.microsoft.azure.sdk.iot.provisioning.service.configs.IndividualEnrollment in project azure-iot-sdk-java by Azure.
the class ProvisioningTPMTests method provisioningTpmFlow.
@Test
public void provisioningTpmFlow() throws SecurityProviderException, ProvisioningServiceClientException, ProvisioningDeviceClientException, InterruptedException {
ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.createFromConnectionString(provisioningServiceConnectionString);
String registrationId = UUID.randomUUID().toString();
String provisionedDeviceId = "Some-Provisioned-Device-" + TPM + "-" + UUID.randomUUID().toString();
SecurityProvider securityProvider = new SecurityProviderTPMEmulator(registrationId);
Attestation attestation = new TpmAttestation(new String(encodeBase64(((SecurityProviderTpm) securityProvider).getEndorsementKey())));
IndividualEnrollment individualEnrollment = new IndividualEnrollment(registrationId, attestation);
individualEnrollment.setDeviceIdFinal(provisionedDeviceId);
provisioningServiceClient.createOrUpdateIndividualEnrollment(individualEnrollment);
ProvisioningDeviceClient provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningServiceGlobalEndpoint, provisioningServiceIdScope, ProvisioningDeviceClientTransportProtocol.AMQPS, securityProvider);
AtomicBoolean registrationCompleted = new AtomicBoolean(false);
AtomicBoolean registrationCompletedSuccessfully = new AtomicBoolean(false);
provisioningDeviceClient.registerDevice((provisioningDeviceClientRegistrationResult, e, context) -> {
log.debug("Provisioning registration callback fired with result {}", provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus());
if (e != null) {
log.error("Provisioning registration callback fired with exception {}", e);
}
ProvisioningDeviceClientStatus status = provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus();
if (status == ProvisioningDeviceClientStatus.PROVISIONING_DEVICE_STATUS_ASSIGNED) {
registrationCompletedSuccessfully.set(true);
}
registrationCompleted.set(true);
}, null);
long startTime = System.currentTimeMillis();
while (!registrationCompleted.get()) {
Thread.sleep(200);
if (System.currentTimeMillis() - startTime > REGISTRATION_TIMEOUT_MILLISECONDS) {
fail("Timed out waiting for device registration to complete.");
}
}
assertTrue("Registration completed, but not successfully", registrationCompletedSuccessfully.get());
provisioningDeviceClient.closeNow();
}
Aggregations