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

Handshake fails for certain RTMP clients #12

Closed
clone1018 opened this issue May 16, 2022 · 5 comments
Closed

Handshake fails for certain RTMP clients #12

clone1018 opened this issue May 16, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@clone1018
Copy link
Member

clone1018 commented May 16, 2022

Seems for some reason the handshake does not shake successfully with restream, so connecting does not work.

Server closed by error: Err = Random echo is not matched
github.com/yutopp/go-rtmp/handshake.HandshakeWithClient
	/root/go/pkg/mod/github.com/yutopp/go-rtmp@v0.0.1/handshake/handshake.go:102
github.com/yutopp/go-rtmp.(*serverConn).Serve
	/root/go/pkg/mod/github.com/yutopp/go-rtmp@v0.0.1/server_conn.go:28
github.com/yutopp/go-rtmp.(*Server).handleConn
	/root/go/pkg/mod/github.com/yutopp/go-rtmp@v0.0.1/server.go:115
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1581

Failed to handshake
github.com/yutopp/go-rtmp.(*serverConn).Serve
	/root/go/pkg/mod/github.com/yutopp/go-rtmp@v0.0.1/server_conn.go:31
github.com/yutopp/go-rtmp.(*Server).handleConn
	/root/go/pkg/mod/github.com/yutopp/go-rtmp@v0.0.1/server.go:115
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1581

The primary example of this is restream.io

@clone1018 clone1018 added the bug Something isn't working label May 16, 2022
@clone1018
Copy link
Member Author

Seems owncast had the same issue: owncast/owncast#34

@clone1018
Copy link
Member Author

Need to look into if they maintain a fork of the RTMP library we should be using instead!

@clone1018 clone1018 changed the title Cannot use with Restream.io Handshake fails for certain RTMP clients May 19, 2022
@clone1018
Copy link
Member Author

Here's some quick code to do a basic RTMP handshake (and send an invalid one for testing):

package main

import (
	"bufio"
	"crypto/rand"
	"fmt"
	"io"
	"net"
)

func main() {
	token := make([]byte, 1536)
	rand.Read(token)

	wrongResponse := make([]byte, 1536)
	rand.Read(wrongResponse)

	conn, err := net.Dial("tcp", "localhost:1935")
	if err != nil {
		panic(err)
	}
	reader := bufio.NewReader(conn)

	// Write 0x03 and token
	conn.Write([]byte{0x03})
	conn.Write(token)

	// Check status response
	status := make([]byte, 1)
	_, err = reader.Read(status)
	if err != nil {
		panic(err)
	}
	fmt.Printf("First Res: %#v\n", status)

	// Generate handshake
	handshake := make([]byte, 1536)
	_, err = io.ReadFull(conn, handshake)
	if err != nil {
		panic(err)
	}
	conn.Write(handshake)
	// Uncomment this if you want the handshake to fail
	// conn.Write(wrongResponse)
	_, err = reader.Read(status)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Second Res: %#v\n", status)
}

@clone1018
Copy link
Member Author

Forked go-rtmp so I could add in lal's handshake code. Seems to be working but will need to actually test.

@clone1018
Copy link
Member Author

That fixed it it seems, there were two issues:

  1. Digest handshake was not implemented. Glimesh/go-rtmp@a33e29d
  2. Publishing Type is sometimes missing from certain services, I made a patch to go-rtmp to default to live (it is a live streaming server after all). Glimesh/go-rtmp@4f0095b#diff-985ac45622f50b5032960af0abd0cca4e5b9bd93ee9b1d76c72093de0d0cd8b5R205-R207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant