From eab2663420b6d990e00fa3f34f2c8187ebf1f4e6 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 30 Oct 2021 15:05:27 +0200 Subject: [PATCH] move VLC authentication hack into gortsplib --- go.mod | 2 +- go.sum | 4 ++-- internal/core/hls_muxer.go | 2 +- internal/core/rtsp_conn.go | 18 ++---------------- internal/core/rtsp_session.go | 4 ++-- internal/core/rtsp_source_test.go | 4 +++- 6 files changed, 11 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 12a0ce2c..ca024da8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/aler9/gortsplib v0.0.0-20211030115237-146b923b1e86 + github.com/aler9/gortsplib v0.0.0-20211030125802-b5f1d7ccb6bc github.com/asticode/go-astits v1.10.0 github.com/fsnotify/fsnotify v1.4.9 github.com/gin-gonic/gin v1.7.2 diff --git a/go.sum b/go.sum index c85a0ad1..d6222284 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aler9/gortsplib v0.0.0-20211030115237-146b923b1e86 h1:AZlReUgswHsQGIzz9w9Bc52U184kOqPOlfa3ReR5R+4= -github.com/aler9/gortsplib v0.0.0-20211030115237-146b923b1e86/go.mod h1:fyQrQyHo8QvdR/h357tkv1g36VesZlzEPsdAu2VrHHc= +github.com/aler9/gortsplib v0.0.0-20211030125802-b5f1d7ccb6bc h1:GgJgZW0o1AKBfVVnp8XI2Pk7IsySn1VmzySaWw8FtqQ= +github.com/aler9/gortsplib v0.0.0-20211030125802-b5f1d7ccb6bc/go.mod h1:fyQrQyHo8QvdR/h357tkv1g36VesZlzEPsdAu2VrHHc= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc= github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8= diff --git a/internal/core/hls_muxer.go b/internal/core/hls_muxer.go index d413c3d4..59e93133 100644 --- a/internal/core/hls_muxer.go +++ b/internal/core/hls_muxer.go @@ -408,7 +408,7 @@ func (r *hlsMuxer) handleRequest(req hlsMuxerRequest) hlsMuxerResponse { tmp, _, _ := net.SplitHostPort(req.Req.RemoteAddr) ip := net.ParseIP(tmp) if !ipEqualOrInRange(ip, conf.ReadIPs) { - r.log(logger.Info, "ERR: ip '%s' not allowed", ip) + r.log(logger.Info, "ip '%s' not allowed", ip) return hlsMuxerResponse{Status: http.StatusUnauthorized} } } diff --git a/internal/core/rtsp_conn.go b/internal/core/rtsp_conn.go index 83f6377a..4e742970 100644 --- a/internal/core/rtsp_conn.go +++ b/internal/core/rtsp_conn.go @@ -90,7 +90,6 @@ func (c *rtspConn) ip() net.IP { func (c *rtspConn) validateCredentials( pathUser conf.Credential, pathPass conf.Credential, - pathName string, req *base.Request, ) error { // reset authValidator every time the credentials change @@ -100,20 +99,7 @@ func (c *rtspConn) validateCredentials( c.authValidator = auth.NewValidator(string(pathUser), string(pathPass), c.authMethods) } - // VLC strips the control attribute - // provide an alternative URL without the control attribute - altURL := func() *base.URL { - if req.Method != base.Setup { - return nil - } - return &base.URL{ - Scheme: req.URL.Scheme, - Host: req.URL.Host, - Path: "/" + pathName + "/", - } - }() - - err := c.authValidator.ValidateRequest(req, altURL) + err := c.authValidator.ValidateRequest(req) if err != nil { c.authFailures++ @@ -180,7 +166,7 @@ func (c *rtspConn) onDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, URL: ctx.Req.URL, IP: c.ip(), ValidateCredentials: func(pathUser conf.Credential, pathPass conf.Credential) error { - return c.validateCredentials(pathUser, pathPass, ctx.Path, ctx.Req) + return c.validateCredentials(pathUser, pathPass, ctx.Req) }, }) diff --git a/internal/core/rtsp_session.go b/internal/core/rtsp_session.go index ad959599..3e696112 100644 --- a/internal/core/rtsp_session.go +++ b/internal/core/rtsp_session.go @@ -130,7 +130,7 @@ func (s *rtspSession) onAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno PathName: ctx.Path, IP: ctx.Conn.NetConn().RemoteAddr().(*net.TCPAddr).IP, ValidateCredentials: func(pathUser conf.Credential, pathPass conf.Credential) error { - return c.validateCredentials(pathUser, pathPass, ctx.Path, ctx.Req) + return c.validateCredentials(pathUser, pathPass, ctx.Req) }, }) @@ -186,7 +186,7 @@ func (s *rtspSession) onSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt PathName: ctx.Path, IP: ctx.Conn.NetConn().RemoteAddr().(*net.TCPAddr).IP, ValidateCredentials: func(pathUser conf.Credential, pathPass conf.Credential) error { - return c.validateCredentials(pathUser, pathPass, ctx.Path, ctx.Req) + return c.validateCredentials(pathUser, pathPass, ctx.Req) }, }) diff --git a/internal/core/rtsp_source_test.go b/internal/core/rtsp_source_test.go index 15900b12..5e0b8580 100644 --- a/internal/core/rtsp_source_test.go +++ b/internal/core/rtsp_source_test.go @@ -27,7 +27,7 @@ func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, sh.authValidator = auth.NewValidator(sh.user, sh.pass, nil) } - err := sh.authValidator.ValidateRequest(ctx.Req, nil) + err := sh.authValidator.ValidateRequest(ctx.Req) if err != nil { return &base.Response{ StatusCode: base.StatusUnauthorized, @@ -100,6 +100,7 @@ func TestRTSPSource(t *testing.T) { err := s.Start("127.0.0.1:8555") require.NoError(t, err) + defer s.Wait() defer s.Close() if source == "udp" || source == "tcp" { @@ -149,6 +150,7 @@ func TestRTSPSourceNoPassword(t *testing.T) { s := gortsplib.Server{Handler: &testServer{user: "testuser", done: done}} err := s.Start("127.0.0.1:8555") require.NoError(t, err) + defer s.Wait() defer s.Close() p, ok := newInstance("rtmpDisable: yes\n" +