Skip to content

Phase 5:Dialog + RegistrationClient + OptionsProbe + Digest 鉴权 - #10

Draft
lixuanqun wants to merge 1 commit into
cursor/transactions-3c36from
cursor/dialog-ua-3c36
Draft

Phase 5:Dialog + RegistrationClient + OptionsProbe + Digest 鉴权#10
lixuanqun wants to merge 1 commit into
cursor/transactions-3c36from
cursor/dialog-ua-3c36

Conversation

@lixuanqun

Copy link
Copy Markdown
Owner

概述

把"事务上面那一层"补完:Dialog(RFC 3261 §12)、Digest 鉴权(RFC 7616 + 兼容 MD5 legacy)、REGISTER 客户端(RFC 3261 §10)、OPTIONS probe(§11)。

🔗 stacked on PR #9

sip-dialog

  • DialogId:(callId, localTag, remoteTag),三元组身份
  • DialogState:EARLY / CONFIRMED / TERMINATED
  • Dialog
    • fromUacResponse(request, response) — UAC 视角;route set = reverse(Record-Route)
    • fromUasRequest(request, response) — UAS 视角;route set = Record-Route 原序
    • nextLocalCSeq() 单调递增供 in-dialog request 使用
    • onResponse 把 EARLY → CONFIRMED
    • refreshRemoteTarget 实现 §12.2.1.2 target refresh
  • 5 个单测覆盖:UAC/UAS 构造、route set 顺序、EARLY→CONFIRMED、CSeq 单调

sip-ua

鉴权(com.sip.ua.auth

  • DigestChallenge.parse(headerValue) — 解析 WWW-Authenticate / Proxy-Authenticate
    • 支持 RFC 7616 SHA-256 / SHA-512-256 与 RFC 2617 MD5
    • quoted-string + escape 自实现解析
  • DigestCredentials — username + password
  • DigestResponse.authorizationHeader(method, uri, nc, challenge, credentials)
    • HA1 / HA2 / response 按 RFC 7616 §3.4 计算
    • qop=auth 时附 cnonce/nc;无 qop 走 legacy
    • 算法映射 MD5/SHA-256/SHA-512-256

REGISTER + OPTIONS

  • Branch.newBranch() — RFC §8.1.1.7 magic cookie + 96-bit 随机熵
  • RegistrationClient
    • 构造 REGISTER(Via 带 rport、Contact、Expires、User-Agent)
    • NonInviteClientTransaction(无锁、非阻塞)
    • 收到 401/407 自动用 Digest 凭据重发(一次性,不二次重试)
    • 自动选 WWW-Authenticate vs Proxy-Authenticate 对应的 Authorization header
  • OptionsProbe — 同样架构,用于检测对端可用性

测试

12 个新测试:

  • DialogTest — 5
  • DigestChallengeTest — 6(含 GB28181 风格的 MD5 legacy 挑战)
  • DigestResponseTest — 4(RFC 7616 example、SHA-256 哈希长度、无 qop 路径、MD5 算式验证)
  • RegistrationClientTest — 2(请求字段、自定义 Expires)

验证

mvn -B verify → 9 modules SUCCESS, 158 tests, 0 failures
Open in Web Open in Cursor 

sip-dialog 模块
- DialogId:(callId, localTag, remoteTag) — RFC 3261 §12.1.1
- DialogState:EARLY / CONFIRMED / TERMINATED
- Dialog
  · fromUacResponse:UAC 视角,UAC route set = reverse(Record-Route)
  · fromUasRequest:UAS 视角,UAS route set = Record-Route 原序
  · remoteTarget 自动从 Contact 解析
  · nextLocalCSeq 单调递增
  · onResponse 把 EARLY 升级为 CONFIRMED
  · refreshRemoteTarget 实现 RFC §12.2.1.2 target refresh
- DialogTest(5 个):UAC/UAS 构造、route set 顺序、early→confirmed、CSeq 单调

sip-ua 模块
- SipStackInfo + Branch(RFC §8.1.1.7 magic cookie + 96-bit 随机熵)
- auth/DigestChallenge:解析 WWW-Authenticate / Proxy-Authenticate
  · 支持 RFC 7616 SHA-256 / SHA-512-256 与 RFC 2617 MD5
  · realm / nonce 必需;opaque / qop / stale / algorithm 可选
  · 自实现 quoted-string + escape 解析
- auth/DigestResponse:构造 Authorization header
  · HA1 / HA2 / response 按 RFC 7616 §3.4 计算
  · qop=auth 时附 cnonce/nc;无 qop 走 legacy
  · 算法映射 MD5/SHA-256/SHA-512-256
- RegistrationClient
  · 构造 REGISTER(含 Via 带 rport、Contact、Expires、User-Agent)
  · 走 NonInviteClientTransaction
  · 收到 401/407 自动用 Digest 凭据重发(一次性,不重试第二次)
  · 自动选 WWW-Authenticate vs Proxy-Authenticate 对应的 Authorization header
- OptionsProbe:OPTIONS 检测可用性,CompletableFuture<SipResponse> 返回

测试(12 个)
- DigestChallengeTest:6 个(basic、MD5 legacy、opaque/stale、非 Digest 拒、缺 realm/nonce 拒)
- DigestResponseTest:4 个(RFC 7616 例验证、SHA-256 哈希长度、无 qop 路径、MD5 哈希正确性)
- RegistrationClientTest:2 个(请求字段、自定义 Expires 值)

mvn verify:9 模块 SUCCESS,全 158 tests 通过。

Co-authored-by: li xuanqun <793005378@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants