Search in sources :

Example 1 with HttpsHsmClient

use of com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient in project azure-iot-sdk-java by Azure.

the class HttpHsmSignatureProviderTest method constructorSuccessWithApiVersion.

// Codes_SRS_HTTPHSMSIGNATUREPROVIDER_34_003: [This constructor shall save the provided api version.]
@Test
public void constructorSuccessWithApiVersion() throws NoSuchAlgorithmException, URISyntaxException {
    // act
    HttpHsmSignatureProvider httpHsmSignatureProvider = new HttpHsmSignatureProvider(expectedProviderUri, expectedApiVersion);
    // assert
    assertEquals(expectedApiVersion, Deencapsulation.getField(httpHsmSignatureProvider, "apiVersion"));
    new Verifications() {

        {
            new HttpsHsmClient(expectedProviderUri);
            times = 1;
        }
    };
}
Also used : HttpsHsmClient(com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient) Verifications(mockit.Verifications) HttpHsmSignatureProvider(com.microsoft.azure.sdk.iot.device.hsm.HttpHsmSignatureProvider) Test(org.junit.Test)

Example 2 with HttpsHsmClient

use of com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient in project azure-iot-sdk-java by Azure.

the class HttpHsmSignatureProviderTest method signSuccess.

// Codes_SRS_HTTPHSMSIGNATUREPROVIDER_34_006: [This function shall create a signRequest for the hsm http client to sign, and shall return the utf-8 encoded result of that signing.]
@Test
public void signSuccess(@Mocked URLEncoder mockedURLEncoder) throws NoSuchAlgorithmException, TransportException, IOException, URISyntaxException, HsmException {
    // arrange
    final String keyName = "keyName";
    final String data = "some data";
    final String expectedDigest = "some digest";
    final String expectedDigestEncoded = "some encoded digest";
    new NonStrictExpectations() {

        {
            new HttpsHsmClient(expectedProviderUri);
            result = mockedHttpsHsmClient;
            new SignRequest();
            result = mockedSignRequest;
            mockedHttpsHsmClient.sign(expectedApiVersion, keyName, mockedSignRequest, expectedGenId);
            result = mockedSignResponse;
            mockedSignResponse.getDigest();
            result = expectedDigest;
            URLEncoder.encode(expectedDigest, "UTF-8");
            result = expectedDigestEncoded;
        }
    };
    final HttpHsmSignatureProvider signatureProvider = new HttpHsmSignatureProvider(expectedProviderUri, expectedApiVersion);
    // act
    String actualDigest = signatureProvider.sign(keyName, data, expectedGenId);
    // assert
    assertEquals(expectedDigestEncoded, actualDigest);
    new Verifications() {

        {
            mockedSignRequest.setData(data.getBytes(StandardCharsets.UTF_8));
            mockedSignRequest.setKeyId("primary");
            mockedSignRequest.setAlgo((Mac) Deencapsulation.getField(signatureProvider, "defaultSignRequestAlgo"));
            mockedHttpsHsmClient.sign(expectedApiVersion, keyName, mockedSignRequest, expectedGenId);
            mockedSignResponse.getDigest();
        }
    };
}
Also used : HttpsHsmClient(com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient) SignRequest(com.microsoft.azure.sdk.iot.device.hsm.parser.SignRequest) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) HttpHsmSignatureProvider(com.microsoft.azure.sdk.iot.device.hsm.HttpHsmSignatureProvider) Test(org.junit.Test)

Example 3 with HttpsHsmClient

use of com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient in project azure-iot-sdk-java by Azure.

the class HttpsHsmTrustBundleProvider method getTrustBundleCerts.

/**
 * Retrieve the list of certificates to be trusted as dictated by the HSM
 * @param providerUri the provider uri of the HSM to communicate with
 * @param apiVersion the api version to use
 * @return the raw string containing all of the certificates to be trusted. May be one certificate or many certificates
 * @throws URISyntaxException if the providerUri cannot be parsed as a uri
 * @throws TransportException if the hsm cannot be reacheed
 * @throws IOException if the hsm cannot be reached
 * @throws HsmException if the hsm cannot give the trust bundle
 */
public String getTrustBundleCerts(String providerUri, String apiVersion) throws URISyntaxException, TransportException, IOException, HsmException {
    // Codes_SRS_TRUSTBUNDLEPROVIDER_34_001: [This function shall create an HttpsHsmClient using the provided provider uri.]
    HttpsHsmClient httpsHsmClient = new HttpsHsmClient(providerUri);
    // Codes_SRS_TRUSTBUNDLEPROVIDER_34_002: [This function shall invoke getTrustBundle on the HttpsHsmClient and return the resulting certificates.]
    TrustBundleResponse response = httpsHsmClient.getTrustBundle(apiVersion);
    return response.getCertificates();
}
Also used : TrustBundleResponse(com.microsoft.azure.sdk.iot.device.hsm.parser.TrustBundleResponse) HttpsHsmClient(com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient)

Example 4 with HttpsHsmClient

use of com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient in project azure-iot-sdk-java by Azure.

the class HttpHsmSignatureProviderTest method constructorSuccess.

// Codes_SRS_HTTPHSMSIGNATUREPROVIDER_34_001: [This constructor shall call the overloaded constructor with the default api version.]
// Codes_SRS_HTTPHSMSIGNATUREPROVIDER_34_002: [This constructor shall create a new HttpsHsmClient with the provided providerUri.]
@Test
public void constructorSuccess() throws NoSuchAlgorithmException, URISyntaxException {
    // act
    HttpHsmSignatureProvider httpHsmSignatureProvider = new HttpHsmSignatureProvider(expectedProviderUri, defaultApiVersion);
    // assert
    assertEquals(defaultApiVersion, Deencapsulation.getField(httpHsmSignatureProvider, "apiVersion"));
    new Verifications() {

        {
            new HttpsHsmClient(expectedProviderUri);
            times = 1;
        }
    };
}
Also used : HttpsHsmClient(com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient) Verifications(mockit.Verifications) HttpHsmSignatureProvider(com.microsoft.azure.sdk.iot.device.hsm.HttpHsmSignatureProvider) Test(org.junit.Test)

Aggregations

HttpsHsmClient (com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient)4 HttpHsmSignatureProvider (com.microsoft.azure.sdk.iot.device.hsm.HttpHsmSignatureProvider)3 Verifications (mockit.Verifications)3 Test (org.junit.Test)3 SignRequest (com.microsoft.azure.sdk.iot.device.hsm.parser.SignRequest)1 TrustBundleResponse (com.microsoft.azure.sdk.iot.device.hsm.parser.TrustBundleResponse)1 NonStrictExpectations (mockit.NonStrictExpectations)1