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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations