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

Please add STUN server username and password support #87

Closed
ndilieto opened this issue Jun 14, 2020 · 15 comments
Closed

Please add STUN server username and password support #87

ndilieto opened this issue Jun 14, 2020 · 15 comments

Comments

@ndilieto
Copy link

This would be greatly appreciated, thanks.

@licaon-kter
Copy link
Contributor

Wait...isn't the actual username and its password used?

@juha-h
Copy link
Owner

juha-h commented Jun 14, 2020

If stunuser and/or stunpass are not given, then looks like uri user (not auth user) and auth_pass are used:

	if (0 == msg_param_exists(&aor->params, "stunuser", &tmp))
		err |= param_dstr(&acc->stun_user, &aor->params, "stunuser");
	else
		err |= pl_strdup(&acc->stun_user, &aor->uri.user);

	if (0 == msg_param_exists(&aor->params, "stunpass", &tmp))
		err |= param_dstr(&acc->stun_pass, &aor->params, "stunpass");
	else if (acc->auth_pass)
		err |= str_dup(&acc->stun_pass, acc->auth_pass);

I can add stun user and stun pass when I get the time.

@ndilieto
Copy link
Author

I've tried entering stunuser/stunpass but they get rejected. Maybe I am doing something wrong, but the help text (lines 82-84 of app/src/main/res/values/strings.xml) says they are not supported.

    <string name="stun_server_help">A STUN Server of form host[:port].
        Factory default value is \'stun.l.google.com:19302\', pointing to public Google STUN server.
        Username and password are currently not supported.

@juha-h
Copy link
Owner

juha-h commented Jun 14, 2020

Yes, they are not yet supported. It should work if you can configure your stun server to accept uri userpart as username and authentication password as password.

@ndilieto
Copy link
Author

ndilieto commented Jun 15, 2020

And would it also be possible to add "TURN" to media nat options? The turn module is already enabled so it probably is just a matter of adding turn/TURN to the arrays on lines 81-82 of app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt.

@juha-h
Copy link
Owner

juha-h commented Jun 16, 2020

I'll add TURN option too. New API functions need to be first added to baresip lib for setting STUN username and password (baresip/baresip#1015).

@ndilieto
Copy link
Author

I'll add TURN option too.

Ok, many thanks. Watch out, the turn module needs the stun server uri to start with "turn:", not "stun:", see cherck on lines 188-189 of libbaresip-android/baresip/modules/turn/turn.c

        if (srv->scheme != STUN_SCHEME_TURN)
                return ENOTSUP;

Also ICE uses the scheme to decide whether to operate in STUN or TURN mode (lines 482-500 of libbaresip-android/baresip/modules/ice/ice.c)

        if (srv) {
                info("ice: new session with %s-server at %s (username=%s)\n",
                     srv->scheme == STUN_SCHEME_TURN ? "TURN" : "STUN",
                     srv->host, user);

                switch (srv->scheme) {

                case STUN_SCHEME_STUN:
                        usage = stun_usage_binding;
                        break;

                case STUN_SCHEME_TURN:
                        usage = stun_usage_relay;
                        break;

                default:
                        return ENOTSUP;
                }
        }

@juha-h
Copy link
Owner

juha-h commented Jun 17, 2020

I just pushed commit e7af96f to master that adds support for TURN server and STUN/TURN username/password.

New version that includes the commit is not in the stores yet, but if you @ndilieto are rolling your own baresip, please give it a try.

@ndilieto
Copy link
Author

ndilieto commented Jun 17, 2020

I've tried it and it works but the TURN module works only if I quit the application then restart it. I've traced it to the fact that when it starts up, account_alloc calls stunsrv_decode which calls stunuri_decode and therefore stunuri.scheme gets set correctly. When changing it from the gui without restarting instead, account_set_stun_host only calls stunuri_set_host which does not update stunuri.scheme. As a result the TURN module fails with ENOTSUP.

Perhaps account_set_stun_host needs to call stunuri_decode too?

@juha-h
Copy link
Owner

juha-h commented Jun 18, 2020

How about this (not tested)?

int account_set_stun_uri(struct account *acc, const char *uri)
{
	struct pl pl;
	int err;
	
	if (!acc)
		return EINVAL;

	acc->stun_host = mem_deref(acc->stun_host);

	if (!uri)
		return 0;

	pl_set_str(&pl, uri);
	err = stunuri_decode(&acc->stun_host, &pl);
	if (err)
		warning("account: decode '%r' failed: %m\n",
			&pl, err);
	
	return err;
}

@ndilieto
Copy link
Author

How about this (not tested)?

It works but after the app is restarted, the STUN server in the gui loses the "turn:"/"stun:" prefix. I think this is because it gets populated by account_stun_host which only returns the host part after the prefix and it ignores the scheme.

@juha-h
Copy link
Owner

juha-h commented Jun 19, 2020

Yes, I noticed it too and I'm now in the process of adding two new API functions: account[_set]_stun_uri, since there is currently no way of getting the scheme of STUN server URI.

@juha-h
Copy link
Owner

juha-h commented Jun 19, 2020

Master branch is now using account[_set]_stun_uri API functions. Please try again.

@ndilieto
Copy link
Author

It works. Many thanks for your very prompt reaction.

@juha-h
Copy link
Owner

juha-h commented Jun 19, 2020

Thanks for testing.

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

No branches or pull requests

3 participants