Projects STRLCPY sing-box Commits fe4b429f
🤬
  • hysteria: Accept inbound configuration without users

  • Loading...
  • 世界 committed 1 year ago
    fe4b429f
    1 parent f680d0ac
  • ■ ■ ■ ■ ■ ■
    docs/configuration/inbound/hysteria.md
    skipped 73 lines
    74 74   
    75 75  #### users.auth
    76 76   
    77  -==Required if `auth_str` is empty==
    78  - 
    79 77  Authentication password, in base64.
    80 78   
    81 79  #### users.auth_str
    82  - 
    83  -==Required if `auth` is empty==
    84 80   
    85 81  Authentication password.
    86 82   
    skipped 29 lines
  • ■ ■ ■ ■ ■ ■
    docs/configuration/inbound/hysteria.zh.md
    skipped 73 lines
    74 74   
    75 75  #### users.auth
    76 76   
    77  -==与 auth_str 必填一个==
    78  - 
    79 77  base64 编码的认证密码。
    80 78   
    81 79  #### users.auth_str
    82  - 
    83  -==与 auth 必填一个==
    84 80   
    85 81  认证密码。
    86 82   
    skipped 29 lines
  • ■ ■ ■ ■ ■ ■
    inbound/hysteria.go
    skipped 186 lines
    187 187   if err != nil {
    188 188   return err
    189 189   }
    190  - userIndex := slices.Index(h.authKey, string(clientHello.Auth))
    191  - if userIndex == -1 {
    192  - err = hysteria.WriteServerHello(controlStream, hysteria.ServerHello{
    193  - Message: "wrong password",
    194  - })
    195  - return E.Errors(E.New("wrong password: ", string(clientHello.Auth)), err)
    196  - }
    197  - user := h.authUser[userIndex]
    198  - if user == "" {
    199  - user = F.ToString(userIndex)
     190 + if len(h.authKey) > 0 {
     191 + userIndex := slices.Index(h.authKey, string(clientHello.Auth))
     192 + if userIndex == -1 {
     193 + err = hysteria.WriteServerHello(controlStream, hysteria.ServerHello{
     194 + Message: "wrong password",
     195 + })
     196 + return E.Errors(E.New("wrong password: ", string(clientHello.Auth)), err)
     197 + }
     198 + user := h.authUser[userIndex]
     199 + if user == "" {
     200 + user = F.ToString(userIndex)
     201 + } else {
     202 + ctx = auth.ContextWithUser(ctx, user)
     203 + }
     204 + h.logger.InfoContext(ctx, "[", user, "] inbound connection from ", conn.RemoteAddr())
    200 205   } else {
    201  - ctx = auth.ContextWithUser(ctx, user)
     206 + h.logger.InfoContext(ctx, "inbound connection from ", conn.RemoteAddr())
    202 207   }
    203  - h.logger.InfoContext(ctx, "[", user, "] inbound connection from ", conn.RemoteAddr())
    204 208   h.logger.DebugContext(ctx, "peer send speed: ", clientHello.SendBPS/1024/1024, " MBps, peer recv speed: ", clientHello.RecvBPS/1024/1024, " MBps")
    205 209   if clientHello.SendBPS == 0 || clientHello.RecvBPS == 0 {
    206 210   return E.New("invalid rate from client")
    skipped 129 lines
Please wait...
Page is in error, reload to recover