Search in sources :

Example 6 with IotHubSSLContext

use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.

the class IotHubAuthenticationProvider method setSSLContext.

public void setSSLContext(SSLContext sslContext) {
    this.iotHubSSLContext = new IotHubSSLContext(sslContext);
    this.sslContextNeedsUpdate = false;
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext)

Example 7 with IotHubSSLContext

use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.

the class IotHubAuthenticationProviderTest method getSSLContextSuccess.

// Codes_SRS_AUTHENTICATIONPROVIDER_34_011: [This function shall return the generated IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws IOException {
    // arrange
    IotHubAuthenticationProvider sasAuth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(IotHubSSLContext.class);
            result = mockedIotHubSSLContext;
            Deencapsulation.invoke(mockedIotHubSSLContext, "getSSLContext");
            result = mockedSSLContext;
        }
    };
    // act
    SSLContext actualSSLContext = sasAuth.getSSLContext();
    // assert
    assertEquals(mockedSSLContext, actualSSLContext);
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) SSLContext(javax.net.ssl.SSLContext) IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) Test(org.junit.Test)

Example 8 with IotHubSSLContext

use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.

the class IotHubAuthenticationProviderTest method constructorSuccessWithSSLContext.

@Test
public void constructorSuccessWithSSLContext() {
    // arrange
    new Expectations() {

        {
            new IotHubSSLContext(mockedSSLContext);
            result = mockedIotHubSSLContext;
        }
    };
    // act
    IotHubAuthenticationProvider iotHubAuthenticationProvider = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId, mockedSSLContext);
    // assert
    assertFalse((boolean) Deencapsulation.getField(iotHubAuthenticationProvider, "sslContextNeedsUpdate"));
    assertEquals(expectedHostname, Deencapsulation.getField(iotHubAuthenticationProvider, "hostname"));
    assertEquals(expectedGatewayHostname, Deencapsulation.getField(iotHubAuthenticationProvider, "gatewayHostname"));
    assertEquals(expectedDeviceId, Deencapsulation.getField(iotHubAuthenticationProvider, "deviceId"));
    assertEquals(expectedModuleId, Deencapsulation.getField(iotHubAuthenticationProvider, "moduleId"));
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) Test(org.junit.Test)

Example 9 with IotHubSSLContext

use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.

the class IotHubSasTokenHardwareAuthenticationProviderTest method getSSLContextSuccess.

// Tests_SRS_IOTHUBSASTOKENHARDWAREAUTHENTICATION_34_008: [This function shall return the generated IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws IOException, InvalidKeyException, SecurityProviderException {
    // arrange
    final String someToken = "someToken";
    final byte[] tokenBytes = someToken.getBytes(StandardCharsets.UTF_8);
    new NonStrictExpectations() {

        {
            URLEncoder.encode(anyString, encodingName);
            result = someToken;
            mockSecurityProviderTpm.signWithIdentity((byte[]) any);
            result = tokenBytes;
            encodeBase64((byte[]) any);
            result = tokenBytes;
            URLEncoder.encode(anyString, encodingName);
            result = someToken;
            mockSecurityProviderTpm.getSSLContext();
            result = mockSSLContext;
            Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { SSLContext.class }, mockSSLContext);
            result = mockIotHubSSLContext;
            mockSecurityProviderTpm.getSSLContext();
            result = mockSSLContext;
            Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { SSLContext.class }, mockSSLContext);
            result = mockIotHubSSLContext;
            Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
            result = mockSSLContext;
        }
    };
    IotHubSasTokenAuthenticationProvider sasTokenAuthentication = new IotHubSasTokenHardwareAuthenticationProvider(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId, mockSecurityProviderTpm);
    // act
    SSLContext actualSSLContext = sasTokenAuthentication.getSSLContext();
    // assert
    assertEquals(mockSSLContext, actualSSLContext);
}
Also used : SSLContext(javax.net.ssl.SSLContext) IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) Test(org.junit.Test)

Example 10 with IotHubSSLContext

use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.

the class MultiplexingClientTests method registrationsUnwindForX509Client.

@Test
public void registrationsUnwindForX509Client() throws Exception {
    // Create a new device client that uses x509 auth, which should throw an UnsupportedOperationException
    // since x509 auth isn't supported while multiplexing
    Device x509Device = Tools.getTestDevice(iotHubConnectionString, IotHubClientProtocol.MQTT, AuthenticationType.SELF_SIGNED, false).getDevice();
    String deviceConnectionString = registryManager.getDeviceConnectionString(x509Device);
    DeviceClient x509DeviceClient = new DeviceClient(deviceConnectionString, testInstance.protocol, new IotHubSSLContext().getSSLContext());
    registrationsUnwindForUnsupportedOperationExceptions(x509DeviceClient);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) Device(com.microsoft.azure.sdk.iot.service.Device) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) Test(org.junit.Test)

Aggregations

IotHubSSLContext (com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext)18 Test (org.junit.Test)14 SSLContext (javax.net.ssl.SSLContext)7 IotHubAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider)3 X509Certificate (java.security.cert.X509Certificate)3 ArrayList (java.util.ArrayList)3 Device (com.microsoft.azure.sdk.iot.service.Device)2 IOException (java.io.IOException)2 WebSocketImpl (com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl)1 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)1 IotHubX509HardwareAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider)1 TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)1 Message (com.microsoft.azure.sdk.iot.service.Message)1 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)1 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)1 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)1 ServiceClientOptions (com.microsoft.azure.sdk.iot.service.ServiceClientOptions)1 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)1