2022-09-17 19:19:45 +00:00
|
|
|
// Package handshake contains the RTMP handshake mechanism.
|
2022-07-16 13:18:04 +00:00
|
|
|
package handshake
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DoClient performs a client-side handshake.
|
2022-07-17 13:17:18 +00:00
|
|
|
func DoClient(rw io.ReadWriter, validateSignature bool) error {
|
2022-07-16 13:18:04 +00:00
|
|
|
err := C0S0{}.Write(rw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c1 := C1S1{}
|
|
|
|
err = c1.Write(rw, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = C0S0{}.Read(rw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s1 := C1S1{}
|
2022-07-17 13:17:18 +00:00
|
|
|
err = s1.Read(rw, false, validateSignature)
|
2022-07-16 13:18:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-17 13:17:18 +00:00
|
|
|
err = (&C2S2{Digest: c1.Digest}).Read(rw, validateSignature)
|
2022-07-16 13:18:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = C2S2{Digest: s1.Digest}.Write(rw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DoServer performs a server-side handshake.
|
2022-07-17 13:17:18 +00:00
|
|
|
func DoServer(rw io.ReadWriter, validateSignature bool) error {
|
2022-07-16 13:18:04 +00:00
|
|
|
err := C0S0{}.Read(rw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c1 := C1S1{}
|
2022-07-17 13:17:18 +00:00
|
|
|
err = c1.Read(rw, true, validateSignature)
|
2022-07-16 13:18:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = C0S0{}.Write(rw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s1 := C1S1{}
|
|
|
|
err = s1.Write(rw, false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = C2S2{Digest: c1.Digest}.Write(rw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-17 13:17:18 +00:00
|
|
|
err = (&C2S2{Digest: s1.Digest}).Read(rw, validateSignature)
|
2022-07-16 13:18:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|