Forum Xamarin.Android

Unable to authorize to SIP server (plivo) using Android.Net.Sip

I have a pretty straightforward SIP client based on SipDemo that appears to be unable to connect to a server which is expecting authorization headers.

I've worked with a support tech at Plivo who has looked at the code and had no complaints, which is not to say I haven't made a mistake, but the next logical thing to do in my position is to look into whether Android.Net.Sip is actually capable of authorization. Can anyone confirm either that I'm doing this wrong or that the support is missing?

Here is what I have:

protected override void OnCreate (Bundle bundle)
{
  /* ... */
  if (null == sipManager)
    sipManager = SipManager.NewInstance (this);

  if (null == regListener)
    regListener = new SipRegistrationListener (this);

  if (null != sipProfile) {
    try { sipManager.Close (sipProfile.UriString); } /* ... */
  }

  /* ... */
  SipProfile.Builder builder = new SipProfile.Builder(username, domain);
  builder.SetAuthUserName (username);
  builder.SetPassword (password);
  builder.SetAutoRegistration (true);
  profile = builder.Build();
  ThreadPool.QueueUserWorkItem (o => Register());
}

private void Register ()
{
  /* ... */
  try {
    sipManager.Open (sipProfile, pRecvIntent, null);
    sipManager.SetRegistrationListener (sipProfile.UriString, regListener);
  }
  /* ... */
}

Here is what the streams look like during registration. Sent:

REGISTER sip:phone.plivo.com SIP/2.0
Call-ID: [email protected]
CSeq: 3923 REGISTER
From: <sip:[email protected]>;tag=923783190
To: <sip:[email protected]>
Via: SIP/2.0/UDP 192.168.2.7:52944;branch=z9hG4bK18b62e7401a0ff55ec48863392b3807a373739;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0

Received:

SIP/2.0 401 Unauthorized
Call-ID: [email protected]
CSeq: 3923 REGISTER
From: <sip:[email protected]>;tag=923783190
To: <sip:[email protected]>;tag=10189173b4422b3fef2ddeddbb216bdd.1e85
Via: SIP/2.0/UDP 192.168.2.7:52944;branch=z9hG4bK18b62e7401a0ff55ec48863392b3807a373739;rport=52632;received=64.245.24.142
WWW-Authenticate: Digest realm="phone.plivo.com", nonce="UuMHjlLjBmKwBPlizi1td0dO5NMpALPX"
Server: kamailio (3.4.0-dev5 (x86_64/linux))
Content-Length: 0

Here is (I think) the specification that the "Authorization" header that belongs in that stream should conform to: http://sofia-sip.sourceforge.net/refdocs/sip/group__sip__authorization.html#_details

The SipManager and SipProfile objects are declared static (along with others), the manager is initialized once but the profile is re-initialized during OnCreate to account for changes in credentials (or to lock out accounts that haven't paid their bill).

To ensure clean login attempts I reboot the phone after redeploying updated code, before testing it. On the Plivo end, my support friend was inspecting the logs for the test SIP account. I captured the stream using tPacketCapture and we both analyzed .pcap files in wireshark to confirm the behavior we were seeing.

We also attempted changing the protocol from UDP to TCP with an identical result.

Interesting anomaly with SipRegistrationListener unless I'm using that wrong, too: SIP registration events are not fired at all if AutoRegistration is set to false, but each event is fired twice when set to true! Yet the stream does not appear to reflect two registration attempts.

Posts

Sign In or Register to comment.