fix
This commit is contained in:
parent
edc50a15ec
commit
cefe601046
|
@ -152,7 +152,7 @@ func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.Resp
|
||||||
isAuth, userInfo = l.checkAuth(r)
|
isAuth, userInfo = l.checkAuth(r)
|
||||||
if !isAuth {
|
if !isAuth {
|
||||||
//未授权响应消息
|
//未授权响应消息
|
||||||
l.unAuthResponse(conn, isFirefoxBrowser)
|
l.unAuthResponse(conn, isFirefoxBrowser, "unAuth")
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -184,34 +184,37 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||||
return wsConnectItem{}, err
|
return wsConnectItem{}, err
|
||||||
}
|
}
|
||||||
if oldWid != "" {
|
if oldWid != "" {
|
||||||
//解析传入的wid是不是属于自己的用户的
|
for i := 0; i < 1; i++ {
|
||||||
decryptionWid, err := encryption_decryption.CBCDecrypt(oldWid)
|
oldWid, err = encryption_decryption.NumberStrToBase64Str(oldWid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err, ":", oldWid)
|
logx.Error("wid转base64失败:", err)
|
||||||
return wsConnectItem{}, errors.New("解码wid失败")
|
break
|
||||||
}
|
}
|
||||||
lendecryptionWid := len(decryptionWid)
|
//解析传入的wid是不是属于自己的用户的
|
||||||
//合成client后缀,不是同个后缀的不能复用
|
decryptionWid, err := encryption_decryption.CBCDecrypt(oldWid)
|
||||||
userPart := getUserJoinPart(userInfo.UserId, userInfo.GuestId, userAgent)
|
if err != nil {
|
||||||
lenUserPart := len(userPart)
|
logx.Error("解密wid失败:", err)
|
||||||
canUseOldWid := true
|
break
|
||||||
//长度太短
|
}
|
||||||
if lendecryptionWid <= lenUserPart {
|
lendecryptionWid := len(decryptionWid)
|
||||||
logx.Info("复用的连接标识太短,不符合重用条件")
|
//合成client后缀,不是同个后缀的不能复用
|
||||||
canUseOldWid = false
|
userPart := getUserJoinPart(userInfo.UserId, userInfo.GuestId, userAgent)
|
||||||
}
|
lenUserPart := len(userPart)
|
||||||
//尾部不同不能复用
|
//长度太短
|
||||||
if decryptionWid[lendecryptionWid-lenUserPart:] != userPart {
|
if lendecryptionWid <= lenUserPart {
|
||||||
logx.Info("尾部用户信息不同,不符合重用条件")
|
logx.Error("复用的连接标识太短,不符合重用条件")
|
||||||
canUseOldWid = false
|
break
|
||||||
}
|
}
|
||||||
//存在是不能给他申请重新绑定
|
//尾部不同不能复用
|
||||||
if _, ok := mapConnPool.Load(oldWid); ok {
|
if decryptionWid[lendecryptionWid-lenUserPart:] != userPart {
|
||||||
logx.Info("复用的连接标识已被其他客户端使用,不符合重用条件")
|
logx.Error("尾部用户信息不同,不符合重用条件")
|
||||||
canUseOldWid = false
|
break
|
||||||
}
|
}
|
||||||
//检测通过可以用旧的
|
//存在是不能给他申请重新绑定
|
||||||
if canUseOldWid {
|
if _, ok := mapConnPool.Load(oldWid); ok {
|
||||||
|
logx.Error("复用的连接标识已被其他客户端使用,不符合重用条件")
|
||||||
|
break
|
||||||
|
}
|
||||||
logx.Info("====复用旧的ws连接成功====")
|
logx.Info("====复用旧的ws连接成功====")
|
||||||
uniqueId = oldWid
|
uniqueId = oldWid
|
||||||
}
|
}
|
||||||
|
@ -275,7 +278,7 @@ func (l *DataTransferLogic) getUniqueId(userInfo *auth.UserInfo, userAgent strin
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return uniqueId, nil
|
return encryption_decryption.Base64StrToNumberStr(uniqueId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 鉴权
|
// 鉴权
|
||||||
|
@ -293,10 +296,10 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
||||||
}
|
}
|
||||||
|
|
||||||
// 鉴权失败通知
|
// 鉴权失败通知
|
||||||
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool) {
|
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool, errMessage string) {
|
||||||
rsp := websocket_data.DataTransferData{
|
rsp := websocket_data.DataTransferData{
|
||||||
T: constants.WEBSOCKET_UNAUTH,
|
T: constants.WEBSOCKET_UNAUTH,
|
||||||
D: websocket_data.ConnectUnAuth{Message: "unAuth"},
|
D: websocket_data.ConnectUnAuth{Message: errMessage},
|
||||||
}
|
}
|
||||||
b, _ := json.Marshal(rsp)
|
b, _ := json.Marshal(rsp)
|
||||||
if isFirefoxBrowser {
|
if isFirefoxBrowser {
|
||||||
|
|
|
@ -24,6 +24,7 @@ func main() {
|
||||||
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
fsconfig.StartNacosConfig(*configFile, &c, nil)
|
||||||
|
c.Port = 9960
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||||
}))
|
}))
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
|
@ -7,11 +7,33 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 必须16字节
|
// 必须16字节
|
||||||
var cbckey = "fusen20230405145"
|
var cbckey = "fusen20230405145"
|
||||||
|
|
||||||
|
func Base64StrToNumberStr(base64Str string) string {
|
||||||
|
s := strings.Builder{}
|
||||||
|
for _, v := range base64Str {
|
||||||
|
s.WriteString(fmt.Sprintf("%d.", v))
|
||||||
|
}
|
||||||
|
return strings.TrimRight(s.String(), ".")
|
||||||
|
}
|
||||||
|
func NumberStrToBase64Str(numberStr string) (string, error) {
|
||||||
|
s := strings.Split(numberStr, ".")
|
||||||
|
b := make([]int32, 0, len(s))
|
||||||
|
for _, v := range s {
|
||||||
|
c, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
b = append(b, int32(c))
|
||||||
|
}
|
||||||
|
return string(b), nil
|
||||||
|
}
|
||||||
|
|
||||||
// 加密(key必须16字节),前端加解密需要先把base64转字符串再取前16字节作为iv
|
// 加密(key必须16字节),前端加解密需要先把base64转字符串再取前16字节作为iv
|
||||||
func CBCEncrypt(data string) (string, error) {
|
func CBCEncrypt(data string) (string, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user