[patch] prev pr patch

pull/185/head
q191201771 3 years ago
parent ae256fafa5
commit b545364ac1

@ -126,7 +126,7 @@ Doc: %s
sm.rtmpServer = rtmp.NewServer(sm.config.RtmpConfig.Addr, sm)
}
if sm.config.RtspConfig.Enable {
sm.rtspServer = rtsp.NewServer(sm.config.RtspConfig.Addr, sm, sm.config.RtspConfig.RtspServerAuthConfig)
sm.rtspServer = rtsp.NewServer(sm.config.RtspConfig.Addr, sm, sm.config.RtspConfig.ServerAuthConfig)
}
if sm.config.HttpApiConfig.Enable {
sm.httpApiServer = NewHttpApiServer(sm.config.HttpApiConfig.Addr, sm)

@ -49,7 +49,7 @@ type IServerObserver interface {
OnDelRtspSubSession(session *SubSession)
}
type RtspServerAuthConfig struct {
type ServerAuthConfig struct {
AuthEnable bool `json:"auth_enable"`
AuthMethod int `json:"auth_method"`
UserName string `json:"username"`
@ -61,10 +61,10 @@ type Server struct {
observer IServerObserver
ln net.Listener
auth RtspServerAuthConfig
auth ServerAuthConfig
}
func NewServer(addr string, observer IServerObserver, auth RtspServerAuthConfig) *Server {
func NewServer(addr string, observer IServerObserver, auth ServerAuthConfig) *Server {
return &Server{
addr: addr,
observer: observer,

@ -55,13 +55,13 @@ type ServerCommandSession struct {
prevConnStat connection.Stat
staleStat *connection.Stat
stat base.StatSession
auth RtspServerAuthConfig
auth ServerAuthConfig
pubSession *PubSession
subSession *SubSession
}
func NewServerCommandSession(observer IServerCommandSessionObserver, conn net.Conn, auth RtspServerAuthConfig) *ServerCommandSession {
func NewServerCommandSession(observer IServerCommandSessionObserver, conn net.Conn, auth ServerAuthConfig) *ServerCommandSession {
uk := base.GenUkRtspServerCommandSession()
s := &ServerCommandSession{
uniqueKey: uk,
@ -291,17 +291,18 @@ func (session *ServerCommandSession) handleDescribe(requestCtx nazahttp.HttpReqM
func (session *ServerCommandSession) handleAuthorized(requestCtx nazahttp.HttpReqMsgCtx) (string, error) {
if requestCtx.Headers.Get(HeaderAuthorization) != "" {
auth_str := requestCtx.Headers.Get(HeaderAuthorization)
if strings.Contains(auth_str, AuthTypeBasic) {
authStr := requestCtx.Headers.Get(HeaderAuthorization)
if strings.Contains(authStr, AuthTypeBasic) {
// Basic 鉴权
auth_base64_client := strings.TrimLeft(auth_str, "Basic ")
authBase64Client := strings.TrimLeft(authStr, "Basic ")
authstr := fmt.Sprintf("%s:%s", session.auth.UserName, session.auth.PassWord)
auth_base64_server := base64.StdEncoding.EncodeToString([]byte(authstr))
if auth_base64_server == auth_base64_client {
authBase64Server := base64.StdEncoding.EncodeToString([]byte(authstr))
if authBase64Server == authBase64Client {
Log.Infof("[%s] Rtsp Basic auth success. uri=%s", session.uniqueKey, requestCtx.Uri)
} else {
err := fmt.Errorf("Rtsp Basic auth failed, auth:%s", auth_base64_client)
// TODO(chef): [refactor] 错误放入base/error.go中 202205
err := fmt.Errorf("rtsp basic auth failed, auth:%s", authBase64Client)
return "", err
}
} else {

Loading…
Cancel
Save