|
|
@ -68,16 +68,23 @@ public class MqttSslHandlerProvider { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private TransportService transportService; |
|
|
private TransportService transportService; |
|
|
|
|
|
|
|
|
private SSLEngine sslEngine; |
|
|
private SSLContext sslContext; |
|
|
|
|
|
|
|
|
public SslHandler getSslHandler() { |
|
|
public SslHandler getSslHandler() { |
|
|
if (sslEngine == null) { |
|
|
if (sslContext == null) { |
|
|
sslEngine = createSslEngine(); |
|
|
sslContext = createSslContext(); |
|
|
} |
|
|
} |
|
|
|
|
|
SSLEngine sslEngine = sslContext.createSSLEngine(); |
|
|
|
|
|
sslEngine.setUseClientMode(false); |
|
|
|
|
|
sslEngine.setNeedClientAuth(false); |
|
|
|
|
|
sslEngine.setWantClientAuth(true); |
|
|
|
|
|
sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); |
|
|
|
|
|
sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); |
|
|
|
|
|
sslEngine.setEnableSessionCreation(true); |
|
|
return new SslHandler(sslEngine); |
|
|
return new SslHandler(sslEngine); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private SSLEngine createSslEngine() { |
|
|
private SSLContext createSslContext() { |
|
|
try { |
|
|
try { |
|
|
TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
|
|
TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
|
|
KeyStore trustStore = KeyStore.getInstance(keyStoreType); |
|
|
KeyStore trustStore = KeyStore.getInstance(keyStoreType); |
|
|
@ -101,17 +108,10 @@ public class MqttSslHandlerProvider { |
|
|
} |
|
|
} |
|
|
SSLContext sslContext = SSLContext.getInstance(sslProtocol); |
|
|
SSLContext sslContext = SSLContext.getInstance(sslProtocol); |
|
|
sslContext.init(km, tm, null); |
|
|
sslContext.init(km, tm, null); |
|
|
SSLEngine sslEngine = sslContext.createSSLEngine(); |
|
|
return sslContext; |
|
|
sslEngine.setUseClientMode(false); |
|
|
|
|
|
sslEngine.setNeedClientAuth(false); |
|
|
|
|
|
sslEngine.setWantClientAuth(true); |
|
|
|
|
|
sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); |
|
|
|
|
|
sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); |
|
|
|
|
|
sslEngine.setEnableSessionCreation(true); |
|
|
|
|
|
return sslEngine; |
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e); |
|
|
log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e); |
|
|
throw new RuntimeException("Failed to get SSL engine", e); |
|
|
throw new RuntimeException("Failed to get SSL context", e); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|