From e3d00878b3572aebe5024d7aa10c1512d1c63354 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Thu, 19 Jan 2023 16:03:48 +0100 Subject: [PATCH] rtmp server: fix handshake and compatibility with streamlabs (#1244) (#1398) --- internal/rtmp/handshake/c2s2.go | 7 +------ internal/rtmp/handshake/handshake.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/rtmp/handshake/c2s2.go b/internal/rtmp/handshake/c2s2.go index 639458becc2..31f0c24c0c0 100644 --- a/internal/rtmp/handshake/c2s2.go +++ b/internal/rtmp/handshake/c2s2.go @@ -2,7 +2,6 @@ package handshake import ( "bytes" - "crypto/rand" "fmt" "io" ) @@ -51,11 +50,7 @@ func (c C2S2) Write(w io.Writer) error { buf[6] = byte(c.Time2 >> 8) buf[7] = byte(c.Time2) - if c.Random == nil { - rand.Read(buf[8:]) - } else { - copy(buf[8:], c.Random) - } + copy(buf[8:], c.Random) // signature if c.Digest != nil { diff --git a/internal/rtmp/handshake/handshake.go b/internal/rtmp/handshake/handshake.go index a1a068e387b..95225b02578 100644 --- a/internal/rtmp/handshake/handshake.go +++ b/internal/rtmp/handshake/handshake.go @@ -29,12 +29,18 @@ func DoClient(rw io.ReadWriter, validateSignature bool) error { return err } - err = (&C2S2{Digest: c1.Digest}).Read(rw, validateSignature) + err = (&C2S2{ + Digest: c1.Digest, + }).Read(rw, validateSignature) if err != nil { return err } - err = C2S2{Digest: s1.Digest}.Write(rw) + err = C2S2{ + Time: s1.Time, + Random: s1.Random, + Digest: s1.Digest, + }.Write(rw) if err != nil { return err } @@ -66,7 +72,11 @@ func DoServer(rw io.ReadWriter, validateSignature bool) error { return err } - err = C2S2{Digest: c1.Digest}.Write(rw) + err = C2S2{ + Time: c1.Time, + Random: c1.Random, + Digest: c1.Digest, + }.Write(rw) if err != nil { return err }