diff --git a/pkg/rtsp/conn.go b/pkg/rtsp/conn.go index 727c433a..6b96a1e0 100644 --- a/pkg/rtsp/conn.go +++ b/pkg/rtsp/conn.go @@ -220,12 +220,15 @@ func (c *Conn) Do(req *tcp.Request) (*tcp.Response, error) { if res.StatusCode == http.StatusUnauthorized { switch c.auth.Method { case tcp.AuthNone: + if c.auth.ReadNone(res) { + return c.Do(req) + } return nil, errors.New("user/pass not provided") case tcp.AuthUnknown: if c.auth.Read(res) { return c.Do(req) } - case tcp.AuthBasic, tcp.AuthDigest: + default: return nil, errors.New("wrong user/pass") } } diff --git a/pkg/tcp/auth.go b/pkg/tcp/auth.go index ec47998a..ac212fcf 100644 --- a/pkg/tcp/auth.go +++ b/pkg/tcp/auth.go @@ -22,6 +22,7 @@ const ( AuthUnknown AuthBasic AuthDigest + AuthTPLink // https://drmnsamoliu.github.io/video.html ) func NewAuth(user *url.Userinfo) *Auth { @@ -79,6 +80,8 @@ func (a *Auth) Write(req *Request) { `, uri="%s", response="%s"`, uri, response, ) req.Header.Set("Authorization", header) + case AuthTPLink: + req.URL.Host = "127.0.0.1" } } @@ -100,6 +103,15 @@ func (a *Auth) Validate(req *Request) bool { return header == a.header } +func (a *Auth) ReadNone(res *Response) bool { + auth := res.Header.Get("WWW-Authenticate") + if strings.Contains(auth, "TP-LINK Streaming Media") { + a.Method = AuthTPLink + return true + } + return false +} + func Between(s, sub1, sub2 string) string { i := strings.Index(s, sub1) if i < 0 {