use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.
the class SecurityProviderTPMEmulatorTest method activateIdentityKeyThrowsOnHSymKeyNull.
// SRS_SecurityProviderTPMEmulator_25_025: [ This method shall throw if loading the created response private onto TPM fails. ]
@Test(expected = SecurityProviderException.class)
public void activateIdentityKeyThrowsOnHSymKeyNull() 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;
}
};
new StrictExpectations() {
{
mockedTpm.Load((TPM_HANDLE) any, (TPM2B_PRIVATE) any, (TPMT_PUBLIC) any);
result = mockedTpmHandle;
}
};
new NonStrictExpectations() {
{
// 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 = mockedCreateResponse;
}
};
new StrictExpectations() {
{
mockedTpm.Load((TPM_HANDLE) any, (TPM2B_PRIVATE) any, (TPMT_PUBLIC) 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 signDataReturnsHMACOnSmallerLength.
@Test
public void signDataReturnsHMACOnSmallerLength(@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 = "less<10".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((TPM_HANDLE) any, (byte[]) any, mockedTpmAlgId);
}
};
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 constructorSavesValidRegistrationId.
// SRS_SecurityProviderTPMEmulator_25_005: [ The constructor shall save the registration Id if it was provided. ]
@Test
public void constructorSavesValidRegistrationId() throws Exception {
for (String regId : VALID_REGISTRATION_IDS) {
createPersistentPrimaryExpectations();
createPersistentPrimaryExpectations();
SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator(regId);
new Verifications() {
{
TpmFactory.localTpmSimulator();
times = 1;
}
};
}
}
use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.
the class SecurityProviderTPMEmulatorTest method constructorSucceedsWithSuccessHandle.
@Test
public void constructorSucceedsWithSuccessHandle() throws Exception {
new NonStrictExpectations() {
{
mockedTpm._allowErrors();
mockedTpm.ReadPublic((TPM_HANDLE) any);
result = mockedReadPublicResponse;
mockedTpm._getLastResponseCode();
result = TPM_RC.SUCCESS;
}
};
SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
new Verifications() {
{
TpmFactory.localTpmSimulator();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator in project azure-iot-sdk-java by Azure.
the class SecurityProviderTPMEmulatorTest method signWithIdentityThrowsOnNullIdKeyPub.
// SRS_SecurityProviderTPMEmulator_25_030: [ This method shall throw SecurityProviderException if ID KEY public was not instantiated. ]
@Test(expected = SecurityProviderException.class)
public void signWithIdentityThrowsOnNullIdKeyPub() throws Exception {
// arrange
final byte[] deviceIdData = "deviceIdData".getBytes(StandardCharsets.UTF_8);
createPersistentPrimaryExpectations();
createPersistentPrimaryExpectations();
SecurityProviderTPMEmulator securityProviderTPMEmulator = new SecurityProviderTPMEmulator();
new NonStrictExpectations() {
{
// idKeyPub
Deencapsulation.setField(securityProviderTPMEmulator, "idKeyPub", null);
}
};
securityProviderTPMEmulator.signWithIdentity(deviceIdData);
}
Aggregations