use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderTpm in project azure-iot-sdk-java by Azure.
the class RegisterTask method authenticateWithTPM.
private RegistrationOperationStatusParser authenticateWithTPM(RequestData requestData) throws ProvisioningDeviceClientException, SecurityProviderException {
try {
if (securityProvider instanceof SecurityProviderTpm) {
SecurityProviderTpm securityClientTpm = (SecurityProviderTpm) securityProvider;
// SRS_RegisterTask_25_011: [ If the provided security client is for Key then, this method shall trigger authenticateWithTPM on the contract API and wait for Authentication Key and decode it from Base64. Also this method shall pass the exception back to the user if it fails. ]
ResponseData nonceResponseData = new ResponseData();
log.debug("Requesting service nonce for tpm authentication");
this.provisioningDeviceClientContract.requestNonceForTPM(requestData, responseCallback, nonceResponseData);
waitForResponse(nonceResponseData);
if (nonceResponseData.getContractState() == DPS_REGISTRATION_RECEIVED) {
if (nonceResponseData.getResponseData() != null) {
// SRS_RegisterTask_25_018: [ If the provided security client is for Key then, this method shall import the Base 64 encoded Authentication Key into the HSM using the security client and pass the exception to the user on failure. ]
log.debug("Received service nonce, activating tpm identity key with it");
securityClientTpm.activateIdentityKey(nonceResponseData.getResponseData());
} else {
// SRS_RegisterTask_25_013: [ If the provided security client is for Key then, this method shall throw ProvisioningDeviceClientException if Authentication Key received is null. ]
throw new ProvisioningDeviceClientAuthenticationException("Service did not send authentication key");
}
log.debug("Authenticating with device provisioning service using the activated tpm identity key");
return authenticateWithSasToken(requestData);
} else {
// SRS_RegisterTask_25_012: [ If the provided security client is for Key then, this method shall throw ProvisioningDeviceClientException if null response is received. ]
throw new ProvisioningDeviceClientException("Did not receive DPS registration nonce successfully");
}
} else {
throw new ProvisioningDeviceClientException("could not identify security provider");
}
} catch (IOException | InterruptedException e) {
throw new ProvisioningDeviceClientException(e);
}
}
Aggregations