Skip to content

Conversation

maximilianfridrich
Copy link
Contributor

@maximilianfridrich maximilianfridrich commented Jul 11, 2024

If the new config option filter_registrar is set to some transport (default: ""), any incoming request of that transport is verified to have originated from a registered server's IP address (only makes sense for registered accounts regint>0). Further, no listening socket is opened for the connection-oriented transport protocols listed in filter_registrar (i.e. a UDP socket is always opened if UDP is configured). BareSIP's default behavior stays the exact same.

Requires:

@juha-h
Copy link
Collaborator

juha-h commented Jul 11, 2024

If UDP is used, nothing can be verified. Also, it would make more sense to use TLS and verify that server's certificate matches.

@maximilianfridrich
Copy link
Contributor Author

maximilianfridrich commented Jul 11, 2024

If UDP is used, nothing can be verified.

The source IP address of the request is still set and we can verify it. I'm not sure what you mean.

Also, it would make more sense to use TLS and verify that server's certificate matches.

Agreed, I'd prefer that too and BareSIP already provides that. However, we still have someone who wants to verify the server by its IP address (they don't use TLS unfortunately).

@juha-h
Copy link
Collaborator

juha-h commented Jul 12, 2024

The source IP address of the request is still set and we can verify it. I'm not sure what you mean.

Yes, but since in UDP there is no connection setup, sender can put whatever source address in the IP packet. So baresip can check that the source address of the IP packet matches, but cannot verify where it was sent from.

@maximilianfridrich
Copy link
Contributor Author

maximilianfridrich commented Jul 12, 2024

I see, you're right. This of course does not protect against IP address spoofing. We all know that TLS is the solution, but we still have a feature request of a customer who wants to verify IP addresses and maybe other people would like that too. They have to be aware of the limitations of this approach, but I believe it could still be a useful feature for some people.

@juha-h
Copy link
Collaborator

juha-h commented Jul 12, 2024

Add clearly to the documentation that in case of UDP this setting cannot verify that a SIP request originated from the server, but only that source IP address of the request matched.

@juha-h
Copy link
Collaborator

juha-h commented Jul 12, 2024

Another security setting that could be added is "Send all in-dialog requests and replies to the outbound proxy".

src/reg.c Outdated
if (!reg)
return NULL;

return sipreg_paddr(reg->sipreg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to save paddr locally. Then there is no changes to libre needed ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that's much better. Done.

@@ -43,6 +43,7 @@
# ;stunserver=stun:[user:pass]@host[:port] # see RFC 3986: Use of the format "user:password" in the userinfo field is deprecated.
# ;tcpsrcport=6060
# ;inreq_allowed={yes, no} # default: yes
# ;server_only={yes, no} # default: no
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TCP and TLS already have a connection to the server, which is difficult to spoof.

What happens if you are using SIP outbound with 2 edge proxies and load balancing,
will you accept incoming request from both ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, now the peer address is stored in the reg struct in BareSIP and now all of the register clients are checked (i.e. all proxies defined in outbound will be allowed). Done.

@juha-h
Copy link
Collaborator

juha-h commented Jul 16, 2024

Commonly outbound proxy or proxies are configured using domain name of the host(s) in the URI(s). Will this PR make DNS query to find their current IP addresses?

@juha-h
Copy link
Collaborator

juha-h commented Jul 16, 2024

Starts to looks to me that baresip account config is not a good way to solve the problem. Better to use firewall configuration in the host.

@maximilianfridrich
Copy link
Contributor Author

maximilianfridrich commented Jul 16, 2024

Commonly outbound proxy or proxies are configured using domain name of the host(s) in the URI(s). Will this PR make DNS query to find their current IP addresses?

That is something I considered, however I believe it is quite unlikely that the case occurs where we receive a REGISTER response from some IP A, and then receive an incoming request from the same "server" (i.e. URI) with a different IP. If the proxy is a domain name and it resolves to multiple IPs, then the client is likely also behind a NAT and not easily reachable from outside except for the IP that it sent the REGISTER request to. It's not impossible of course, but I think it could be enough to document this limitation if anyone wants to use this feature.

Starts to looks to me that baresip account config is not a good way to solve the problem. Better to use firewall configuration in the host.

That's a valid point. If the maintainers agree and don't want to see this feature in BareSIP then we will have to accept that.

@maximilianfridrich
Copy link
Contributor Author

Grandstream and Snom for example have such a setting:

@juha-h
Copy link
Collaborator

juha-h commented Jul 17, 2024

When baresip uses TCP or TLS to connect to outbound proxy/proxies, baresip should accept SIP requests only when they come via those connections. That is, there is no reason why baresip should accept incoming TCP or TLS connections from anywhere. And in case of UDP, source IP address does not prove anything as I have mentioned earlier.

@alfredh
Copy link
Collaborator

alfredh commented Jul 19, 2024

The SIP stack has a TCP server that is listening for incoming TCP/TLS and WS/WSS connections.
In the context of this PR you might want to disable this server to increase the perceived security.

Reusing naming from other products is nice for people already familiar with Snom products:

Example:

filter_registrar    udp
filter_registrar    udp,tcp

@maximilianfridrich
Copy link
Contributor Author

Sounds good, thank you for the feedback. I will start working on that.

@juha-h
Copy link
Collaborator

juha-h commented Jul 19, 2024

The SIP stack has a TCP server that is listening for incoming TCP/TLS and WS/WSS connections. In the context of this PR you might want to disable this server to increase the perceived security.

This makes sense. As I commented in above, when outbound proxy is used and baresip connects to it over TLS, TCP, or WS/WSS, there is no need for baresip to accept any connections from anywhere and thus not to listed for any incoming connections.

@sreimers sreimers added this to the v3.15.0 milestone Jul 22, 2024
@maximilianfridrich maximilianfridrich changed the title add server_only account config add filter_registrar option Jul 22, 2024
@maximilianfridrich maximilianfridrich force-pushed the server_only branch 2 times, most recently from aeb3355 to ee2ed97 Compare July 23, 2024 08:06
@cspiel1
Copy link
Collaborator

cspiel1 commented Jul 26, 2024

This is ready for merge in our opinion. Any further suggestions?

@alfredh
Copy link
Collaborator

alfredh commented Jul 26, 2024

this look good. Please go ahead and merge it.

@juha-h
Copy link
Collaborator

juha-h commented Jul 26, 2024

Is there now the possibility to prevent all incoming connection setups when outbound proxy is defined using a connection oriented transport?

@maximilianfridrich
Copy link
Contributor Author

Yes, @juha-h. For example with the following config:

sip_transports      tcp,tls
filter_registrar    tcp,tls

No listening ports will be opened and only outgoing TCP/TLS connections will work. The proxy/registrar will have to use the existing TCP/TLS connection.

@juha-h
Copy link
Collaborator

juha-h commented Jul 26, 2024

Yes, @juha-h. For example with the following config:

sip_transports      tcp,tls
filter_registrar    tcp,tls

No listening ports will be opened and only outgoing TCP/TLS connections will work. The proxy/registrar will have to use the existing TCP/TLS connection.

Very good.

@cspiel1 cspiel1 merged commit a61ffe2 into baresip:main Jul 26, 2024
@maximilianfridrich maximilianfridrich deleted the server_only branch July 26, 2024 11:35
maximilianfridrich added a commit to maximilianfridrich/baresip that referenced this pull request Jul 29, 2024
cspiel1 pushed a commit to cspiel1/baresip that referenced this pull request Aug 23, 2024
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

Successfully merging this pull request may close these issues.

5 participants