2011-04-29 114 views
2

我正在开发连接到Asterisk服务器并尝试拨打电话的SIP用户代理应用程序。我正在使用JAIN SIP API的NIST实现。SIP代理验证失败

当应用程序注册自身时,401(未授权)响应会使用WWW-Authenticate标头对其进行挑战。应用程序将授权标头插入到下一个REGISTER请求中。这次Asterisk返回200(OK)响应 - 注册成功。

当应用程序发送INVITE请求时,Asterisk以407(需要代理身份验证)响应作出响应。这次响应包含一个Proxy-Authenticate头。我的应用程序再次发送一个INVITE,但是这次使用授权标头,Asterisk响应同样的407(需要代理认证)响应。

下面是所传输的SIP消息( '>>' 指示传出消息; '< <' 指示的传入消息):

>>

REGISTER sip:10.0.84.30:5060 SIP/2.0 
Call-ID: [email protected] 
CSeq: 1 REGISTER 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]> 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKc7dd178d3d444ccc059a191e700fc8b73230 
Max-Forwards: 70 
Contact: <sip:10.0.85.3:5060> 
Expires: 300 
Content-Length: 0 

< <

SIP/2.0 100 Trying 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKc7dd178d3d444ccc059a191e700fc8b73230;received=10.0.85.3 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]> 
Call-ID: [email protected] 
CSeq: 1 REGISTER 
User-Agent: Asterisk PBX (switchvox) 
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY 
Contact: <sip:[email protected]> 
Content-Length: 0 

< <

SIP/2.0 401 Unauthorized 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKc7dd178d3d444ccc059a191e700fc8b73230;received=10.0.85.3 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]>;tag=as3c458716 
Call-ID: [email protected] 
CSeq: 1 REGISTER 
User-Agent: Asterisk PBX (switchvox) 
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY 
Contact: <sip:[email protected]> 
WWW-Authenticate: Digest realm="asterisk",nonce="6fbe5a68" 
Content-Length: 0 

>>

REGISTER sip:10.0.84.30:5060 SIP/2.0 
CSeq: 2 REGISTER 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]> 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKffb0be254f93f61fa0dc7ac32b9078a43230 
Max-Forwards: 70 
Contact: <sip:10.0.85.3:5060> 
Expires: 300 
Authorization: Digest username="301",realm="asterisk",nonce="6fbe5a68",response="bc7075e8e241a4109dfa24d6ae95e78c",algorithm=MD5,uri="sip:10.0.84.30:5060",nc=00000001 
Call-ID: [email protected] 
Content-Length: 0 

< <

SIP/2.0 100 Trying 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKffb0be254f93f61fa0dc7ac32b9078a43230;received=10.0.85.3 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]> 
Call-ID: [email protected] 
CSeq: 2 REGISTER 
User-Agent: Asterisk PBX (switchvox) 
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY 
Contact: <sip:[email protected]> 
Content-Length: 0 

< <

SIP/2.0 200 OK 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKffb0be254f93f61fa0dc7ac32b9078a43230;received=10.0.85.3 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]>;tag=as3c458716 
Call-ID: [email protected] 
CSeq: 2 REGISTER 
User-Agent: Asterisk PBX (switchvox) 
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY 
Expires: 300 
Contact: <sip:10.0.85.3:5060>;expires=300 
Date: Tue, 03 May 2011 06:42:33 GMT 
Content-Length: 0 

>>

INVITE sip:[email protected] SIP/2.0 
Call-ID: [email protected] 
CSeq: 3 INVITE 
From: <sip:[email protected]>;tag=KOZWxg 
To: <sip:[email protected]> 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKaa0520efde83907b71d1f76315188c413230 
Max-Forwards: 70 
Contact: <sip:10.0.85.3:5060> 
Route: <sip:10.0.84.30:5060;lr> 
Content-Type: application/sdp 
Content-Length: 106 

>>

v=0 
o=- 3513393083 3513393083 IN IP4 10.0.85.3 
s=- 
c=IN IP4 10.0.85.3 
t=0 0 
m=audio 40000 RTP/AVP 3 

< <

SIP/2.0 407 Proxy Authentication Required 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bKaa0520efde83907b71d1f76315188c413230;received=10.0.85.3 
From: <sip:[email protected]>;tag=KOZWxg 
To: <sip:[email protected]>;tag=as5de9ed83 
Call-ID: [email protected] 
CSeq: 3 INVITE 
User-Agent: Asterisk PBX (switchvox) 
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY 
Contact: <sip:[email protected]> 
Proxy-Authenticate: Digest realm="asterisk",nonce="74986b64" 
Content-Length: 0 

