Skip to content

Commit

Permalink
Add rtsp server failed auth logging
Browse files Browse the repository at this point in the history
  • Loading branch information
subbyte committed Dec 25, 2024
1 parent 8ecaabf commit 6057062
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/rtsp/rtsp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rtsp

import (
"fmt"
"io"
"net"
"net/url"
Expand Down Expand Up @@ -237,7 +238,10 @@ func tcpHandler(conn *rtsp.Conn) {
})

if err := conn.Accept(); err != nil {
if err != io.EOF {
if err == rtsp.AuthFailed {
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 {
Expand Down
10 changes: 9 additions & 1 deletion pkg/rtsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/AlexxIT/go2rtc/pkg/tcp"
)

var AuthFailed = errors.New("failed authentication")

func NewServer(conn net.Conn) *Conn {
return &Conn{
Connection: core.Connection{
Expand Down Expand Up @@ -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 AuthFailed
} else {
continue
}
}

// Receiver: OPTIONS > DESCRIBE > SETUP... > PLAY > TEARDOWN
Expand Down

0 comments on commit 6057062

Please sign in to comment.