Commit b3dc441428205bc158b1d3e84d6803c078ee7356

Authored by Igor Kulikov
1 parent b2d694f7

Fix io.netty.handler.ssl.SslHandler is not a @Sharable handler

@@ -15,12 +15,10 @@ @@ -15,12 +15,10 @@
15 */ 15 */
16 package org.thingsboard.server.transport.mqtt; 16 package org.thingsboard.server.transport.mqtt;
17 17
18 -import com.google.common.io.Resources;  
19 import io.netty.handler.ssl.SslHandler; 18 import io.netty.handler.ssl.SslHandler;
20 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
21 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.beans.factory.annotation.Value; 21 import org.springframework.beans.factory.annotation.Value;
23 -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;  
24 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 22 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25 import org.springframework.stereotype.Component; 23 import org.springframework.stereotype.Component;
26 import org.springframework.util.StringUtils; 24 import org.springframework.util.StringUtils;
@@ -30,8 +28,8 @@ import org.thingsboard.server.common.msg.EncryptionUtil; @@ -30,8 +28,8 @@ import org.thingsboard.server.common.msg.EncryptionUtil;
30 import org.thingsboard.server.common.transport.TransportService; 28 import org.thingsboard.server.common.transport.TransportService;
31 import org.thingsboard.server.common.transport.TransportServiceCallback; 29 import org.thingsboard.server.common.transport.TransportServiceCallback;
32 import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; 30 import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
33 -import org.thingsboard.server.gen.transport.TransportProtos;  
34 import org.thingsboard.server.common.transport.util.SslUtil; 31 import org.thingsboard.server.common.transport.util.SslUtil;
  32 +import org.thingsboard.server.gen.transport.TransportProtos;
35 33
36 import javax.net.ssl.KeyManager; 34 import javax.net.ssl.KeyManager;
37 import javax.net.ssl.KeyManagerFactory; 35 import javax.net.ssl.KeyManagerFactory;
@@ -40,10 +38,7 @@ import javax.net.ssl.SSLEngine; @@ -40,10 +38,7 @@ import javax.net.ssl.SSLEngine;
40 import javax.net.ssl.TrustManager; 38 import javax.net.ssl.TrustManager;
41 import javax.net.ssl.TrustManagerFactory; 39 import javax.net.ssl.TrustManagerFactory;
42 import javax.net.ssl.X509TrustManager; 40 import javax.net.ssl.X509TrustManager;
43 -import java.io.File;  
44 -import java.io.FileInputStream;  
45 import java.io.InputStream; 41 import java.io.InputStream;
46 -import java.net.URL;  
47 import java.security.KeyStore; 42 import java.security.KeyStore;
48 import java.security.cert.CertificateEncodingException; 43 import java.security.cert.CertificateEncodingException;
49 import java.security.cert.CertificateException; 44 import java.security.cert.CertificateException;
@@ -73,16 +68,16 @@ public class MqttSslHandlerProvider { @@ -73,16 +68,16 @@ public class MqttSslHandlerProvider {
73 @Autowired 68 @Autowired
74 private TransportService transportService; 69 private TransportService transportService;
75 70
76 - private SslHandler sslHandler; 71 + private SSLEngine sslEngine;
77 72
78 public SslHandler getSslHandler() { 73 public SslHandler getSslHandler() {
79 - if (sslHandler == null) {  
80 - sslHandler = createSslHandler(); 74 + if (sslEngine == null) {
  75 + sslEngine = createSslEngine();
81 } 76 }
82 - return sslHandler; 77 + return new SslHandler(sslEngine);
83 } 78 }
84 79
85 - private SslHandler createSslHandler() { 80 + private SSLEngine createSslEngine() {
86 try { 81 try {
87 TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 82 TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
88 KeyStore trustStore = KeyStore.getInstance(keyStoreType); 83 KeyStore trustStore = KeyStore.getInstance(keyStoreType);
@@ -113,10 +108,10 @@ public class MqttSslHandlerProvider { @@ -113,10 +108,10 @@ public class MqttSslHandlerProvider {
113 sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); 108 sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
114 sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); 109 sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
115 sslEngine.setEnableSessionCreation(true); 110 sslEngine.setEnableSessionCreation(true);
116 - return new SslHandler(sslEngine); 111 + return sslEngine;
117 } catch (Exception e) { 112 } catch (Exception e) {
118 log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e); 113 log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e);
119 - throw new RuntimeException("Failed to get SSL handler", e); 114 + throw new RuntimeException("Failed to get SSL engine", e);
120 } 115 }
121 } 116 }
122 117