Search in sources :

Example 16 with SecurityProviderTPMEmulator

use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.

the class SecurityProviderTPMEmulatorTest method getStorageRootSucceeds.

// SRS_SecurityProviderTPMEmulator_25_033: [ This method shall return the TPM2B_PUBLIC form of SRK. ]
@Test
public void getStorageRootSucceeds() throws Exception {
    // arrange
    createPersistentPrimaryExpectations();
    createPersistentPrimaryExpectations();
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
    // act //assert
    TestCase.assertNotNull(securityProviderTPMEmulator.getStorageRootKey());
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Example 17 with SecurityProviderTPMEmulator

use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.

the class SecurityProviderTPMEmulatorTest method constructorThrowsOnResponseCodeNotSuccessNotHandle.

@Test(expected = SecurityProviderException.class)
public void constructorThrowsOnResponseCodeNotSuccessNotHandle() throws Exception {
    // arrange
    new StrictExpectations() {

        {
            mockedTpm._allowErrors();
            mockedTpm.ReadPublic((TPM_HANDLE) any);
            result = mockedReadPublicResponse;
            mockedTpm._getLastResponseCode();
            result = TPM_RC.TESTING;
        }
    };
    // act
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Example 18 with SecurityProviderTPMEmulator

use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.

the class ProvisioningTests method reprovisioningFlow.

protected void reprovisioningFlow(EnrollmentType enrollmentType, AllocationPolicy allocationPolicy, ReprovisionPolicy reprovisionPolicy, CustomAllocationDefinition customAllocationDefinition, List<String> iothubsToStartAt, List<String> iothubsToFinishAt, DeviceCapabilities capabilities) throws Exception {
    if (enrollmentType == EnrollmentType.GROUP && testInstance.attestationType != AttestationType.SYMMETRIC_KEY) {
        // tpm doesn't support group, and x509 group test has not been implemented yet
        return;
    }
    testInstance.securityProvider = getSecurityProviderInstance(enrollmentType, allocationPolicy, reprovisionPolicy, customAllocationDefinition, iothubsToStartAt, capabilities);
    ProvisioningStatus provisioningStatus = registerDevice(testInstance.protocol, testInstance.securityProvider, provisioningServiceGlobalEndpoint, true, iothubsToStartAt);
    assertProvisionedDeviceCapabilitiesAreExpected(capabilities, farAwayIotHubConnectionString);
    String expectedReportedPropertyName = "someProperty";
    String expectedReportedPropertyValue = "someValue";
    sendReportedPropertyUpdate(expectedReportedPropertyName, expectedReportedPropertyValue, testInstance.provisionedIotHubUri, testInstance.provisionedDeviceId);
    updateEnrollmentToForceReprovisioning(enrollmentType, iothubsToFinishAt);
    if (testInstance.securityProvider instanceof SecurityProviderTPMEmulator) {
        ((SecurityProviderTPMEmulator) testInstance.securityProvider).shutDown();
        testInstance.securityProvider = new SecurityProviderTPMEmulator(testInstance.registrationId);
    }
    // re-register device, test which hub it was provisioned to
    registerDevice(testInstance.protocol, testInstance.securityProvider, provisioningServiceGlobalEndpoint, true, reprovisionPolicy.getUpdateHubAssignment() ? iothubsToFinishAt : iothubsToStartAt);
    assertTwinIsCorrect(reprovisionPolicy, expectedReportedPropertyName, expectedReportedPropertyValue, !reprovisionPolicy.getUpdateHubAssignment());
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString)

Example 19 with SecurityProviderTPMEmulator

use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.

the class SecurityProviderTPMEmulatorTest method constructorSucceeds.

// SRS_SecurityProviderTPMEmulator_25_001: [ The constructor shall start the local TPM Simulator, clear persistent for EK and SRK if it exist, create persistent primary for EK and SRK. ]
// SRS_SecurityProviderTPMEmulator_25_002: [ The constructor shall set the registration Id to null if none was provided. ]
@Test
public void constructorSucceeds() throws Exception {
    createPersistentPrimaryExpectations();
    createPersistentPrimaryExpectations();
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
    new Verifications() {

        {
            TpmFactory.localTpmSimulator();
            times = 1;
        }
    };
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Example 20 with SecurityProviderTPMEmulator

use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.

the class SecurityProviderTPMEmulatorTest method constructorThrowsOnCreatePrimaryResponseNull.

@Test(expected = SecurityProviderException.class)
public void constructorThrowsOnCreatePrimaryResponseNull() throws Exception {
    // arrange
    new StrictExpectations() {

        {
            mockedTpm._allowErrors();
            mockedTpm.ReadPublic((TPM_HANDLE) any);
            result = mockedReadPublicResponse;
            mockedTpm._getLastResponseCode();
            result = TPM_RC.HANDLE;
            mockedTpm.CreatePrimary((TPM_HANDLE) any, (TPMS_SENSITIVE_CREATE) any, (TPMT_PUBLIC) any, (byte[]) any, (TPMS_PCR_SELECTION[]) any);
            result = null;
        }
    };
    // act
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Aggregations

SecurityProviderTPMEmulator (com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator)32 Test (org.junit.Test)29 SecurityProvider (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider)3 SecurityProviderTpm (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderTpm)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 ProvisioningDeviceClient (com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClient)1 ProvisioningDeviceClientStatus (com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClientStatus)1 ProvisioningDeviceClientException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)1 SecurityProviderSymmetricKey (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey)1 SecurityProviderException (com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)1 SecurityProviderX509Cert (com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderX509Cert)1 ProvisioningServiceClient (com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient)1 Attestation (com.microsoft.azure.sdk.iot.provisioning.service.configs.Attestation)1 IndividualEnrollment (com.microsoft.azure.sdk.iot.provisioning.service.configs.IndividualEnrollment)1 TpmAttestation (com.microsoft.azure.sdk.iot.provisioning.service.configs.TpmAttestation)1 IOException (java.io.IOException)1 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1 DeviceProvisioningServiceTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DeviceProvisioningServiceTest)1