Add rtsp server failed auth logging

This commit is contained in:
Xiaokui Shu
2024-12-25 17:09:23 -05:00
parent 8ecaabfce9
commit 261a936bb8
2 changed files with 14 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package rtsp
import (
"fmt"
"io"
"net"
"net/url"
@@ -237,7 +238,10 @@ func tcpHandler(conn *rtsp.Conn) {
})
if err := conn.Accept(); err != nil {
if err != io.EOF {
if err == rtsp.FailedAuth {
rAddr := conn.Connection.RemoteAddr
log.Warn().Msg(fmt.Sprintf("[rtsp] failed authentication from %s", rAddr))
} else if err != io.EOF {
log.WithLevel(level).Err(err).Caller().Send()
}
if closer != nil {

View File

@@ -13,6 +13,8 @@ import (
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
var FailedAuth = errors.New("failed authentication")
func NewServer(conn net.Conn) *Conn {
return &Conn{
Connection: core.Connection{
@@ -54,7 +56,13 @@ func (c *Conn) Accept() error {
if err = c.WriteResponse(res); err != nil {
return err
}
continue
if req.Header.Get("Authorization") != "" {
// eliminate false positive: ffmpeg sends first request without
// authorization header even if the user provides credentials
return FailedAuth
} else {
continue
}
}
// Receiver: OPTIONS > DESCRIBE > SETUP... > PLAY > TEARDOWN