Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIP INVITE Failing with "401 Unauthorized" Response from Asterisk [v1.2.3] #3402

Open
mamoun-mohammed opened this issue Jul 7, 2024 · 9 comments
Labels
multistream Related to Janus 1.x

Comments

@mamoun-mohammed
Copy link

mamoun-mohammed commented Jul 7, 2024

What version of Janus is this happening on?
v1.2.3

Have you tested a more recent version of Janus too?
Yes

Was this working before?
No
Is there a gdb or libasan trace of the issue?
Not Sure

Additional context
I'm facing an issue with SIP plugin where SIP INVITE requests fail with a "401 Unauthorized" response from the Asterisk server when I use the SIP demo to create audio calls. The same setup works perfectly when receiving calls from the sip demo but when I try to make calls it fails due to an authorization error even though it works with receiving. I have been looking into this for a long time without any productive outcome. any help would be appreciated.

Configuration:

Janus WebRTC Server SIP Plugin version: 0.0.9
Asterisk version: FPBX-16.0.33(18.16.0)
Janus logs:

Sending event to janus.transport.http (0x7fde1c022440)
Got a Janus API event to send (0x7fde1c022440)
We have a message to serve...
        [
   {
      "janus": "event",
      "session_id": 647694817353594,
      "transaction": "SwZp6rdRup2B",
      "sender": 7586608400691431,
      "plugindata": {
         "plugin": "janus.plugin.sip",
         "data": {
            "sip": "event",
            "result": {
               "event": "calling",
               "call_id": "hGZeS2EF1CRYm9LJcyOT6WS"
            },
            "call_id": "hGZeS2EF1CRYm9LJcyOT6WS"
         }
      }
   }
]
  >> Pushing event: 0 (Success)
[2][nua_i_state]: 0 INVITE sent, call state [calling]
[2][nua_r_invite]: 401 Unauthorized
        Digest:"asterisk":2:0785431125Mm
[2][nua_i_state]: 0 INVITE sent, call state [calling]
New connection on REST API: ::1
Session: 647694817353594
Handle: 7586608400691431
Processing POST data (application/json) (244 bytes)...
Session: 647694817353594
Handle: 7586608400691431
Processing POST data (application/json) (0 bytes)...
{"janus":"trickle","candidate":{"candidate":"candidate:3719411463 1 udp 2113937151 22be25f2-a78f-441b-b255-4d8d7570ef3e.local 56093 typ host generation 0 ufrag +zar network-cost 999","sdpMid":"0","sdpMLineIndex":0},"transaction":"bnO2Gy50fjIE"}
Forwarding request to the core (0x7fde1c011fa0)
Got a Janus API request from janus.transport.http (0x7fde1c005460)
[7586608400691431] Still waiting for the answer, queueing this trickle to wait until we're done there...
Sending Janus API response to janus.transport.http (0x7fde1c005460)
Got a Janus API response to send (0x7fde1c005460)
Session: 647694817353594
Got a Janus API request from janus.transport.http (0x7fde1c008b40)
Session 647694817353594 found... returning up to 10 messages
Got a keep-alive on session 647694817353594
Sending Janus API response to janus.transport.http (0x7fde1c008b40)
Got a Janus API response to send (0x7fde1c008b40)
[7586608400691431] Gathering done for stream 1
[2][nua_i_options]: 200 OK`

Janus INVITE Request:

`[2024-07-06 22:58:23] VERBOSE[2129] res_pjsip_logger.c: <--- Received SIP request (1351 bytes) from UDP:192.168.1.147:60200 --->
INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 172.28.49.29:45182;rport;branch=z9hG4bKS1FX4724m8D7a
Max-Forwards: 70
From: "john" sip:[email protected];tag=4rtvDyeaU913K
To: sip:[email protected]
Call-ID: lW78YaWRJmVliYyJP6Slae6
CSeq: 982337813 INVITE
Contact: johnsip:[email protected]:45182;transport=udp
User-Agent: Janus WebRTC Server SIP Plugin 0.0.9
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, REFER, MESSAGE, INFO, NOTIFY
Supported: replaces
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 800

Asterisk Response to Janus:

SIP/2.0 401 Unauthorized Via: SIP/2.0/UDP 172.28.49.29:45182;rport=60200;received=192.168.1.147;branch=z9hG4bKS1FX4724m8D7a Call-ID: lW78YaWRJmVliYyJP6Slae6 From: "john" <sip:[email protected]>;tag=4rtvDyeaU913K To: <sip:[email protected]>;tag=z9hG4bKS1FX4724m8D7a CSeq: 982337813 INVITE WWW-Authenticate: Digest realm="asterisk",nonce="1720306703/b09119604c79ccafc29d8ef9522a1932",opaque="68110e3d0b662ee4",algorithm=MD5,qop="auth" Server: FPBX-16.0.33(18.16.0) Content-Length: 0

