jselbie / stunserver

Version 1.2. This is the source code to STUNTMAN - an open source STUN server and client code by john selbie. Compliant with the latest RFCs including 5389, 5769, and 5780. Also includes backwards compatibility for RFC 3489. Compiles on Linux, MacOS, BSD, Solaris, and Win32 with Cygwin. Windows binaries avaialble from www.stunprotocol.org.
http://www.stunprotocol.org
Apache License 2.0
1.41k stars 347 forks source link

XOR_MAPPED_ADDRESS_OPTIONAL attribute #57

Closed Chaosvex closed 7 months ago

Chaosvex commented 8 months ago

I'm implementing a STUN client and I've been using your server a test endpoint (thanks!). When adhering to RFC3489, I noticed that the server responds with an undocumented XOR_MAPPED_ADDRESS_OPTIONAL attribute, which seemed odd. I found that it comes from an early RFC5780 draft and was made comprehension required in subsequent drafts.

It's not a big deal given that it's comprehension optional but I'd argue that the server should not be sending this attribute at all. This attribute never existed in RFC3489 and any newer client will be using the correct XOR_MAPPED_ADDRESS. I can see that it's used for Vovida compatibility but that appears to be pertinent to the client rather than the server.

I'm not really expecting any change to be made on the back of this issue but for being a stickler for adhering to the standard, I figured I'd present an argument for no longer sending it to legacy clients. I'd happily submit a PR for it.

Thanks again. :)

jselbie commented 8 months ago

Good catch.

As the server is coded now:

I can't remember the clients and servers I tested with back then, but I suspect certain products only understood RFC 3489 and the 0x8020 attribute when this code was first published. I think there might have been a bug fix a while after as well.

My advice would be for your client to be strict in sending RFC 5780 style binding requests, but be prepared to handle RFC 3489 style responses from legacy servers that might still be out there. I think this is as simple as just accepting both 0x8020 and 0x0020 for the XOR Mapped address and falling back to the un-xor'd mapped address if neither is found.

Chaosvex commented 8 months ago

Thanks for the quick response.

My client has a toggle for both RFC3489 and the 5xxx series, which is why I noticed the XOR_..._OPT (and added handling), since it'll pretend it isn't aware of anything that was introduced in later standards (a 'strict' mode, so to speak). I doubt there actually many servers out there that only speak RFC3489 but I figured I'd support it anyway as a sort of 'baseline', since it isn't much more work on my part.

jselbie commented 7 months ago

I doubt there actually many servers out there that only speak RFC3489

Well, the "Vovida" code, I think was just an RFC 3478 server. Which was the only other STUN code base before this repo came along. Look here: https://sourceforge.net/projects/stun/

I'm implementing a STUN client

You are aware that the Stuntman code base has a fully functional client and client message generator/parser, right? I'm not sure if you using C++, but the code is here:

https://github.com/jselbie/stunserver/blob/master/client/clientmain.cpp https://github.com/jselbie/stunserver/blob/master/stuncore/stunclientlogic.cpp