Skip to content

BadFormat for message/cookie error (CLASSIC-STUN) #444

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

Open
ispysoftware opened this issue Feb 23, 2025 · 4 comments
Open

BadFormat for message/cookie error (CLASSIC-STUN) #444

ispysoftware opened this issue Feb 23, 2025 · 4 comments

Comments

@ispysoftware
Copy link

I know i'm missing something obvious here. The examples seem to demonstrate setting this up as STUN or TURN. TURN should also support STUN right?

When I run it as a TURN server and test it from stun client (on ubuntu) I get errors like

OnTurnServerOutput: turn ERROR: 2025/02/23 10:27:36 Failed to handle datagram: failed to create stun message from packet: BadFormat for message/cookie: 1c0265f is invalid magic cookie (should be 2112a442)
OnTurnServerOutput: turn ERROR: 2025/02/23 10:27:36 Failed to handle datagram: failed to create stun message from packet: BadFormat for message/cookie: 203e909 is invalid magic cookie (should be 2112a442)
OnTurnServerOutput: turn ERROR: 2025/02/23 10:27:36 Failed to handle datagram: failed to create stun message from packet: BadFormat for message/cookie: 3c0a820 is invalid magic cookie (should be 2112a442)
OnTurnServerOutput: turn ERROR: 2025/02/23 10:27:36 Failed to handle datagram: failed to create stun message from packet: BadFormat for message/cookie: 19c1239 is invalid magic cookie (should be 2112a442)

Do I need to do anything special to support both? Is the AuthHandler being called for Binding requests?

 server, err := turn.NewServer(turn.ServerConfig{
     Realm: *realm,
     AuthHandler: func(username, realm string, srcAddr net.Addr) ([]byte, bool) {
         userSuffix, valid := validateUsername(username)
         if !valid {
             log.Println("Auth failed; invalid username:", username)
             return nil, false
         }
         expectedPassword := generateTURNPassword(username, realm, *staticAuthSecret)
         key := turn.GenerateAuthKey(username, realm, expectedPassword)
         log.Printf("Auth succeeded for user: %s (suffix=%s)", username, userSuffix)
         return key, true
     },
     PacketConnConfigs: packetConfigs,
     ListenerConfigs:   listenerConfigs,
 })
@Sean-Der
Copy link
Member

It should work by default! The STUN packets are responded too automatically.

That error message is suggesting we aren't actually getting a STUN packet. Could you do wireshark/tcpdump and see if the TURN server is wrong?

@ispysoftware
Copy link
Author

ispysoftware commented Feb 23, 2025

Thanks for responding.
Wireshark is detecting this as CLASSIC-STUN. I'm wondering if pion supports that or not? When i try the ubuntu stun test client on googles stun servers it seems to work ok.

I'm getting the same error reports from deployed pion turn servers but they say "Failed to handle datagram: failed to create stun message from packet: BadFormat for message/cookie: 0 is invalid magic cookie (should be 2112a442)"

I think some clients are probably using some older STUN version.
Packet capture attached.

pcap.zip

edit: had a report that chrome on windows 10 is also causing this issue
chrome on win 11 seems ok.

@ispysoftware ispysoftware changed the title support STUN and TURN BadFormat for message/cookie error Feb 23, 2025
@ispysoftware ispysoftware changed the title BadFormat for message/cookie error BadFormat for message/cookie error (CLASSIC-STUN) Feb 23, 2025
@ispysoftware
Copy link
Author

ispysoftware commented Feb 24, 2025

OK it looks like i've run into

Compatability notes
RFC 5389 obsoletes RFC 3489, so implementation was ignored by purpose, however, RFC 3489 can be easily implemented as separate package.

This is a bit of a show-stopper if windows 10 clients and linux clients are still using that RFC and it completely breaks the functionality of this library.

@hpmkruit
Copy link

Source of the reported issue here. Let me know if i can test something or provide with extra info.

I have been using win 10 on server side and chrome client on desktop and mobile and been getting these issues

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

No branches or pull requests

3 participants