Add rtsp server failed auth logging
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package rtsp
|
package rtsp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -237,7 +238,10 @@ func tcpHandler(conn *rtsp.Conn) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err := conn.Accept(); err != nil {
|
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()
|
log.WithLevel(level).Err(err).Caller().Send()
|
||||||
}
|
}
|
||||||
if closer != nil {
|
if closer != nil {
|
||||||
|
|||||||
+9
-1
@@ -13,6 +13,8 @@ import (
|
|||||||
"github.com/AlexxIT/go2rtc/pkg/tcp"
|
"github.com/AlexxIT/go2rtc/pkg/tcp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var FailedAuth = errors.New("failed authentication")
|
||||||
|
|
||||||
func NewServer(conn net.Conn) *Conn {
|
func NewServer(conn net.Conn) *Conn {
|
||||||
return &Conn{
|
return &Conn{
|
||||||
Connection: core.Connection{
|
Connection: core.Connection{
|
||||||
@@ -54,7 +56,13 @@ func (c *Conn) Accept() error {
|
|||||||
if err = c.WriteResponse(res); err != nil {
|
if err = c.WriteResponse(res); err != nil {
|
||||||
return err
|
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
|
// Receiver: OPTIONS > DESCRIBE > SETUP... > PLAY > TEARDOWN
|
||||||
|
|||||||
Reference in New Issue
Block a user