use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onConnectionBound_call_flow_and_init_ok_amqp_ws.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_010: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_024: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqp_ws() throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
event.getConnection();
result = connection;
connection.getTransport();
result = transportInternal;
new WebSocketImpl(anyInt);
result = webSocket;
webSocket.configure(anyString, anyString, anyString, 443, anyString, null, null);
transportInternal.addTransportLayer(webSocket);
Proton.sslDomain();
result = sslDomain;
sslDomain.init(SslDomain.Mode.CLIENT);
sslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
transportInternal.ssl(sslDomain);
new IotHubSSLContext();
result = mockedIotHubSSLContext;
}
};
// Act
amqpSendHandler.onConnectionBound(event);
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubX509HardwareIotHubAuthenticationProviderTest method getSSLContextSuccess.
// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_003: [If this object's ssl context has not been generated yet, this function shall generate it from the saved security provider.]
// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_005: [This function shall return the saved IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws SecurityProviderException, IOException, TransportException {
// arrange
IotHubAuthenticationProvider authentication = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
new NonStrictExpectations() {
{
Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
result = mockSSLContext;
mockSecurityProviderX509.getSSLContext();
result = mockSSLContext;
Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { SSLContext.class }, mockSSLContext);
result = mockIotHubSSLContext;
Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
result = mockSSLContext;
}
};
Deencapsulation.setField(authentication, "iotHubSSLContext", null);
// act
SSLContext actualSSLContext = authentication.getSSLContext();
assertEquals(mockSSLContext, actualSSLContext);
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubX509SoftwareIotHubAuthenticationProviderTest method getSSLContextSuccess.
// Tests_SRS_IOTHUBX509SOFTWAREAUTHENTICATION_34_003: [If this object's ssl context has not been generated yet, this function shall generate it from the saved security provider.]
// Tests_SRS_IOTHUBX509SOFTWAREAUTHENTICATION_34_005: [This function shall return the saved IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws IOException, TransportException {
// arrange
IotHubAuthenticationProvider authentication = new IotHubX509SoftwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, publicKeyCertificate, false, privateKey, false);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { String.class, String.class });
result = mockIotHubSSLContext;
Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
result = mockSSLContext;
}
};
Deencapsulation.setField(authentication, "iotHubSSLContext", null);
// act
SSLContext actualSSLContext = authentication.getSSLContext();
assertEquals(mockSSLContext, actualSSLContext);
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class AmqpConnectionHandler method makeDomain.
/**
* Create Proton SslDomain object from Address using the given Ssl mode
* @return The created Ssl domain
*/
private SslDomain makeDomain() {
SslDomain domain = Proton.sslDomain();
try {
if (this.sslContext == null) {
// Need the base trusted certs for IotHub in our ssl context. IotHubSSLContext handles that
domain.setSslContext(new IotHubSSLContext().getSSLContext());
} else {
// Custom SSLContext set by user from service client options
domain.setSslContext(this.sslContext);
}
} catch (Exception e) {
this.savedException = e;
}
domain.init(SslDomain.Mode.CLIENT);
return domain;
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubSSLContextTest method constructorCreatesSSLContext.
// Tests_SRS_IOTHUBSSLCONTEXT_25_001: [**The constructor shall create a default certificate to be used with IotHub.**]**
// Tests_SRS_IOTHUBSSLCONTEXT_25_002: [**The constructor shall create default SSL context for TLSv1.2.**]**
// Tests_SRS_IOTHUBSSLCONTEXT_25_003: [**The constructor shall create default TrustManagerFactory with the default algorithm.**]**
// Tests_SRS_IOTHUBSSLCONTEXT_25_004: [**The constructor shall create default KeyStore instance with the default type and initialize it.**]**
// Tests_SRS_IOTHUBSSLCONTEXT_25_005: [**The constructor shall set the above created certificate into a keystore.**]**
// Tests_SRS_IOTHUBSSLCONTEXT_25_006: [**The constructor shall initialize TrustManagerFactory with the above initialized keystore.**]**
// Tests_SRS_IOTHUBSSLCONTEXT_25_007: [**The constructor shall initialize SSL context with the above initialized TrustManagerFactory and a new secure random.**]**
@Test
public void constructorCreatesSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException {
// arrange
testCollection.add(mockedX509Certificate);
generateSSLContextExpectations();
// act
IotHubSSLContext testContext = Deencapsulation.newInstance(IotHubSSLContext.class);
// assert
generateSSLContextVerifications();
assertNotNull(Deencapsulation.invoke(testContext, "getSSLContext"));
testCollection.remove(mockedX509Certificate);
}
Aggregations