SIP INVITE 的 Asterisk 摘要认证给出 "user mismatch" 错误

Asterisk Digest Authentication for SIP INVITE gives "user mismatch" error

我正在构建一个基本的 SIP UA。我正在发送以下 INVITE,如 Asterisk 控制台中所示(仅显示与身份验证相关的 headers):

INVITE sip:104@192.168.1.92 SIP/2.0
From: "110"<sip:110@192.168.1.92>;tag=80859256
To: <sip:104@192.168.1.92>
Call-ID: 80859256
CSeq: 80859256 INVITE
Via: SIP/2.0/UDP 192.168.1.92:6000;branch=z9hG4bK-80859256
Contact: <sip:110@192.168.1.92>

作为回应,我收到以下挑战:

 SIP/2.0 401 Unauthorized
 Via: SIP/2.0/UDP 192.168.1.92:6000;branch=z9hG4bK-   80859256;received=127.0.0.1
 From: "110"<sip:110@192.168.1.92>;tag=80859256
 To: <sip:104@192.168.1.92>;tag=as25af7f49
 Call-ID: 80859256
 CSeq: 80859256 INVITE
 Server: Asterisk PBX 13.7.2
 Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
 Supported: replaces, timer
 WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="20e95772"
 Content-Length: 0

我回复如下:

 ACK sip:104@192.168.1.92 SIP/2.0
 From: "110"<sip:110@192.168.1.92>;tag=80859256
 To: <sip:104@192.168.1.92>;tag=as25af7f49
 Call-ID: 80859256
 CSeq: 80859256 ACK
 Via: SIP/2.0/UDP 192.168.1.92:6000;rport;branch=z9hG4bK-80859256
 Contact: <sip:110@192.168.1.92>
 Content-Length: 0


 INVITE sip:104@192.168.1.92 SIP/2.0
 From: "110"<sip:110@192.168.1.92>;tag=80859256
 To: <sip:104@192.168.1.92>
 Call-ID: 80859256
 CSeq: 80859257 INVITE
 Via: SIP/2.0/UDP 192.168.1.92:6000;rport;branch=z9hG4bK-80859257
 Max-Forwards:5
 Allow: REGISTER, INVITE, ACK, BYE, REFER, NOTIFY, CANCEL, INFO, OPTIONS, PRACK, SUBSCRIBE
 Contact: <sip:110@192.168.1.92>
 Authorization: Digest
 username="110",realm="asterisk", nonce="20e95772",uri="sip:104@192.168.1.92",response="ed2de012b2255e85ddb0ee724b9a3ffd"
 Session-Expires: 1800
 Min-SE: 90
 Content-Type: application/sdp

我没有在上面包含与邀请一起发送的实际 SDP。分机 110 的密码是 sip.conf.

中定义的 110

问题: 我收到此错误:

 WARNING...: chan_sip.c:16702 check_auth: username mismatch, have <110>, digest has <>
 NOTICE...: chan_sip.c:25603 handle_request_invite: Failed to authenticate device "110"<sip:110@192.168.1.92>;tag=76981187

随后是 "SIP/2.0 403 Forbidden" 消息。

我不认为我在第二个 INVITE 中发送的摘要计算有误。

需要更改什么?我花了很多时间来调试这个...... 任何帮助将不胜感激。

响应中的用户名被 Asterisk 解析为空,因为授权 header 字段在单词 "Digest" 和 "username" 之间的 CR+LF 之后结束。为了在新行上继续 header 字段,该行需要以空格开头;来自 RFC3261:

Header fields can be extended over multiple lines by preceding each extra line with at least
one SP or horizontal tab (HT).  The line break and the whitespace at the beginning of the
next line are treated as a single SP character.

删除 CR+LF 或在新行的开头插入空格应该可以解决问题。