From 9502b01b49d004a46738aa899c5136efb466d2bb Mon Sep 17 00:00:00 2001 From: imhao183 Date: Thu, 24 Dec 2020 12:35:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=8A=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 6 - .../java/io/moquette/BrokerConstants.java | 3 - .../main/java/io/moquette/server/Server.java | 2 +- .../io/moquette/server/config/IConfig.java | 4 - .../moquette/server/config/MemoryConfig.java | 13 -- .../moquette/server/netty/NettyAcceptor.java | 115 ------------------ .../src/main/resources/wildfirechat.conf | 6 - 7 files changed, 1 insertion(+), 148 deletions(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 97dbb0b7..acf99f5e 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -20,9 +20,6 @@ port 1883 ##客户端短链接端口 http_port 80 -##WEB客户端长链接端口 -websocket_port 8083 - #管理端口 http.admin.port 18080 @@ -46,9 +43,6 @@ http.admin.secret_key 123456 ##这个地方上线前要改为false http.admin.no_check_time true -##客户端协议栈密钥,需要与客户端协议栈文件libemqq.cc文件中的aes_key值保持一致,16进制byte用逗号分割。这个密钥对安全性帮助不大,客户不要修改 -client.proto.secret_key 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F - ##用来生产im token的私钥,只在服务器使用,客户端不用。正式使用时为了安全一定要修改这个值,切记切记 token.key testim diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 450c0abb..5d437be5 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -35,7 +35,6 @@ public final class BrokerConstants { public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb"; public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.dir") + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; - public static final String WEB_SOCKET_PORT_PROPERTY_NAME = "websocket_port"; public static final String WSS_PORT_PROPERTY_NAME = "secure_websocket_port"; public static final String SSL_PORT_PROPERTY_NAME = "ssl_port"; public static final String JKS_PATH_PROPERTY_NAME = "jks_path"; @@ -47,7 +46,6 @@ public final class BrokerConstants { public static final String DB_AUTHENTICATOR_QUERY = "authenticator.db.query"; public static final String DB_AUTHENTICATOR_DIGEST = "authenticator.db.digest"; public static final int PORT = 1883; - public static final int WEBSOCKET_PORT = 8080; public static final String DISABLED_PORT_BIND = "disabled"; public static final String HOST = "0.0.0.0"; public static final String NEED_CLIENT_AUTH = "need_client_auth"; @@ -115,7 +113,6 @@ public final class BrokerConstants { public static final String HTTP_SERVER_SECRET_KEY = "http.admin.secret_key"; public static final String HTTP_SERVER_API_NO_CHECK_TIME = "http.admin.no_check_time"; - public static final String CLIENT_PROTO_SECRET_KEY = "client.proto.secret_key"; public static final String TOKEN_SECRET_KEY = "token.key"; public static final String TOKEN_EXPIRE_TIME = "token.expire_time"; diff --git a/broker/src/main/java/io/moquette/server/Server.java b/broker/src/main/java/io/moquette/server/Server.java index 3ebaf282..0fca413d 100755 --- a/broker/src/main/java/io/moquette/server/Server.java +++ b/broker/src/main/java/io/moquette/server/Server.java @@ -226,7 +226,7 @@ public class Server { handlers = Collections.emptyList(); } DBUtil.init(config); - String strKey = config.getProperty(BrokerConstants.CLIENT_PROTO_SECRET_KEY); + String strKey = "0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F"; String[] strs = strKey.split(","); if(strs.length != 16) { LOG.error("Key error, it length should be 16"); diff --git a/broker/src/main/java/io/moquette/server/config/IConfig.java b/broker/src/main/java/io/moquette/server/config/IConfig.java index 846d5b55..08240127 100644 --- a/broker/src/main/java/io/moquette/server/config/IConfig.java +++ b/broker/src/main/java/io/moquette/server/config/IConfig.java @@ -35,10 +35,6 @@ public abstract class IConfig { void assignDefaults() { setProperty(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT)); setProperty(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST); - // setProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, - // Integer.toString(BrokerConstants.WEBSOCKET_PORT)); - // setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, - // BrokerConstants.DEFAULT_PERSISTENT_PATH); setProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, ""); } diff --git a/broker/src/main/java/io/moquette/server/config/MemoryConfig.java b/broker/src/main/java/io/moquette/server/config/MemoryConfig.java index 8917761c..378d2876 100644 --- a/broker/src/main/java/io/moquette/server/config/MemoryConfig.java +++ b/broker/src/main/java/io/moquette/server/config/MemoryConfig.java @@ -33,19 +33,6 @@ public class MemoryConfig extends IConfig { } } - // private void createDefaults() { - // m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT)); - // m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST); - // m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, - // Integer.toString(BrokerConstants.WEBSOCKET_PORT)); - // m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, ""); - // m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, - // BrokerConstants.DEFAULT_PERSISTENT_PATH); - // m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); - // m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, ""); - // m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, ""); - // } - @Override public void setProperty(String name, String value) { m_properties.setProperty(name, value); diff --git a/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java b/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java index 25a85bd7..8de0b417 100644 --- a/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java +++ b/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java @@ -58,35 +58,6 @@ import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE; public class NettyAcceptor implements ServerAcceptor { - private static final String MQTT_SUBPROTOCOL_CSV_LIST = "mqtt, mqttv3.1, mqttv3.1.1"; - - static class WebSocketFrameToByteBufDecoder extends MessageToMessageDecoder { - - @Override - protected void decode(ChannelHandlerContext chc, BinaryWebSocketFrame frame, List out) - throws Exception { - // convert the frame to a ByteBuf - ByteBuf bb = frame.content(); - // System.out.println("WebSocketFrameToByteBufDecoder decode - " + - // ByteBufUtil.hexDump(bb)); - bb.retain(); - out.add(bb); - } - } - - static class ByteBufToWebSocketFrameEncoder extends MessageToMessageEncoder { - - @Override - protected void encode(ChannelHandlerContext chc, ByteBuf bb, List out) throws Exception { - // convert the ByteBuf to a WebSocketFrame - BinaryWebSocketFrame result = new BinaryWebSocketFrame(); - // System.out.println("ByteBufToWebSocketFrameEncoder encode - " + - // ByteBufUtil.hexDump(bb)); - result.content().writeBytes(bb); - out.add(result); - } - } - abstract class PipelineInitializer { abstract void init(ChannelPipeline pipeline) throws Exception; @@ -145,17 +116,6 @@ public class NettyAcceptor implements ServerAcceptor { this.errorsCather = Optional.empty(); initializePlainTCPTransport(mqttHandler, props); - String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME); - String wssPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME); - if (sslTcpPortProp != null || wssPortProp != null) { - SSLContext sslContext = sslCtxCreator.initSSLContext(); - if (sslContext == null) { - LOG.error("Can't initialize SSLHandler layer! Exiting, check your configuration of jks"); - return; - } - initializeSSLTCPTransport(mqttHandler, props, sslContext); - initializeWSSTransport(mqttHandler, props, sslContext); - } } private void initFactory(String host, int port, String protocol, final PipelineInitializer pipeliner) { @@ -233,81 +193,6 @@ public class NettyAcceptor implements ServerAcceptor { }); } - private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext) - throws IOException { - LOG.info("Configuring SSL MQTT transport"); - String sslPortProp = props.getProperty(SSL_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); - if (DISABLED_PORT_BIND.equals(sslPortProp)) { - // Do nothing no SSL configured - LOG.info("Property {} has been set to {}. SSL MQTT will be disabled", - BrokerConstants.SSL_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); - return; - } - - int sslPort = Integer.parseInt(sslPortProp); - LOG.info("Starting SSL on port {}", sslPort); - - final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler(); - String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); - String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false"); - final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth); - initFactory(host, sslPort, "SSL MQTT", new PipelineInitializer() { - - @Override - void init(ChannelPipeline pipeline) throws Exception { - pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth)); - pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0)); - pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler); - // pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR)); - pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector)); - pipeline.addLast("decoder", new MqttDecoder()); - pipeline.addLast("encoder", MqttEncoder.INSTANCE); - pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector)); - pipeline.addLast("messageLogger", new MQTTMessageLogger()); - pipeline.addLast("handler", handler); - } - }); - } - - private void initializeWSSTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext) - throws IOException { - LOG.info("Configuring secure websocket MQTT transport"); - String sslPortProp = props.getProperty(WSS_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); - if (DISABLED_PORT_BIND.equals(sslPortProp)) { - // Do nothing no SSL configured - LOG.info("Property {} has been set to {}. Secure websocket MQTT will be disabled", - BrokerConstants.WSS_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); - return; - } - int sslPort = Integer.parseInt(sslPortProp); - final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler(); - String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); - String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false"); - final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth); - initFactory(host, sslPort, "Secure websocket", new PipelineInitializer() { - - @Override - void init(ChannelPipeline pipeline) throws Exception { - pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth)); - pipeline.addLast("httpEncoder", new HttpResponseEncoder()); - pipeline.addLast("httpDecoder", new HttpRequestDecoder()); - pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); - pipeline.addLast("webSocketHandler", - new WebSocketServerProtocolHandler("/org/fusesource/mqtt", MQTT_SUBPROTOCOL_CSV_LIST)); - pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder()); - pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder()); - pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0)); - pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler); - pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector)); - pipeline.addLast("decoder", new MqttDecoder()); - pipeline.addLast("encoder", MqttEncoder.INSTANCE); - pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector)); - pipeline.addLast("messageLogger", new MQTTMessageLogger()); - pipeline.addLast("handler", handler); - } - }); - } - public void close() { LOG.info("Closing Netty acceptor..."); if (m_workerGroup == null || m_bossGroup == null) { diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 40ff450b..b574d08e 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -16,9 +16,6 @@ port 1883 ##客户端短链接端口 http_port 80 -##WEB客户端长链接端口 -websocket_port 8083 - #管理端口 http.admin.port 18080 @@ -41,9 +38,6 @@ http.admin.secret_key 123456 ##nonce = "76616", timestamp = "1558350862502", sign = "b98f9b0717f59febccf1440067a7f50d9b31bdde" http.admin.no_check_time false -##客户端协议栈密钥,需要与客户端协议栈文件libemqq.cc文件中的aes_key值保持一致,16进制byte用逗号分割。这个密钥不能修改!!! -client.proto.secret_key 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F - ##用来生产im token的私钥,只在服务器使用,客户端不用。正式使用时为了安全一定要修改这个值,切记切记 token.key testim