@mamoun-mohammed mamoun-mohammed added the multistream Related to Janus 1.x label Jul 7, 2024
@lminiero
Copy link
Member

lminiero commented Jul 8, 2024

Please do NOT paste huge logs inline. As explained in the guidelines, you should either use an external service for that, or use the details/summary feature of github. I fixed it this time for you, but please notice that next time I'll just close the issue.

@mamoun-mohammed
Copy link
Author

@lminiero , i'm sorry about that I didn't know the guidelines. any idea on how to tackle this? thanks.

@shivanshtalwar
Copy link

@lminiero this seems like a legit issue as after upgrading to latest version we cant make calls as it is giving unauthorized error even though we pass correct credentials

@lminiero
Copy link
Member

lminiero commented Oct 8, 2024

I just tried with Asterisk 18.3.0 and it seems to be working fine for me. Of course, I may have a much more basic setup, since I rarely use SIP for anything myself except simple tests. On unauthorized errors, if the user is registered and an INVITE requires a challenge, we use the same credendials we used for a REGISTER. If you're using guest accounts on the Janus SIP plugin side and you get a challenge, there's no credentials available to challenge that and so it will obviously fail.

@shivanshtalwar
Copy link

but we are using sip providers like commpeak and bpo earlier same code used to work and our register request looks like this

{
    "request": "register",
    "username": "sip:[email protected]",
    "force_udp": true,
    "rfc2543_cancel": true,
    "secret": "somepassword",
    "proxy": "sip:pbx.bpotel.com"
}

and janus always give 401 unauthorized even tried on sip demo page however when i pass

{
    "request": "register",
    "type": "guest",
    "proxy": "sip:pbx.bpotel.com",
    "username": "sip:[email protected]"
}

register works and but we cant make a call since authorization is needed which makes sense could you please guide what can i be doing wrong? btw thank you very much in advance and for replying back at the earliest

@lminiero
Copy link
Member

lminiero commented Oct 8, 2024

If you say it used to work before and doesn't now, please use git bisect to find the commit that seems to have broken it for you. That command will pull different versions of Janus that you can then build and test, and you can say whether they work or don't. Eventually, it will identify the commit at fault. If you'd rather not do that, at least telling us which tagged version works and which doesn't will be of help too.

@shivanshtalwar
Copy link

interesting just found out there is no problem with janus but this underlying problem stems from sip dependency i suspect from sofia sip as i was trying to use latest sofia sip version and it is happening on it when i switched to old janus deps image of mine it works fine, i am gonna verify which new version of sofia sip it last worked on thanks for your input i will keep you guys posted

@lminiero
Copy link
Member

lminiero commented Oct 8, 2024

Thanks, that would help, as it may suggest that either some of the latest versions of Sofia SIP are broken somewhere, or the flow to handle authentication changed.

@shivanshtalwar
Copy link

strange the sofia sip version that my old docker image is using is 1.13.16 which i found out by running
pkg-config --modversion sofia-sip-ua in running container, but when i build a new image with 1.13.16 i face this issue also i tried oldest release of sofia sip that is 1.13.2 yet this problem seems to exist could you pin point what other dependencies could be causing this?
for reference i am attaching my old docker image if it can be of any help

# this is a base image for compiling janus with all dependencies 
docker pull shivanshtalwar0/januscoredeps:x86_64

can be used like this

ARG architecture=x86_64
FROM shivanshtalwar0/januscoredeps:${architecture}
LABEL maintainer="shivansh talwar <[email protected]>"
LABEL description="Provides an image with Janus Gateway"
RUN cd ~ \
    && git clone https://github.com/meetecho/janus-gateway.git \
    && cd janus-gateway \
    && sh autogen.sh \
    && ./configure --prefix=/opt/janus  \
    && make \
    && make install \
    && make configs
COPY conf/*.jcfg /opt/janus/etc/janus/
EXPOSE 7088 8088 8188 8089 7188
EXPOSE 10000-10200/udp
CMD /opt/janus/bin/janus

or alternatively you can see my community project https://github.com/flutterjanus/JanusDocker for all files dockerfile,docker-compose.yaml etc.
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multistream Related to Janus 1.x
Projects
None yet
Development

No branches or pull requests

3 participants