Browse Source

move VLC authentication hack into gortsplib

pull/707/head
aler9 4 years ago
parent
commit
eab2663420
  1. 2
      go.mod
  2. 4
      go.sum
  3. 2
      internal/core/hls_muxer.go
  4. 18
      internal/core/rtsp_conn.go
  5. 4
      internal/core/rtsp_session.go
  6. 4
      internal/core/rtsp_source_test.go

2
go.mod

@ -5,7 +5,7 @@ go 1.16 @@ -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

4
go.sum

@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo @@ -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=

2
internal/core/hls_muxer.go

@ -408,7 +408,7 @@ func (r *hlsMuxer) handleRequest(req hlsMuxerRequest) hlsMuxerResponse { @@ -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}
}
}

18
internal/core/rtsp_conn.go

@ -90,7 +90,6 @@ func (c *rtspConn) ip() net.IP { @@ -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( @@ -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, @@ -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)
},
})

4
internal/core/rtsp_session.go

@ -130,7 +130,7 @@ func (s *rtspSession) onAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno @@ -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 @@ -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)
},
})

4
internal/core/rtsp_source_test.go

@ -27,7 +27,7 @@ func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, @@ -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) { @@ -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) { @@ -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" +

Loading…
Cancel
Save