Resip学习笔记(sip服务器对初次registration信令回复407而不是401)

首先我们讨论一下sip服务器回复401与407有什么区别,看了一下rfc3261,发现没有明确的说明,只是说401是UAS和registar回复的应答,而407是proxy回复的应答。但是很多时候proxy就是UAS,在GB28181里面有什么讲究呢?从网络上看到这么一种解答不知准确与否:

401 Unauthorized,明确提示是未授权。这个应答是由UAS和注册服务器产生的。常见场景是Register用户注册的时候。
407 proxy authentication required ,意思是proxy服务器需要提供认证信息。常见场景是Invite发起呼叫的时候。

目前我们就当他是准确的说法吧,回到我们的问题,怎么解决服务器对registration回复是407而不是401,通过跟踪源码我们发现:

SipMessage*
Helper::makeChallenge(const SipMessage& request, const Data& realm, bool useAuth, bool stale, bool proxy)
{
   Auth auth;
   auth.scheme() = Symbols::Digest;
   Data timestamp(Timer::getTimeSecs());
   auth.param(p_nonce) = makeNonce(request, timestamp);
   auth.param(p_algorithm) = "MD5";
   auth.param(p_realm) = realm;
   if (useAuth)
   {
      auth.param(p_qopOptions) = "auth,auth-int";
   }
   if (stale)
   {
      auth.param(p_stale) = "true";
   }
   SipMessage *response;
   if(proxy)
   {
      response = Helper::makeResponse(request, 407);
      response->header(h_ProxyAuthenticates).push_back(auth);
   }
   else
   {
      response = Helper::makeResponse(request, 401);
      response->header(h_WWWAuthenticates).push_back(auth);
   }
   return response;
}

我们Helper是根据是否是proxy决定生成401的响应还是407的响应,如果是proxy生成407,如果不是生成401.

而是不是proxy是由ServerAuthManager决定的,调用上面代码的代码片段为:

void
ServerAuthManager::issueChallenge(SipMessage *sipMsg) 
{
  //assume TransactionUser has matched/repaired a realm
  SharedPtr<SipMessage> challenge(Helper::makeChallenge(*sipMsg,
                                                        getChallengeRealm(*sipMsg), 
                                                        useAuthInt(), 
                                                        false /*stale*/,
                                                        proxyAuthenticationMode()));

  InfoLog (<< "Sending challenge to " << sipMsg->brief());
  mDum.send(challenge);
}

而在ServerAuthManager中proxyAuthenticationMode()的返回值总为true,所以我们得想办法让该函数的返回值为false,本着不改变协议栈代码的原则,我们发现proxyAuthenticationMode()是一个虚函数,所以我们只要写一个类继承ServerAuthManager,在我们的新类中将proxyAuthenticationMode()的返回值改为false即可解决该问题。

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

heibao111728

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值