From ff430df8454a1662f78c4d0935bde66066eb224e Mon Sep 17 00:00:00 2001 From: goomadao <39483078+goomadao@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:35:41 +0800 Subject: [PATCH] Fix: connectivity of ssr auth_chain_(ab) protocol (#1180) --- component/ssr/protocol/auth_chain_a.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/component/ssr/protocol/auth_chain_a.go b/component/ssr/protocol/auth_chain_a.go index d14fc817..2028ba79 100644 --- a/component/ssr/protocol/auth_chain_a.go +++ b/component/ssr/protocol/auth_chain_a.go @@ -230,7 +230,7 @@ func (a *authChain) initUserKeyAndID() { if len(params) >= 2 { if userID, err := strconv.ParseUint(params[0], 10, 32); err == nil { binary.LittleEndian.PutUint32(a.uid[:], uint32(userID)) - a.userKey = []byte(params[1])[:len(a.userKey)] + a.userKey = []byte(params[1]) } } @@ -292,6 +292,10 @@ func (a *authChain) packAuthData(data []byte) (outData []byte) { defer a.mutex.Unlock() a.connectionID++ if a.connectionID > 0xFF000000 { + a.clientID = nil + } + if len(a.clientID) == 0 { + a.clientID = make([]byte, 4) rand.Read(a.clientID) b := make([]byte, 4) rand.Read(b) @@ -351,7 +355,7 @@ func (a *authChain) packAuthData(data []byte) (outData []byte) { // data chunkLength, randLength := a.packedDataLen(data) - if chunkLength <= 1500 { + if chunkLength+authHeadLength <= cap(outData) { outData = outData[:authHeadLength+chunkLength] } else { newOutData := make([]byte, authHeadLength+chunkLength)