From 04f54713857814f8f549b6375a717a322fa2d9b9 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Tue, 10 Sep 2024 10:53:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7id=E9=BB=98=E8=AE=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 4 ++++ .../main/java/io/moquette/BrokerConstants.java | 2 ++ .../moquette/persistence/MemoryMessagesStore.java | 15 ++++++++++++--- distribution/src/main/resources/wildfirechat.conf | 4 ++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index f6668a2a..6526d508 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -68,6 +68,10 @@ token.key testim ##是否使用AES256加密。默认客户端和服务器都是AES128加密,如果需要开启AES256,需要客户端和IM服务同时开通。 #encrypt.use_aes256 true +##当创建一个对象时(用户,群组,频道,机器人等),如果没有传入ID,野火会为这个对象生成一个ID。如果id.use_uuid为true,会使用uuid作为对象ID,否则会使用野火短ID,默认为false。 +## 短ID有个很大的风险是容易被人穷举进行攻击。建议用UUID。 +id.use_uuid true + ##首次登录,是否接收之前的历史消息。 ##0 不接收历史消息,只接收${message.compensate_time_limit}毫秒以内的消息,由于服务器没有保存已经收取记录,所以如果有超过${message.compensate_time_limit}毫秒之前未收取的消息也不会收取下拉; ##1接收,会接收 message.max_queue 配置的条数的历史消息 diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index fb8b0cd7..fcd031e4 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -115,6 +115,8 @@ public final class BrokerConstants { public static final String CONNECT_CLIENT_SIGNATURE_LIST = "connect.client_signature_list"; public static final String CONNECT_REJECT_EMPTY_SIGNATURE = "connect.reject_empty_signature"; + public static final String ID_USE_UUID = "id.use_uuid"; + public static final String EMBED_DB_PROPERTY_NAME = "embed.db"; public static final String DB_AUTO_CLEAN_HISTORY_MESSAGES = "db.auto_clean_history_messages"; public static final String H2DB_PATH = "h2db.path"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 1dd402ad..18b63d3c 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -166,6 +166,8 @@ public class MemoryMessagesStore implements IMessagesStore { private Set mAllowStrangerChatSet = new HashSet<>(); private boolean mDisableStrangerAddGroup = false; + private boolean mIDUseUUID = true; + private Set mClientSignatureSet = new HashSet<>(); private boolean mRejectEmptySignature = true; @@ -614,6 +616,11 @@ public class MemoryMessagesStore implements IMessagesStore { } catch (Exception e) { } + + try { + mIDUseUUID = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ID_USE_UUID, "false")); + } catch (Exception e) { + } } private void printMissConfigLog(String config, String defaultValue) { @@ -4791,9 +4798,11 @@ public class MemoryMessagesStore implements IMessagesStore { @Override public String getShortUUID(){ - int id = databaseStore.getGeneratedId(); - if (id > 0) { - return IDUtils.toUid(id); + if(!mIDUseUUID) { + int id = databaseStore.getGeneratedId(); + if (id > 0) { + return IDUtils.toUid(id); + } } return UUIDGenerator.getUUID(); } diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 83b3b891..e2f7d935 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -66,6 +66,10 @@ token.key testim ##是否使用AES256加密。默认客户端和服务器都是AES128加密,如果需要开启AES256,需要客户端和IM服务同时开通。 #encrypt.use_aes256 true +##当创建一个对象时(用户,群组,频道,机器人等),如果没有传入ID,野火会为这个对象生成一个ID。如果id.use_uuid为true,会使用uuid作为对象ID,否则会使用野火短ID,默认为false。 +## 短ID有个很大的风险是容易被人穷举进行攻击。建议用UUID。 +id.use_uuid true + ##首次登录,是否接收之前的历史消息。 ##0 不接收历史消息,只接收${message.compensate_time_limit}毫秒以内的消息,由于服务器没有保存已经收取记录,所以如果有超过${message.compensate_time_limit}毫秒之前未收取的消息也不会收取下拉; ##1接收,会接收 message.max_queue 配置的条数的历史消息