コード例 #1
0
ファイル: config_json.go プロジェクト: DZLZHCODE/v2ray-core
func (this *Config) UnmarshalJSON(data []byte) error {
	type JsonConfig struct {
		Cipher   string `json:"method"`
		Password string `json:"password"`
		UDP      bool   `json:"udp"`
		Level    byte   `json:"level"`
		Email    string `json:"email"`
	}
	jsonConfig := new(JsonConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return errors.New("Shadowsocks: Failed to parse config: " + err.Error())
	}

	this.UDP = jsonConfig.UDP
	jsonConfig.Cipher = strings.ToLower(jsonConfig.Cipher)
	switch jsonConfig.Cipher {
	case "aes-256-cfb":
		this.Cipher = &AesCfb{
			KeyBytes: 32,
		}
	case "aes-128-cfb":
		this.Cipher = &AesCfb{
			KeyBytes: 16,
		}
	case "chacha20":
		this.Cipher = &ChaCha20{
			IVBytes: 8,
		}
	case "chacha20-ietf":
		this.Cipher = &ChaCha20{
			IVBytes: 12,
		}
	default:
		log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher)
		return common.ErrBadConfiguration
	}

	if len(jsonConfig.Password) == 0 {
		log.Error("Shadowsocks: Password is not specified.")
		return common.ErrBadConfiguration
	}
	this.Key = PasswordToCipherKey(jsonConfig.Password, this.Cipher.KeySize())

	this.Level = protocol.UserLevel(jsonConfig.Level)
	this.Email = jsonConfig.Email

	return nil
}
コード例 #2
0
ファイル: config_json.go プロジェクト: DZLZHCODE/v2ray-core
func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
	type JsonDefaultConfig struct {
		AlterIDs uint16 `json:"alterId"`
		Level    byte   `json:"level"`
	}
	jsonConfig := new(JsonDefaultConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return errors.New("VMessIn: Failed to parse default config: " + err.Error())
	}
	this.AlterIDs = jsonConfig.AlterIDs
	if this.AlterIDs == 0 {
		this.AlterIDs = 32
	}
	this.Level = protocol.UserLevel(jsonConfig.Level)
	return nil
}
コード例 #3
0
ファイル: config_json.go プロジェクト: DZLZHCODE/v2ray-core
func (this *Config) UnmarshalJSON(data []byte) error {
	type JsonConfig struct {
		Users        []json.RawMessage `json:"clients"`
		Features     *FeaturesConfig   `json:"features"`
		Defaults     *DefaultConfig    `json:"default"`
		DetourConfig *DetourConfig     `json:"detour"`
	}
	jsonConfig := new(JsonConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return errors.New("VMessIn: Failed to parse config: " + err.Error())
	}
	this.Features = jsonConfig.Features // Backward compatibility
	this.Defaults = jsonConfig.Defaults
	if this.Defaults == nil {
		this.Defaults = &DefaultConfig{
			Level:    protocol.UserLevel(0),
			AlterIDs: 32,
		}
	}
	this.DetourConfig = jsonConfig.DetourConfig
	// Backward compatibility
	if this.Features != nil && this.DetourConfig == nil {
		this.DetourConfig = this.Features.Detour
	}
	this.AllowedUsers = make([]*protocol.User, len(jsonConfig.Users))
	for idx, rawData := range jsonConfig.Users {
		user := new(protocol.User)
		if err := json.Unmarshal(rawData, user); err != nil {
			return errors.New("VMess|Inbound: Invalid user: "******"VMess|Inbound: Invalid user: " + err.Error())
		}
		user.Account = account
		this.AllowedUsers[idx] = user
	}

	return nil
}
コード例 #4
0
ファイル: commands.go プロジェクト: DZLZHCODE/v2ray-core
func (this *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
	cmd := new(protocol.CommandSwitchAccount)
	if len(data) == 0 {
		return nil, transport.ErrCorruptedPacket
	}
	lenHost := int(data[0])
	if len(data) < lenHost+1 {
		return nil, transport.ErrCorruptedPacket
	}
	if lenHost > 0 {
		cmd.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
	}
	portStart := 1 + lenHost
	if len(data) < portStart+2 {
		return nil, transport.ErrCorruptedPacket
	}
	cmd.Port = v2net.PortFromBytes(data[portStart : portStart+2])
	idStart := portStart + 2
	if len(data) < idStart+16 {
		return nil, transport.ErrCorruptedPacket
	}
	cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
	alterIdStart := idStart + 16
	if len(data) < alterIdStart+2 {
		return nil, transport.ErrCorruptedPacket
	}
	cmd.AlterIds = serial.BytesToUint16(data[alterIdStart : alterIdStart+2])
	levelStart := alterIdStart + 2
	if len(data) < levelStart+1 {
		return nil, transport.ErrCorruptedPacket
	}
	cmd.Level = protocol.UserLevel(data[levelStart])
	timeStart := levelStart + 1
	if len(data) < timeStart {
		return nil, transport.ErrCorruptedPacket
	}
	cmd.ValidMin = data[timeStart]
	return cmd, nil
}