rtmp server: fix handshake and compatibility with streamlabs (#1244) (#1398)

This commit is contained in:
Alessandro Ros 2023-01-19 16:03:48 +01:00 committed by GitHub
parent c79c3c83cb
commit e3d00878b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -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 {

View File

@ -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
}