mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
// +build json
|
|
|
|
package shadowsocks
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
|
"github.com/v2ray/v2ray-core/proxy/internal"
|
|
)
|
|
|
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
|
type JsonConfig struct {
|
|
Cipher *serial.StringLiteral `json:"method"`
|
|
Password *serial.StringLiteral `json:"password"`
|
|
}
|
|
jsonConfig := new(JsonConfig)
|
|
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
|
return err
|
|
}
|
|
if this.Password == nil {
|
|
log.Error("Shadowsocks: Password is not specified.")
|
|
return internal.ErrorBadConfiguration
|
|
}
|
|
this.Password = jsonConfig.Password.String()
|
|
if this.Cipher == nil {
|
|
log.Error("Shadowsocks: Cipher method is not specified.")
|
|
return internal.ErrorBadConfiguration
|
|
}
|
|
jsonConfig.Cipher = jsonConfig.Cipher.ToLower()
|
|
switch jsonConfig.Cipher.String() {
|
|
case "aes-256-cfb":
|
|
this.Cipher = &AesCfb {
|
|
KeyBytes: 32
|
|
}
|
|
case "aes-128-cfb":
|
|
this.Cipher = &AesCfb {
|
|
KeyBytes: 32
|
|
}
|
|
default:
|
|
log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher)
|
|
return internal.ErrorBadConfiguration
|
|
}
|
|
return nil
|
|
}
|