fix:修改收到信息先验证合法性再解码内容

This commit is contained in:
SL 2025-01-08 19:09:15 +08:00
commit 25caa7a067
3 changed files with 14 additions and 2 deletions

View File

@ -168,11 +168,13 @@ public class WKConnection {
connectionClient = new ConnectionClient(iNonBlockingConnection -> {
connCount = 0;
if (iNonBlockingConnection == null || connection == null || !connection.getId().equals(iNonBlockingConnection.getId())) {
WKLoggerUtils.getInstance().e(TAG,"重复连接");
forcedReconnection();
return;
}
Object att = iNonBlockingConnection.getAttachment();
if (att == null || !att.equals(socketSingleID)) {
WKLoggerUtils.getInstance().e(TAG,"不属于当前连接");
forcedReconnection();
return;
}

View File

@ -220,6 +220,11 @@ class WKProto {
receivedMsg.topicID = wkRead.readString();
}
String content = wkRead.readPayload();
<<<<<<< HEAD
=======
WKLoggerUtils.getInstance().e(TAG, "消息payload:" + content);
receivedMsg.payload = CryptoUtils.getInstance().aesDecrypt(CryptoUtils.getInstance().base64Decode(content));
>>>>>>> 9978523a9a818731b66c2409ff4c0cba70fab46f
String msgKey = receivedMsg.messageID
+ receivedMsg.messageSeq
+ receivedMsg.clientMsgNo

View File

@ -102,11 +102,15 @@ public class CryptoUtils {
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException |
InvalidAlgorithmParameterException | IllegalBlockSizeException |
BadPaddingException e) {
<<<<<<< HEAD
WKLoggerUtils.getInstance().e(TAG,"aesEncrypt encrypt error");
return null;
=======
WKLoggerUtils.getInstance().e(TAG, "aesEncrypt encrypt error");
>>>>>>> 9978523a9a818731b66c2409ff4c0cba70fab46f
}
if (encrypted == null) {
WKLoggerUtils.getInstance().e(TAG,"aesEncrypt The encrypted data is empty");
WKLoggerUtils.getInstance().e(TAG, "aesEncrypt The encrypted data is empty");
encrypted = sSrc.getBytes();
}
return encrypted;
@ -137,8 +141,9 @@ public class CryptoUtils {
return content;
}
public byte[] base64Decode(String data) {
return Base64.decode(data, Base64.NO_WRAP);
return Base64.decode(data, Base64.NO_WRAP);
}
/**