瀏覽代碼

Server side OTA settings in shadowsocks

Darien Raymond 9 年之前
父節點
當前提交
470e35849f
共有 2 個文件被更改,包括 25 次插入1 次删除
  1. 17 1
      proxy/shadowsocks/protocol.go
  2. 8 0
      tools/conf/shadowsocks.go

+ 17 - 1
proxy/shadowsocks/protocol.go

@@ -56,7 +56,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
 	lenBuffer := 1
 	_, err = io.ReadFull(reader, buffer.Value[:1])
 	if err != nil {
-		return nil, nil, errors.New("Sahdowsocks|TCP: Failed to read address type: " + err.Error())
+		return nil, nil, errors.New("Shadowsocks|TCP: Failed to read address type: " + err.Error())
 	}
 
 	addrType := (buffer.Value[0] & 0x0F)
@@ -64,6 +64,14 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
 		request.Option |= RequestOptionOneTimeAuth
 	}
 
+	if request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Disabled {
+		return nil, nil, errors.New("Shadowsocks|TCP: Rejecting connection with OTA enabled, while server disables OTA.")
+	}
+
+	if !request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Enabled {
+		return nil, nil, errors.New("Shadowsocks|TCP: Rejecting connection with OTA disabled, while server enables OTA.")
+	}
+
 	switch addrType {
 	case AddrTypeIPv4:
 		_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+4])
@@ -308,6 +316,14 @@ func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.Requ
 		request.Option |= RequestOptionOneTimeAuth
 	}
 
+	if request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Disabled {
+		return nil, nil, errors.New("Shadowsocks|UDP: Rejecting packet with OTA enabled, while server disables OTA.")
+	}
+
+	if !request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Enabled {
+		return nil, nil, errors.New("Shadowsocks|UDP: Rejecting packet with OTA disabled, while server enables OTA.")
+	}
+
 	if request.Option.Has(RequestOptionOneTimeAuth) {
 		payloadLen := payload.Len() - AuthSize
 		authBytes := payload.Value[payloadLen:]

+ 8 - 0
tools/conf/shadowsocks.go

@@ -15,6 +15,7 @@ type ShadowsocksServerConfig struct {
 	UDP      bool   `json:"udp"`
 	Level    byte   `json:"level"`
 	Email    string `json:"email"`
+	OTA      *bool  `json:"ota"`
 }
 
 func (this *ShadowsocksServerConfig) Build() (*loader.TypedSettings, error) {
@@ -28,6 +29,13 @@ func (this *ShadowsocksServerConfig) Build() (*loader.TypedSettings, error) {
 		Password: this.Password,
 		Ota:      shadowsocks.Account_Auto,
 	}
+	if this.OTA != nil {
+		if *this.OTA {
+			account.Ota = shadowsocks.Account_Enabled
+		} else {
+			account.Ota = shadowsocks.Account_Disabled
+		}
+	}
 	cipher := strings.ToLower(this.Cipher)
 	switch cipher {
 	case "aes-256-cfb":