Search in sources :

Example 6 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 activateIdentityKeyThrowsOnNullIdKeyPub.

// SRS_SecurityProviderTPMEmulator_25_008: [ This method shall throw SecurityProviderException if ID Key Public could not be extracted form TPM. ]
@Test(expected = SecurityProviderException.class)
public void activateIdentityKeyThrowsOnNullIdKeyPub() throws Exception {
    // arrange
    final byte[] testKey = "testKey".getBytes(StandardCharsets.UTF_8);
    createPersistentPrimaryExpectations();
    createPersistentPrimaryExpectations();
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
    new NonStrictExpectations() {

        {
            TPM2B_PUBLIC.fromTpm((TpmBuffer) any);
            result = null;
        }
    };
    // act
    securityProviderTPMEmulator.activateIdentityKey(testKey);
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Example 7 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 signWithIdentityThrowsOnNullHandle.

@Test(expected = SecurityProviderException.class)
public void signWithIdentityThrowsOnNullHandle(@Mocked TPM_ALG_ID mockedTpmAlgId, @Mocked TPMU_ASYM_SCHEME mockedTpmuAsymScheme, @Mocked TPMU_PUBLIC_PARMS mockedTpmuPublicParms, @Mocked TPMS_SCHEME_HMAC mockedTpmsSchemeHmac, @Mocked TPMS_KEYEDHASH_PARMS mockedTpmsKeyedhashParms) throws Exception {
    // arrange
    final byte[] deviceIdData = "deviceIdData".getBytes(StandardCharsets.UTF_8);
    createPersistentPrimaryExpectations();
    createPersistentPrimaryExpectations();
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
    new NonStrictExpectations() {

        {
            // idKeyPub
            Deencapsulation.setField(securityProviderTPMEmulator, "idKeyPub", mockedTpm2BPublic);
            // publicArea
            Deencapsulation.setField(mockedTpm2BPublic, "publicArea", mockedTpmtPublic);
            // parameters
            Deencapsulation.setField(mockedTpmtPublic, "parameters", mockedTpmsKeyedhashParms);
            // scheme
            Deencapsulation.setField(mockedTpmsKeyedhashParms, "scheme", mockedTpmsSchemeHmac);
            // hashAlg
            Deencapsulation.setField(mockedTpmsSchemeHmac, "hashAlg", mockedTpmAlgId);
            TpmHelpers.getTpmProperty(mockedTpm, TPM_PT.INPUT_BUFFER);
            result = 10;
            mockedTpm.HMAC_Start((TPM_HANDLE) any, (byte[]) any, mockedTpmAlgId);
            result = null;
        }
    };
    securityProviderTPMEmulator.signWithIdentity(deviceIdData);
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Example 8 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 constructorThrowsOnReadPublicResponseNull.

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

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

Example 9 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 activateIdentityKeyThrowsOnCreateResponseNull.

// SRS_SecurityProviderTPMEmulator_25_023: [ This method shall throw SecurityProviderException if creating TPMS_SENSITIVE_CREATE for the inner wrap key fails. ]
@Test(expected = SecurityProviderException.class)
public void activateIdentityKeyThrowsOnCreateResponseNull() throws Exception {
    // arrange
    final byte[] testKey = "testKey".getBytes(StandardCharsets.UTF_8);
    createPersistentPrimaryExpectations();
    createPersistentPrimaryExpectations();
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
    new NonStrictExpectations() {

        {
            TPM2B_PUBLIC.fromTpm((TpmBuffer) any);
            result = mockedTpm2BPublic;
            TPM2B_DATA.fromTpm((TpmBuffer) any);
            result = mockedTpm2BData;
            mockedTpm.StartAuthSession((TPM_HANDLE) any, (TPM_HANDLE) any, (byte[]) any, (byte[]) any, (TPM_SE) any, (TPMT_SYM_DEF) any, (TPM_ALG_ID) any);
            result = mockedStartAuthSessionResponse;
            mockedTpm.PolicySecret((TPM_HANDLE) any, (TPM_HANDLE) any, (byte[]) any, (byte[]) any, (byte[]) any, anyInt);
            mockedTpm._withSessions((TPM_HANDLE) any, mockedStartAuthSessionResponse.handle);
            mockedTpm.ActivateCredential((TPM_HANDLE) any, (TPM_HANDLE) any, (TPMS_ID_OBJECT) any, (byte[]) any);
            result = "innerWrapKey".getBytes(StandardCharsets.UTF_8);
            mockedTpm.Import((TPM_HANDLE) any, (byte[]) any, (TPMT_PUBLIC) any, (TPM2B_PRIVATE) any, (byte[]) any, (TPMT_SYM_DEF_OBJECT) any);
            result = mockedTpm2BPrivate;
            mockedTpm.Load((TPM_HANDLE) any, (TPM2B_PRIVATE) any, (TPMT_PUBLIC) any);
            result = mockedTpmHandle;
            // clearPersistentExpectations
            mockedTpm._allowErrors();
            mockedTpm.ReadPublic((TPM_HANDLE) any);
            result = mockedReadPublicResponse;
            mockedTpm._getLastResponseCode();
            result = TPM_RC.SUCCESS;
            mockedTpm.EvictControl((TPM_HANDLE) any, (TPM_HANDLE) any, (TPM_HANDLE) any);
            mockedTpm.EvictControl((TPM_HANDLE) any, (TPM_HANDLE) any, (TPM_HANDLE) any);
            mockedTpm.FlushContext((TPM_HANDLE) any);
            Deencapsulation.setField(mockedTpm2BData, "buffer", "len<10".getBytes(StandardCharsets.UTF_8));
            TpmHelpers.getTpmProperty(mockedTpm, TPM_PT.INPUT_BUFFER);
            result = 10;
            mockedTpm.Create((TPM_HANDLE) any, (TPMS_SENSITIVE_CREATE) any, (TPMT_PUBLIC) any, (byte[]) any, (TPMS_PCR_SELECTION[]) any);
            result = null;
        }
    };
    // act
    securityProviderTPMEmulator.activateIdentityKey(testKey);
}
Also used : SecurityProviderTPMEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator) Test(org.junit.Test)

Example 10 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 activateIdentityKeyThrowsOnHIdKeyNull.

// SRS_SecurityProviderTPMEmulator_25_017: [ This method shall throw SecurityProviderException if loading SRK onto TPM fails. ]
@Test(expected = SecurityProviderException.class)
public void activateIdentityKeyThrowsOnHIdKeyNull() throws Exception {
    // arrange
    final byte[] testKey = "testKey".getBytes(StandardCharsets.UTF_8);
    createPersistentPrimaryExpectations();
    createPersistentPrimaryExpectations();
    SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
    new NonStrictExpectations() {

        {
            TPM2B_PUBLIC.fromTpm((TpmBuffer) any);
            result = mockedTpm2BPublic;
            TPM2B_DATA.fromTpm((TpmBuffer) any);
            result = mockedTpm2BData;
            mockedTpm.StartAuthSession((TPM_HANDLE) any, (TPM_HANDLE) any, (byte[]) any, (byte[]) any, (TPM_SE) any, (TPMT_SYM_DEF) any, (TPM_ALG_ID) any);
            result = mockedStartAuthSessionResponse;
            mockedTpm.PolicySecret((TPM_HANDLE) any, (TPM_HANDLE) any, (byte[]) any, (byte[]) any, (byte[]) any, anyInt);
            mockedTpm._withSessions((TPM_HANDLE) any, mockedStartAuthSessionResponse.handle);
            mockedTpm.ActivateCredential((TPM_HANDLE) any, (TPM_HANDLE) any, (TPMS_ID_OBJECT) any, (byte[]) any);
            result = "innerWrapKey".getBytes(StandardCharsets.UTF_8);
            mockedTpm.Import((TPM_HANDLE) any, (byte[]) any, (TPMT_PUBLIC) any, (TPM2B_PRIVATE) any, (byte[]) any, (TPMT_SYM_DEF_OBJECT) any);
            result = mockedTpm2BPrivate;
            mockedTpm.Load((TPM_HANDLE) any, (TPM2B_PRIVATE) any, (TPMT_PUBLIC) any);
            result = null;
        }
    };
    // act
    securityProviderTPMEmulator.activateIdentityKey(testKey);
}
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