fix(issue#3 追报): 公网7890系第三方网关定位+CMPP版本协商(3.0按1B布局应答)+ISMG串掺shared_secret+系统配置弹窗防截断
This commit is contained in:
@@ -2,6 +2,14 @@
|
||||
|
||||
> 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。
|
||||
|
||||
## 2026-11-16(晚三)· Issue#3 追报:客户连公网 7890 非 本平台 + CMPP 版本协商 + 弹窗防截断
|
||||
|
||||
- **「登录仍报 -1」根因(网络层,非协议)**:探针对照实证——**公网 121.46.230.53:7890 是另一个 CMPP 网关**(回 Status=3 拒绝,本平台码值从不返回 3),s2demo 在彼处不存在;**本平台 CMPP 服务在内网 192.168.5.18:7890**(同请求 Status=0 鉴权通过)且 gateway 日志零客户连接记录(请求未达)。**结论:客户交付的连接地址指向公网机上的第三方/旧平台网关;本平台无公网 CMPP 入口。**解法=公网机 nginx 加 TCP stream 反代(7890 已被占用须用新端口如 17890→192.168.5.18:7890,需运维执行,配置片段已交付);过渡期客户可内网直连 192.168.5.18:7890。
|
||||
- **CMPP 版本协商加固(Issue#3 加固)**:服务端按客户端 Connect.Version(包体 offset22)应答——≥0x30 回 **3.0 布局**(1B Status/18B 包体/ISMG 串按 1B 参与/version 回显 0x30),否则 2.0(4B Status/21B);`ConnectResp.ClientVersion` 字段+Marshal/AuthenticatorISMG 双分支。**ISMG 鉴权串规范修正**:server 侧新增可选接口 `ISMGSecretSource`(access 实现=账号 ApiSecret),AuthenticatorISMG=MD5(Status+clientAuth+**shared_secret**)按规范掺入真密钥(此前 Secret 恒空串,严格校验 ISMG 的客户端必判失败——潜在 -1 源)。真机探针实证:2.0(21B/4B)与 3.0(18B/1B)Status=0 且**严格客户端视角重算 ISMG 串均匹配**。
|
||||
- **系统配置弹窗防截断**:Chrome 实测本机 1280×720/1024×600 几何均在视口内(用户场景为小视口/缩放/长选项);防御性全覆盖——dialog `align-center`(垂直居中,实测 top=精确居中)+`append-to-body`(防布局层裁剪)+max-width 92vw+body max-height 62vh 内滚(footer 恒可见);el-select 选项改**两行模板**(key 等宽主行+中文说明副行,原单行拼接 label ≈520px>面板 396px 必然省略号截断)+选中已知键在下方显示生效说明(keyHint)。
|
||||
- **测试 +2**:TestServer_ConnectVersion30(裸 TCP 第三方视角:0x30→18B/1B/version 回显,0x20→21B/4B 回归)、TestConnectRespVersion30Layout(3.0 布局往返+ISMG 1B 口径);fakeHandler 实现 ISMGSecret。
|
||||
- **门禁**:vet 0/-race cmpp+access+sysconfig 三包绿(全量 42 包前轮已绿)/lint 0;eslint 0/vue-tsc 0/vitest 165;gateway 串行部署(md5 ✓)。
|
||||
|
||||
## 2026-11-16(晚二)· Issue#3 方案B:系统配置页 + 系统级默认接入码回退链
|
||||
|
||||
- **范围(用户拍板 A+B)**:「系统配置」占位页做实(system_config KV 管理面)+ SrcID 校验两级回退链(账号 ext_code 优先 → 系统默认 cmpp.default_ext_code 兜底 → 均空放行)。
|
||||
|
||||
@@ -95,17 +95,25 @@ func VerifyAuth(sourceAddr, secret string, ts uint32, authenticator []byte) bool
|
||||
// ConnectResp 包体(CMPP 2.0 规范:Status 4B 大端 + authenticator_ISMG 16B + version 1B = 21B)。
|
||||
type ConnectResp struct {
|
||||
Status byte
|
||||
Secret string // 计算服务端鉴权串
|
||||
Secret string // 计算服务端鉴权串(shared_secret;server 侧应填账号密钥)
|
||||
AuthenticatorClient []byte // 客户端鉴权串(参与计算)
|
||||
// ClientVersion 客户端 Connect.Version 声明(Issue#3 加固):≥0x30 按 3.0
|
||||
// 布局应答(1B Status,18B 包体,ISMG 串 Status 以 1B 参与)——防严格 3.0
|
||||
// 客户端按 1B 校验 ISMG 串错位报 -1;0/0x20 按 2.0(4B Status,21B 包体)。
|
||||
ClientVersion byte
|
||||
}
|
||||
|
||||
// AuthenticatorISMG 计算服务端鉴权串:MD5(status + authenticatorSource + shared)。
|
||||
// Issue#3 修正:CMPP 2.0 规范中 Status 以 4 字节大端参与拼接(此前误用 1 字节)。
|
||||
// Issue#3 修正:CMPP 2.0 规范中 Status 以 4 字节大端参与拼接(3.0 为 1 字节)。
|
||||
func (r *ConnectResp) AuthenticatorISMG() []byte {
|
||||
buf := make([]byte, 0, 4+len(r.AuthenticatorClient)+len(r.Secret))
|
||||
var st [4]byte
|
||||
binary.BigEndian.PutUint32(st[:], uint32(r.Status))
|
||||
buf = append(buf, st[:]...)
|
||||
if r.ClientVersion >= 0x30 { // 3.0:Status 1B 参与
|
||||
buf = append(buf, r.Status)
|
||||
} else { // 2.0:Status 4B 大端参与
|
||||
var st [4]byte
|
||||
binary.BigEndian.PutUint32(st[:], uint32(r.Status))
|
||||
buf = append(buf, st[:]...)
|
||||
}
|
||||
buf = append(buf, r.AuthenticatorClient...)
|
||||
buf = append(buf, r.Secret...)
|
||||
sum := md5.Sum(buf)
|
||||
@@ -118,7 +126,15 @@ func (r *ConnectResp) AuthenticatorISMG() []byte {
|
||||
// 两字段上互为镜像,极易混淆)。此前按 1B 编码(18B 包体),标准 2.0 客户端按
|
||||
// 4B 大端解析 Status 时读到 [status,MD5[0..2]] 恒非 0,客户连接被误判失败
|
||||
// (客户端工具报 -1);自家客户端同按 1B 解析,自测格式对称掩盖了缺陷。
|
||||
// Issue#3 加固:按客户端 Connect.Version 协商——0x30 回 3.0 布局(18B)。
|
||||
func (r *ConnectResp) Marshal() []byte {
|
||||
if r.ClientVersion >= 0x30 {
|
||||
b := make([]byte, 1+16+1)
|
||||
b[0] = r.Status
|
||||
copy(b[1:17], r.AuthenticatorISMG())
|
||||
b[17] = 0x30
|
||||
return b
|
||||
}
|
||||
b := make([]byte, 4+16+1)
|
||||
binary.BigEndian.PutUint32(b[0:4], uint32(r.Status))
|
||||
copy(b[4:20], r.AuthenticatorISMG())
|
||||
|
||||
@@ -3,6 +3,7 @@ package cmpp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -126,6 +127,25 @@ func TestParseConnectRespAdaptive(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConnectRespVersion30Layout Issue#3 加固:3.0 布局(1B Status)往返 +
|
||||
// ISMG 串按 1B status 计算(严格 3.0 客户端校验口径)。
|
||||
func TestConnectRespVersion30Layout(t *testing.T) {
|
||||
clientAuth := bytes.Repeat([]byte{0x33}, 16)
|
||||
r := &ConnectResp{Status: 0, Secret: "pw", AuthenticatorClient: clientAuth, ClientVersion: 0x30}
|
||||
body := r.Marshal()
|
||||
if len(body) != 18 {
|
||||
t.Fatalf("3.0 包体应 18B: %d", len(body))
|
||||
}
|
||||
st, ismg, err := ParseConnectResp(body)
|
||||
if err != nil || st != 0 || len(ismg) != 16 {
|
||||
t.Fatalf("解析: st=%d err=%v", st, err)
|
||||
}
|
||||
want := md5.Sum(append(append([]byte{0}, clientAuth...), []byte("pw")...))
|
||||
if !bytes.Equal(want[:], ismg) {
|
||||
t.Fatal("3.0 ISMG 串应按 1B status 计算")
|
||||
}
|
||||
}
|
||||
|
||||
// TestPacketReadWrite 包读写往返(WritePacket 自动补 TotalLength)。
|
||||
func TestPacketReadWrite(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
@@ -68,6 +68,13 @@ type ConnLimiter interface {
|
||||
ConnLimit(sourceAddr string) int
|
||||
}
|
||||
|
||||
// ISMGSecretSource 可选接口(Issue#3 加固):提供账号共享密钥——ConnectResp 的
|
||||
// AuthenticatorISMG=MD5(Status+AuthenticatorSource+shared_secret) 按规范掺入;
|
||||
// 不实现=空串(旧口径,严格校验 ISMG 的客户端会判失败)。
|
||||
type ISMGSecretSource interface {
|
||||
ISMGSecret(sourceAddr string) string
|
||||
}
|
||||
|
||||
// SubmitRateLimiter 可选接口(Day 62):账号级单链提交限速 条/s(≤0=不限)。
|
||||
type SubmitRateLimiter interface {
|
||||
SubmitRateLimit(sourceAddr string) int
|
||||
@@ -284,6 +291,17 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
||||
if perr == nil {
|
||||
status = s.h.Connect(sourceAddr, ts, authenticator, ip)
|
||||
}
|
||||
// Issue#3 加固:按客户端 Connect.Version 协商应答布局(≥0x30 回 3.0 的
|
||||
// 1B Status/18B;否则 2.0 的 4B Status/21B)——版本字节在包体 offset 22。
|
||||
ver := byte(0x20)
|
||||
if len(body) >= 23 && body[22] >= 0x30 {
|
||||
ver = body[22]
|
||||
}
|
||||
// Issue#3 加固:ISMG 鉴权串按规范掺 shared_secret(可选接口;不实现=空串)。
|
||||
smsSecret := ""
|
||||
if ss, ok := s.h.(ISMGSecretSource); ok {
|
||||
smsSecret = ss.ISMGSecret(sourceAddr)
|
||||
}
|
||||
// Day 62:鉴权通过后先占会话名额(账号级连接数上限,可选接口;持锁原子
|
||||
// 检查+登记防并发超卖),超限回保留码 0x8 后断链。
|
||||
if status == ConnectOK {
|
||||
@@ -297,7 +315,8 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
||||
status = ConnectTooMany
|
||||
}
|
||||
}
|
||||
resp := &ConnectResp{Status: status, Secret: "", AuthenticatorClient: authenticator}
|
||||
resp := &ConnectResp{Status: status, Secret: smsSecret,
|
||||
AuthenticatorClient: authenticator, ClientVersion: ver}
|
||||
if werr := WritePacket(conn, &Header{CommandID: CmdConnectResp, SequenceID: h.SequenceID}, resp.Marshal()); werr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ package cmpp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -36,6 +38,9 @@ func (h *fakeHandler) Connect(sourceAddr string, ts uint32, authenticator []byte
|
||||
return ConnectOK
|
||||
}
|
||||
|
||||
// ISMGSecret Issue#3 加固:ConnectResp 鉴权串掺入 shared_secret(fake=密钥本身)。
|
||||
func (h *fakeHandler) ISMGSecret(sourceAddr string) string { return h.secret }
|
||||
|
||||
func (h *fakeHandler) Submit(sourceAddr, srcID string, dest []string,
|
||||
content string, udh *UDHInfo, registeredDelivery uint8, msgFmt uint8) (uint64, byte) {
|
||||
if h.rejectAll {
|
||||
@@ -113,6 +118,50 @@ func TestServer_ConnectOKAndSubmit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestServer_ConnectVersion30 Issue#3 加固:按客户端 Connect.Version 协商应答——
|
||||
// 0x30 回 3.0 布局(18B/1B Status/version 回显 0x30);0x20 回 2.0(21B/4B)。
|
||||
// 裸 TCP 第三方视角(自家 client 固定发 0x20 测不到该分支)。
|
||||
func TestServer_ConnectVersion30(t *testing.T) {
|
||||
h := &fakeHandler{secret: "abc123", submits: make(chan *submitRecord, 1)}
|
||||
srv := startTestServer(t, h)
|
||||
|
||||
send := func(ver byte) []byte {
|
||||
t.Helper()
|
||||
conn, err := net.DialTimeout("tcp", srv.Addr(), 2*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = conn.Close() }()
|
||||
_ = conn.SetDeadline(time.Now().Add(3 * time.Second))
|
||||
req := &Connect{SourceAddr: "user1", Secret: "abc123", Version: ver}
|
||||
if err := WritePacket(conn, &Header{CommandID: CmdConnect, SequenceID: 7},
|
||||
req.Marshal(authTimestamp(time.Now()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, body, err := ReadPacket(conn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
b30 := send(0x30)
|
||||
if len(b30) != 18 {
|
||||
t.Fatalf("3.0 客户端应答应 18B(1B Status): %d", len(b30))
|
||||
}
|
||||
if b30[0] != 0 {
|
||||
t.Fatalf("3.0 Status(1B)=%d 期望 0", b30[0])
|
||||
}
|
||||
if b30[17] != 0x30 {
|
||||
t.Fatalf("3.0 应答回显 version=0x30, got 0x%02x", b30[17])
|
||||
}
|
||||
|
||||
b20 := send(0x20)
|
||||
if len(b20) != 21 || binary.BigEndian.Uint32(b20[0:4]) != 0 {
|
||||
t.Fatalf("2.0 应答应 21B/Status=0: len=%d", len(b20))
|
||||
}
|
||||
}
|
||||
|
||||
// TestServer_PushDeliver Day 61(P0.5):Connect 注册会话→PushDeliver 下发状态报告
|
||||
// →客户端 OnDeliver 收到(含 MsgID/Stat 口径)→服务端吸收 Deliver_Resp。
|
||||
func TestServer_PushDeliver(t *testing.T) {
|
||||
|
||||
@@ -275,6 +275,17 @@ func (s *Service) Connect(sourceAddr string, ts uint32, authenticator []byte, cl
|
||||
// Submit 实现 cmpp.ServerHandler:账号/通道号前缀校验→SendMass 受理。
|
||||
// 长短信片(udh 非 nil 且单目的码)改走聚合器:按组拼接合并为一条逻辑
|
||||
// 短信单次受理(批次 2278141 修复,决策①A/②A/③——详见 longsms.go);其余
|
||||
// ISMGSecret 实现 cmpp.ISMGSecretSource:ConnectResp 鉴权串的 shared_secret
|
||||
// (账号 ApiSecret;查无账号=空串——该场景应答本就 status≠0,客户端按状态码判)。
|
||||
// 与 Connect 同走 loadAccountDB 直查(握手期非热路径,口径一致)。
|
||||
func (s *Service) ISMGSecret(sourceAddr string) string {
|
||||
_, cfg := s.loadAccountDB(context.Background(), sourceAddr)
|
||||
if cfg == nil {
|
||||
return ""
|
||||
}
|
||||
return cfg.ApiSecret
|
||||
}
|
||||
|
||||
// (普通提交/多目的码片)走原直发路径不变。
|
||||
func (s *Service) Submit(sourceAddr, srcID string, dest []string,
|
||||
content string, udh *cmpp.UDHInfo, registeredDelivery uint8, msgFmt uint8) (uint64, byte) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## 当前状态快照(2026-11-16,**Issue#3 三连修复+方案B 系统配置落地,S4 泳道收官,一期 18/27 计划日**)
|
||||
|
||||
- **Issue#3 方案B(2026-11-16 晚二)**:系统配置页(views/system 占位转正;system_config KV:GET/PUT /system/config)+ **SrcID 两级回退链**(账号 ext_code 优先→系统默认 cmpp.default_ext_code→均空放行;access.effectiveExtCode 三路径统一:直发/长短信/SMPP)。sysconfig 域新包(Get 30s 缓存/Set UPSERT+**写即刻失效缓存**);真机四态矩阵实证系统级接管+账号级优先;**生产值 cmpp.default_ext_code=10690331 已设**(未配置账号开箱即校验);uplink.blacklist.keywords 键现可页面管理(uplink 域 60s 自刷新照旧)。门禁 -race 42 包/vitest 165/build 全绿;gateway 已部署。
|
||||
- **Issue#3 追报闭环(2026-11-16 晚三)**:①「客户登录仍 -1」根因=**网络层**——探针对照实证公网 121.46.230.53:7890 是**另一个 CMPP 网关**(Status=3 拒绝),本平台 CMPP 在内网 192.168.5.18:7890(Status=0 正常)且日志零客户连接;**解法=公网机 nginx TCP stream 反代(7890 被占须用新端口 17890,运维项,配置片段已交付)/过渡期内网直连**;②CMPP **版本协商**加固(Connect.Version≥0x30 回 3.0 布局 18B/1B,否则 2.0 21B/4B)+**ISMG 串规范修正**(server 恒空 secret→ISMGSecretSource 接口掺账号 ApiSecret;严格客户端重算 ISMG 双版本均匹配);③系统配置弹窗防截断(align-center+append-to-body+92vw+62vh 内滚+select 两行选项+keyHint)。
|
||||
|
||||
- **Issue#3 三连修复(2026-11-16 晚)**:①CMPP 连接报 -1 根因=`ConnectResp` 误按 **3.0 的 1B Status** 编码(标准 2.0 客户端按 4B 大端解析恒非 0)→ 修复=Marshal 4B(21B 包体)+AuthenticatorISMG 4B 参与 MD5+`ParseConnectResp` 自适应双布局(≥20B/2.0,17~19B/3.0);标准 2.0 探针真机实证 18B/垃圾值→21B/Status=0,**教训:2.0 与 3.0 在 CONNECT_RESP.Status/SUBMIT_RESP.Result 上互为镜像(2.0=4B/1B),自家 client+server 同源对称自测掩盖协议错位——同 Day39 坑**;②充值无响应=前端发 `{count}` 后端要 `{amount}`+submit 无 catch 静默吞错 → API/mock/组件三处修复;③SrcID 核验**用户裁定方案 C(前缀+动态扩展,行业惯例)**——s2demo 已配 ext_code=10690331(通道码即前缀),客户 SrcID 须以 10690331 开头+可追加扩展(≤21 位);真机四场景实证(纯码→10 过/码+扩展→10 过/不匹配→9/空→9);**运营口径:ext_code 变更后 30s 缓存生效(Day63 accCache)**。顺手修 TestClient_LoginOK 时序竞争(轮询吸收);门禁 -race 41 包/vitest 165/build 全绿;gateway 已串行部署(md5 比对 ✓)。
|
||||
- **仓库**:main 已推 Gitea;每日 bundle+push 双轨。
|
||||
|
||||
@@ -36,13 +36,20 @@
|
||||
</template>
|
||||
</el-table>
|
||||
|
||||
<el-dialog v-model="dlg" :title="editing ? '编辑参数' : '新增参数'" width="520px">
|
||||
<el-dialog v-model="dlg" :title="editing ? '编辑参数' : '新增参数'" width="520px"
|
||||
align-center append-to-body class="sc-dlg">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="配置键">
|
||||
<el-select v-model="form.cfg_key" filterable allow-create default-first-option
|
||||
:disabled="editing" placeholder="选择已知键或输入新键" style="width: 100%" data-testid="cfg-key">
|
||||
<el-option v-for="k in KNOWN_CFG_KEYS" :key="k.key" :value="k.key" :label="`${k.key}(${k.label})`" />
|
||||
<el-option v-for="k in KNOWN_CFG_KEYS" :key="k.key" :value="k.key" :label="k.key">
|
||||
<div class="sc-opt">
|
||||
<span class="sc-opt-key">{{ k.key }}</span>
|
||||
<span class="sc-opt-label">{{ k.label }}</span>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<div v-if="keyHint" class="sc-key-hint">{{ keyHint }}</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="配置值">
|
||||
<el-input v-model="form.cfg_value" type="textarea" :rows="2" maxlength="1024" show-word-limit
|
||||
@@ -63,7 +70,7 @@
|
||||
<script setup lang="ts">
|
||||
// Issue#3 方案B:系统配置页(keep-alive 缓存锚点——组件名必须=路由 name)。
|
||||
defineOptions({ name: 'system' })
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { KNOWN_CFG_KEYS, systemApi, type SystemConfigRow } from '@/api/system'
|
||||
|
||||
@@ -74,6 +81,12 @@ const saving = ref(false)
|
||||
const editing = ref(false)
|
||||
const form = ref({ cfg_key: '', cfg_value: '', remark: '' })
|
||||
|
||||
// 选中已知键时在下方给出该键的生效说明(替代下拉里拼接长 label 被截断)。
|
||||
const keyHint = computed(() => {
|
||||
const hit = KNOWN_CFG_KEYS.find((k) => k.key === form.value.cfg_key)
|
||||
return hit?.hint ?? ''
|
||||
})
|
||||
|
||||
async function reload() {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -127,4 +140,15 @@ async function save() {
|
||||
.sc-hint-key { font-family: monospace; }
|
||||
.sc-key { font-family: monospace; }
|
||||
.sc-val { font-family: monospace; }
|
||||
.sc-key-hint { font-size: var(--gosms-fs-xs, 12px); color: var(--gosms-text-dim, #909399); line-height: 1.5; margin-top: 4px; word-break: break-all; }
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* 弹窗防截断(append-to-body 后为全局层):窄视口不右溢、超高内容内滚、footer 恒可见。 */
|
||||
.sc-dlg { max-width: 92vw; }
|
||||
.sc-dlg .el-dialog__body { max-height: 62vh; overflow-y: auto; }
|
||||
/* 下拉选项两行:key 等宽主行 + 中文说明副行(单行拼接长 label 会省略号截断)。 */
|
||||
.sc-opt { display: flex; flex-direction: column; gap: 2px; padding: 2px 0; }
|
||||
.sc-opt-key { font-family: monospace; font-size: 13px; }
|
||||
.sc-opt-label { font-size: 12px; color: #909399; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user