Search in sources :

Example 11 with SecurityProviderTpm

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);
    }
}
Also used : SecurityProviderTpm(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderTpm) ProvisioningDeviceClientAuthenticationException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientAuthenticationException) IOException(java.io.IOException) ProvisioningDeviceClientException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)

Aggregations

SecurityProviderTpm (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderTpm)11 ProvisioningDeviceClientException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)5 Test (org.junit.Test)5 SecurityProviderSymmetricKey (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey)3 IOException (java.io.IOException)3 ProvisioningDeviceSecurityException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceSecurityException)2 SecurityProviderException (com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)2 SecurityProviderTPMEmulator (com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator)2 NonStrictExpectations (mockit.NonStrictExpectations)2 Verifications (mockit.Verifications)2 UrlPathBuilder (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.UrlPathBuilder)1 ProvisioningDeviceClientAuthenticationException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientAuthenticationException)1 ProvisioningDeviceHubException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceHubException)1 DeviceRegistrationResultParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationResultParser)1 RegistrationOperationStatusParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.RegistrationOperationStatusParser)1 SecurityProvider (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider)1 SecurityProviderX509 (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509)1 SecurityProviderX509Cert (com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderX509Cert)1 Scanner (java.util.Scanner)1 KeyManager (javax.net.ssl.KeyManager)1