use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.
the class ProvisioningTests method individualEnrollmentGetAttestationMechanismTPM.
@Test
public void individualEnrollmentGetAttestationMechanismTPM() throws ProvisioningServiceClientException, SecurityProviderException {
// with the other TPM tests, so it lives here with them
if (testInstance.attestationType != AttestationType.TPM) {
return;
}
if (testInstance.protocol != HTTPS) {
// The test protocol has no bearing on this test since it only uses the provisioning service client, so the test should only run once.
return;
}
SecurityProvider securityProvider = new SecurityProviderTPMEmulator(testInstance.registrationId, MAX_TPM_CONNECT_RETRY_ATTEMPTS);
Attestation attestation = new TpmAttestation(new String(encodeBase64(((SecurityProviderTpm) securityProvider).getEndorsementKey())));
IndividualEnrollment individualEnrollment = new IndividualEnrollment(testInstance.registrationId, attestation);
testInstance.provisioningServiceClient.createOrUpdateIndividualEnrollment(individualEnrollment);
AttestationMechanism retrievedAttestationMechanism = testInstance.provisioningServiceClient.getIndividualEnrollmentAttestationMechanism(testInstance.registrationId);
assertEquals(retrievedAttestationMechanism.getType(), AttestationMechanismType.TPM);
assertTrue(retrievedAttestationMechanism.getAttestation() instanceof TpmAttestation);
TpmAttestation retrievedTpmAttestation = (TpmAttestation) retrievedAttestationMechanism.getAttestation();
assertNotNull(retrievedTpmAttestation.getEndorsementKey());
}
use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator 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