public override IList <IAdapterConfig> ReadJson(JsonReader reader, Type objectType, IList <IAdapterConfig> existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            var jsonList = JArray.Load(reader);
            var objList  = new List <IAdapterConfig>(jsonList.Count);

            foreach (var json in jsonList)
            {
                var jsonReader  = json.CreateReader();
                var adapterType = json[nameof(IAdapterConfig.AdapterType)].Value <string>();
                switch (adapterType)
                {
                case "shadowsocks":
                    var ss = new ShadowsocksConfig();
                    serializer.Populate(jsonReader, ss);
                    objList.Add(ss);
                    break;

                case "http":
                    var http = new HttpConfig();
                    serializer.Populate(jsonReader, http);
                    objList.Add(http);
                    break;

                case "trojan":
                    var trojan = new TrojanConfig();
                    serializer.Populate(jsonReader, trojan);
                    objList.Add(trojan);
                    break;
                }
            }
            return(objList);
        }
Esempio n. 2
0
        public ShadowsocksFactory(ShadowsocksConfig config)
        {
            this.config = config;
            serviceName = config.ServerPort.ToString();
            var lowerMethod = config.Method.ToLower();

            if (lowerMethod.EndsWith("gcm") || lowerMethod.EndsWith("poly1305"))
            {
                isAead = true;
            }
            GlobalCryptorFactory = CryptorFactory = CryptorFactory.CreateFactory(config.Method, Encoding.UTF8.GetBytes(config.Password));
        }
        public JsonConfig()
        {
            config            = new List <Config>();
            versions          = new List <string>();
            autorun           = new Autorun();
            shadowsocksConfig = new ShadowsocksConfig();

            shadowsocksPath = null;
            autorunEnabled  = false;
            autoStartup     = false;
            //pacUrl = new PacUrl();
        }
Esempio n. 4
0
        private static string ShadowsocksConfigEncoder(ShadowsocksConfig config)
        {
            string tag           = string.Empty;
            var    parts         = $"{config.Method}:{config.Password}";
            var    base64        = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
            var    websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('=');
            var    plugin        = "";
            var    url           = $"{websafeBase64}@{config.ServerHost}:{config.ServerPort}/?plugin={WebUtility.UrlEncode(plugin)}";

            if (!string.IsNullOrEmpty(config.Name))
            {
                tag = $"#{WebUtility.UrlEncode(config.Name)}";
            }
            return($"ss://{url}{tag}");
        }
Esempio n. 5
0
        public Config()
        {
            websites          = new List <Website>();
            plaintexts        = new List <PlainText>();
            qrCodes           = new List <QRCode>();
            statics           = new List <Server>();
            versions          = new List <string>();
            autorun           = new Autorun();
            shadowsocksConfig = new ShadowsocksConfig();

            shadowsocksPath = null;
            autorunEnabled  = false;
            autoStartup     = false;
            pacUrl          = new PacUrl();
        }
Esempio n. 6
0
 public ShadowsocksFactory(ShadowsocksConfig config)
 {
     this.config    = config;
     cryptorFactory = new CryptorFactory(config.Method, Encoding.UTF8.GetBytes(config.Password));
 }