Search in sources :

Example 1 with TrustBundleResponse

use of com.microsoft.azure.sdk.iot.device.hsm.parser.TrustBundleResponse 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 2 with TrustBundleResponse

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

the class TrustBundleResponseTest method getCertificatesReturnsCertificates.

// Tests_SRS_TRUSTBUNDLERESPONSE_34_003: [This constructor shall create a new TrustBundleResponse from json.]
@Test
public void getCertificatesReturnsCertificates() {
    // arrange
    TrustBundleResponse response = TrustBundleResponse.fromJson(jsonWithTrustedCertificates);
    // act
    String certificates = response.getCertificates();
    // assert
    assertEquals(testCertificates, certificates);
}
Also used : TrustBundleResponse(com.microsoft.azure.sdk.iot.device.hsm.parser.TrustBundleResponse) Test(org.junit.Test)

Example 3 with TrustBundleResponse

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

the class TrustBundleResponseTest method constructorSavesCertificates.

// Tests_SRS_TRUSTBUNDLERESPONSE_34_001: [This function shall return the saved certificates string.]
@Test
public void constructorSavesCertificates() {
    // act
    TrustBundleResponse response = TrustBundleResponse.fromJson(jsonWithTrustedCertificates);
    String certificates = Deencapsulation.getField(response, "certificates");
    // assert
    assertEquals(testCertificates, certificates);
}
Also used : TrustBundleResponse(com.microsoft.azure.sdk.iot.device.hsm.parser.TrustBundleResponse) Test(org.junit.Test)

Aggregations

TrustBundleResponse (com.microsoft.azure.sdk.iot.device.hsm.parser.TrustBundleResponse)3 Test (org.junit.Test)2 HttpsHsmClient (com.microsoft.azure.sdk.iot.device.hsm.HttpsHsmClient)1