datso / react-native-pjsip

A PJSIP module for React Native.
http://datso.github.io/react-native-pjsip
GNU General Public License v3.0
272 stars 228 forks source link

CreateAccount return Registration Unauthorized #218

Closed dariomalfatti-centropaghe closed 3 years ago

dariomalfatti-centropaghe commented 3 years ago

Hi, I'm trying to connect to a Kamailio server but after executing the CreateAccount, into the registration_changed event, I got this:

_registration: AccountRegistration
    _active: false
    _reason: "Unauthorized"
    _status: "PJSIP_SC_UNAUTHORIZED"
    _statusText: "Unauthorized"

My configuration is this:

            const configuration : PjsipConfiguration = {
            name: 'My App',
            username: 'user_dsadsada',
            password: '******',
            domain: 'kamailio.site',
            transport: 'UDP',
            regServer: 'kazoo.kamailio.it',
            proxy: '<sip:kazoo.kamailio.it;transport=udp>',
            regOnAdd: true,
            regTimeout: 3600,
            regHeaders: {
                "user-agent": MyApp'
            }
        };

               const contactUriParams = Platform.select({
            ios: [
                ";app-id=com.myapp",
                (tokens['voip'] ? `;pn-voip-tok=${tokens['voip']}` : ""),
                (tokens['im'] ? `;pn-im-tok=${tokens['im']}` : "")
            ].join(''),
            android: `;im-type=sip`
        });

                try {

            const account = await endpoint.createAccount({
                ...configuration,
                transport: configuration.transport || 'UDP',
                contactUriParams
            });

            dispatch(accountUpdated(account));

            return account;

        } catch (e : unknown) {

            logError(e);

        }

        return null;

The Kamailio log is this:

start|received udp request REGISTER sip:kamailio.site
log|source 159.255.222.111:59543 -> 10.100.100.220:5060
log|from sip:user_dsadsada@kamailio.site
log|to sip:user_dsadsada@kamailio.site
log|originated from external sources
end|challenging user_dsadsada@kamailio.site 159.255.222.111:59543

If I try to do the connection with Linphone, with the same configuration, I got this:

|start|received udp request REGISTER sip:kamailio.site
|log|source 159.255.111.222:52510 -> 10.100.100.220:5060
|log|from sip:user_dsadsada@kamailio.site
|log|to sip:user_dsadsada@kamailio.site
|log|originated from external sources
|end|challenging user_dsadsada@kamailio.site 159.255.111.222:52510
|start|received udp request REGISTER sip:kamailio.site
|log|source 159.255.111.222:52510 -> 10.100.100.220:5060
|log|from sip:user_dsadsada@kamailio.site
|log|to sip:user_dsadsada@kamailio.site
|log|originated from external sources
|log|received directory authn_resp reply from registrar-4.0.0 (Δ1 1223 μs , Δ2 268 μs, Δ3 21892 μs)
|log|authenticating user_dsadsada@kamailio.site via registrar-4.0.0 response
|end|successful registered with contact : "Dario" <sip:user_dsadsada@159.255.111.222:52510;transport=udp>;+sip.instance="<urn:uuid:c0f5ff82-ad3b-0078-8417-337e3a2fad1c>" : 3600

It seems that it doesn't automatically reply to the first responce to complete the authentication.

dariomalfatti-centropaghe commented 3 years ago

I found the solution, the problem was in the configuration. I get rid of the regServer property and I got the registration ok.

const configuration : PjsipConfiguration = {
            name: 'My App',
            username: 'user_dsadsada',
            password: '******',
            domain: 'kamailio.site',
            transport: 'UDP',
            proxy: '<sip:kazoo.kamailio.it;transport=udp>'
        };