Skip to content

Commit

Permalink
enhance: revalidation after ending cooperation
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyzyykk committed Feb 27, 2025
1 parent 8ae2b12 commit afecfcb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public void onOpen(Session sessionSocket, @PathParam("env") String env) throws I
Integer state = ResultCodeEnum.COOPERATE_KEY_INVALID.getState();
String msg = ResultCodeEnum.COOPERATE_KEY_INVALID.getDesc();
try {
String sshKey = AesUtil.aesDecrypt(StringUtil.changeStrBase64(cooperateKey), AdvanceController.COOPERATE_SECRET_KEY);
String[] keyInfo = AesUtil.aesDecrypt(StringUtil.changeStrBase64(cooperateKey), AdvanceController.COOPERATE_SECRET_KEY).split("\\^");
String cooperateId = keyInfo[0];
String sshKey = keyInfo[1];
WebSocketServer webSocketServer = WebSocketServer.webSocketServerMap.get(sshKey);
if(webSocketServer == null || webSocketServer.cooperateInfo == null)
if(webSocketServer == null || webSocketServer.cooperateInfo == null || !webSocketServer.cooperateInfo.getId().equals(cooperateId))
throw new RuntimeException();

List<Session> sessions = WebSocketServer.cooperateMap.computeIfAbsent(sshKey, k -> new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.UUID;

/**
* 高级功能接口类
Expand Down Expand Up @@ -64,12 +65,14 @@ public Result cooperateKey(String sshKey, Boolean readOnly, Integer maxHeadCount
if(webSocketServer.getCooperateInfo() != null)
return Result.error(errorMsg);

String cooperateId = UUID.randomUUID().toString();
CooperateInfo cooperateInfo = new CooperateInfo();
cooperateInfo.setId(cooperateId);
cooperateInfo.setReadOnly(readOnly);
cooperateInfo.setMaxHeadCount(maxHeadCount);
webSocketServer.setCooperateInfo(cooperateInfo);

String key = StringUtil.changeBase64Str(AesUtil.aesEncrypt(sshKey, COOPERATE_SECRET_KEY));
String key = StringUtil.changeBase64Str(AesUtil.aesEncrypt(cooperateId + "^" + sshKey, COOPERATE_SECRET_KEY));

return Result.success(successMsg, key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@AllArgsConstructor
public class CooperateInfo {

private String id;

private Boolean readOnly;

private Integer maxHeadCount;
Expand Down

0 comments on commit afecfcb

Please sign in to comment.