Skip to content

Commit

Permalink
rtmp server: fix handshake and compatibility with streamlabs (#1244) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Jan 19, 2023
1 parent c79c3c8 commit e3d0087
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 1 addition & 6 deletions internal/rtmp/handshake/c2s2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handshake

import (
"bytes"
"crypto/rand"
"fmt"
"io"
)
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 13 additions & 3 deletions internal/rtmp/handshake/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e3d0087

Please sign in to comment.