>>

INVITE sip:[email protected] SIP/2.0 
CSeq: 4 INVITE 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]> 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bK86f9dbdff9eeca422fbb67321dd45f7a3230 
Max-Forwards: 70 
Contact: <sip:10.0.85.3:5060> 
Route: <sip:10.0.84.30:5060;lr> 
Content-Type: application/sdp 
Authorization: Digest username="301",realm="asterisk",nonce="74986b64",response="a08b8d7ce96cae00e7d334e132bf7358",algorithm=MD5,uri="sip:[email protected]",nc=00000001 
Call-ID: [email protected] 
Content-Length: 106 

>>

v=0 
o=- 3513393083 3513393083 IN IP4 10.0.85.3 
s=- 
c=IN IP4 10.0.85.3 
t=0 0 
m=audio 40000 RTP/AVP 3 

< <

SIP/2.0 407 Proxy Authentication Required 
Via: SIP/2.0/UDP 10.0.85.3:5060;branch=z9hG4bK86f9dbdff9eeca422fbb67321dd45f7a3230;received=10.0.85.3 
From: <sip:[email protected]>;tag=2B3n8g 
To: <sip:[email protected]>;tag=as3c458716 
Call-ID: [email protected] 
CSeq: 4 INVITE 
User-Agent: Asterisk PBX (switchvox) 
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY 
Contact: <sip:10.0.85.3:5060> 
Proxy-Authenticate: Digest realm="asterisk",nonce="1bd30f50" 
Content-Length: 0 

授权标头在两种情况下都是以完全相同的方式构造的(与执行的代码相同)。 我为“digestURI”使用请求的请求URI。 我试过使用代理授权标头而不是授权标头,但结果是一样的。

任何人都可以看到我做错了什么? 在此先感谢。

回答

3

对于代理进行身份验证(换句话说,您得到了407 Proxy Authentication Required,您需要一个Proxy-Authorization标头。

由于RFC 2617表示,您的构造方法与您的Authorization标题相同。

您提到在您的问题中使用From URI。 RFC 2617 section 3.2.2表示您使用请求URI(sip:[email protected])。注意RFC 3261 section 22.4中SIP特定的更改。

+0

感谢您的提示。我已将标题更改为代理授权标头,但我仍然遇到同样的问题。我已经更新了问题中的SIP会话。 – bgh 2011-04-29 11:12:08

0

有点奇怪你的Asterisk服务器正在响应一个407我刚刚检查过我的,它以401响应。星号毕竟是B2BUA而不是代理。我建议在已验证的请求中尝试授权标头,而不是代理授权,因为它适用于我的Asterisk服务器。

此外,您还需要在摘要中使用请求URI,而不是From头URI。所以你的情况应该是uri = sip:302 @ asterisk。

+0

我已将摘要URI更改为请求的请求-URI。注册请求仍然有效(显然,Asterisk并不在乎这个请求的摘要URI使用了什么URI(例如,我可以使用URI“sip:blah @ asterisk”),尽管它确实检查了响应被正确计算),但对于INVITE请求,我仍然得到相同的回应。我已经尝试使用授权标题和使用代理授权标头。在这两种情况下,我都会得到相同的结果我已经更新了问题中的请求,就像我现在所做的那样。 – bgh 2011-05-03 07:19:58

1

我已经解决了这个问题。 似乎Asterisk无法将我的第二个INVITE请求与前面的407(需要代理身份验证)响应关联,其中包含Proxy-Authentication标头的随机数值。

这是因为我没有对两个INVITE请求使用相同的Call-ID值和From-header标签。对于包含Proxy-Authentication Header的第二个INVITE请求,我不小心使用了第一个REGISTER请求的Call-ID和From-Header标记值,而不是第一个INVITE请求。

虽然INVITE还没有成功。对于第二个反应,我现在得到了488(这里不能接受),但是我会尝试在另一个问题中找出现在有什么问题。

+0

我知道这是几年后,但我有一个类似的问题,我已发布[这里](http://stackoverflow.com/questions/36998787/asterisk-digest-authentication-for-sip-invite-gives-user-mismatch - 恐怖)如果你可以看看,会感激。我花了很多时间试图修复它,但无济于事...... – Sam 2016-05-03 12:39:00