fix: 对齐闲鱼消息连接与登录续期流程
对齐官方 WebSocket 竞速、连接级凭证、注册解码、控制状态与心跳时序。 持久化完整 Cookie Jar,修正请求作用域、删除、分区、加密、并发写回与错误路径。 统一启动续期、长登录开关和业务 MTOP 的原子更新,并补充回归与竞态测试。
This commit is contained in:
1 parent
d77c317452
commit
de9c12196f
59 files changed
+6170
-1247
No files matched your search
@@ -3,11 +3,11 @@ package engine
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"sort"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"xianyu-go/internal/xianyu/protocol"
|
||||
"xianyu-go/internal/xianyu/cookierefresh"
|
||||
)
|
||||
|
||||
const tokenExpirySafetyMargin = time.Minute
|
||||
@@ -25,19 +25,39 @@ func effectiveTokenExpireAt(serverExpireAt int64, now time.Time) int64 {
|
||||
}
|
||||
|
||||
func credentialCookieFingerprint(cookieStr string) string {
|
||||
cookies := protocol.TransCookies(cookieStr)
|
||||
keys := make([]string, 0, len(cookies))
|
||||
for key := range cookies {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
var canonical strings.Builder
|
||||
for _, key := range keys {
|
||||
for _, part := range strings.Split(cookieStr, ";") {
|
||||
key, value, ok := strings.Cut(strings.TrimSpace(part), "=")
|
||||
key = strings.TrimSpace(key)
|
||||
if !ok || key == "" {
|
||||
continue
|
||||
}
|
||||
canonical.WriteString(key)
|
||||
canonical.WriteByte(0)
|
||||
canonical.WriteString(cookies[key])
|
||||
canonical.WriteString(strings.TrimSpace(value))
|
||||
canonical.WriteByte(0)
|
||||
}
|
||||
sum := sha256.Sum256([]byte(canonical.String()))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
// credentialStateFingerprint binds a connection token to both the exact flat
|
||||
// Cookie header and the authoritative browser Jar that produced it. The flat
|
||||
// fingerprint deliberately retains duplicate names and their order because
|
||||
// lib-mtop reads the first path-ordered _m_h5_tk entry. A present empty Jar is
|
||||
// distinct from legacy metadata that has no complete snapshot.
|
||||
func credentialStateFingerprint(cookieStr, metadataJSON string) string {
|
||||
var canonical strings.Builder
|
||||
canonical.WriteString("flat\x00")
|
||||
canonical.WriteString(credentialCookieFingerprint(cookieStr))
|
||||
canonical.WriteString("\x00snapshot\x00")
|
||||
if snapshot, complete := cookierefresh.SnapshotFromMetadataOK(metadataJSON); complete {
|
||||
canonical.WriteByte('1')
|
||||
raw, _ := json.Marshal(cookierefresh.NormalizeSnapshot(snapshot))
|
||||
canonical.Write(raw)
|
||||
} else {
|
||||
canonical.WriteByte('0')
|
||||
}
|
||||
sum := sha256.Sum256([]byte(canonical.String()))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
Reference in new issue
Block a user