示例#1
0
文件: Utils.cs 项目: onfork/x2tap
            public static Objects.Server.ShadowsocksR ShadowsocksR(string text)
            {
                var data         = UrlSafeBase64Decode(text.Remove(0, 6)).Split(':');
                var shadowsocksr = new Objects.Server.ShadowsocksR();

                shadowsocksr.Address = data[0];
                shadowsocksr.Port    = int.Parse(data[1]);

                switch (data[2])
                {
                case "origin":
                    shadowsocksr.Protocol = 0;
                    break;

                case "auth_sha1_v4":
                    shadowsocksr.Protocol = 1;
                    break;

                case "auth_aes128_sha1":
                    shadowsocksr.Protocol = 2;
                    break;

                case "auth_aes128_md5":
                    shadowsocksr.Protocol = 3;
                    break;

                case "auth_chain_a":
                    shadowsocksr.Protocol = 4;
                    break;

                case "auth_chain_b":
                    shadowsocksr.Protocol = 5;
                    break;

                case "auth_chain_c":
                    shadowsocksr.Protocol = 6;
                    break;

                case "auth_chain_d":
                    shadowsocksr.Protocol = 7;
                    break;

                case "auth_chain_e":
                    shadowsocksr.Protocol = 8;
                    break;

                case "auth_chain_f":
                    shadowsocksr.Protocol = 9;
                    break;

                default:
                    throw new NotSupportedException(String.Format("不支持的协议:{0}", data[2]));
                }

                switch (data[3])
                {
                case "none":
                    shadowsocksr.EncryptMethod = 0;
                    break;

                case "table":
                    shadowsocksr.EncryptMethod = 1;
                    break;

                case "rc4":
                    shadowsocksr.EncryptMethod = 2;
                    break;

                case "rc4-md5":
                    shadowsocksr.EncryptMethod = 3;
                    break;

                case "rc4-md5-6":
                    shadowsocksr.EncryptMethod = 4;
                    break;

                case "aes-128-cfb":
                    shadowsocksr.EncryptMethod = 5;
                    break;

                case "aes-192-cfb":
                    shadowsocksr.EncryptMethod = 6;
                    break;

                case "aes-256-cfb":
                    shadowsocksr.EncryptMethod = 7;
                    break;

                case "aes-128-ctr":
                    shadowsocksr.EncryptMethod = 8;
                    break;

                case "aes-192-ctr":
                    shadowsocksr.EncryptMethod = 9;
                    break;

                case "aes-256-ctr":
                    shadowsocksr.EncryptMethod = 10;
                    break;

                case "bf-cfb":
                    shadowsocksr.EncryptMethod = 11;
                    break;

                case "camellia-128-cfb":
                    shadowsocksr.EncryptMethod = 12;
                    break;

                case "camellia-192-cfb":
                    shadowsocksr.EncryptMethod = 13;
                    break;

                case "camellia-256-cfb":
                    shadowsocksr.EncryptMethod = 14;
                    break;

                case "salsa20":
                    shadowsocksr.EncryptMethod = 15;
                    break;

                case "chacha20":
                    shadowsocksr.EncryptMethod = 16;
                    break;

                case "chacha20-ietf":
                    shadowsocksr.EncryptMethod = 17;
                    break;

                default:
                    throw new NotSupportedException(String.Format("不支持的加密方式:{0}", data[3]));
                }

                switch (data[4])
                {
                case "plain":
                    shadowsocksr.OBFS = 0;
                    break;

                case "http_simple":
                    shadowsocksr.OBFS = 1;
                    break;

                case "http_post":
                    shadowsocksr.OBFS = 2;
                    break;

                case "http_mix":
                    shadowsocksr.OBFS = 3;
                    break;

                case "tls1.2_ticket_auth":
                    shadowsocksr.OBFS = 4;
                    break;

                case "tls1.2_ticket_fastauth":
                    shadowsocksr.OBFS = 5;
                    break;

                default:
                    throw new NotSupportedException(String.Format("不支持的混淆方式:{0}", data[4]));
                }

                var info = data[5].Split('/');

                shadowsocksr.Password = Utils.UrlSafeBase64Decode(info[0]);

                var dict = new Dictionary <string, string>();

                foreach (var str in info[1].Remove(0, 1).Split('&'))
                {
                    var splited = str.Split('=');

                    dict.Add(splited[0], splited[1]);
                }

                if (dict.ContainsKey("remarks"))
                {
                    shadowsocksr.Remark = Utils.UrlSafeBase64Decode(dict["remarks"]);
                }
                else
                {
                    shadowsocksr.Remark = String.Format("{0}:{1}", shadowsocksr.Address, shadowsocksr.Port);
                }

                if (dict.ContainsKey("protoparam"))
                {
                    shadowsocksr.ProtocolParam = Utils.UrlSafeBase64Decode(dict["protoparam"]);
                }

                if (dict.ContainsKey("obfsparam"))
                {
                    shadowsocksr.OBFSParam = Utils.UrlSafeBase64Decode(dict["obfsparam"]);
                }

                return(shadowsocksr);
            }
示例#2
0
文件: Utils.cs 项目: onfork/x2tap
            public static string GetShadowsocksR(Objects.Server.ShadowsocksR shadowsocksr)
            {
                var data = new Objects.ShadowsocksRConfig();

                data.server      = shadowsocksr.Address;
                data.server_port = shadowsocksr.Port;

                switch (shadowsocksr.EncryptMethod)
                {
                case 0:
                    data.method = "none";
                    break;

                case 1:
                    data.method = "table";
                    break;

                case 2:
                    data.method = "rc4";
                    break;

                case 3:
                    data.method = "rc4-md5";
                    break;

                case 4:
                    data.method = "rc4-md5-6";
                    break;

                case 5:
                    data.method = "aes-128-cfb";
                    break;

                case 6:
                    data.method = "aes-192-cfb";
                    break;

                case 7:
                    data.method = "aes-256-cfb";
                    break;

                case 8:
                    data.method = "aes-128-ctr";
                    break;

                case 9:
                    data.method = "aes-192-ctr";
                    break;

                case 10:
                    data.method = "aes-256-ctr";
                    break;

                case 11:
                    data.method = "bf-cfb";
                    break;

                case 12:
                    data.method = "camellia-128-cfb";
                    break;

                case 13:
                    data.method = "camellia-192-cfb";
                    break;

                case 14:
                    data.method = "camellia-256-cfb";
                    break;

                case 15:
                    data.method = "salsa20";
                    break;

                case 16:
                    data.method = "chacha20";
                    break;

                case 17:
                    data.method = "chacha20-ietf";
                    break;

                default:
                    throw new NotSupportedException(String.Format("不支持的加密方式:{0}", shadowsocksr.EncryptMethod));
                }

                data.password = shadowsocksr.Password;

                switch (shadowsocksr.Protocol)
                {
                case 0:
                    data.protocol = "origin";
                    break;

                case 1:
                    data.protocol = "auth_sha1_v4";
                    break;

                case 2:
                    data.protocol = "auth_aes128_sha1";
                    break;

                case 3:
                    data.protocol = "auth_aes128_md5";
                    break;

                case 4:
                    data.protocol = "auth_chain_a";
                    break;

                case 5:
                    data.protocol = "auth_chain_b";
                    break;

                case 6:
                    data.protocol = "auth_chain_c";
                    break;

                case 7:
                    data.protocol = "auth_chain_d";
                    break;

                case 8:
                    data.protocol = "auth_chain_e";
                    break;

                case 9:
                    data.protocol = "auth_chain_f";
                    break;

                default:
                    throw new NotSupportedException(String.Format("不支持的协议:{0}", shadowsocksr.Protocol));
                }

                data.protocol_param = shadowsocksr.ProtocolParam;

                switch (shadowsocksr.OBFS)
                {
                case 0:
                    data.obfs = "plain";
                    break;

                case 1:
                    data.obfs = "http_simple";
                    break;

                case 2:
                    data.obfs = "http_post";
                    break;

                case 3:
                    data.obfs = "http_mix";
                    break;

                case 4:
                    data.obfs = "tls1.2_ticket_auth";
                    break;

                case 5:
                    data.obfs = "tls1.2_ticket_fastauth";
                    break;

                default:
                    throw new NotSupportedException(String.Format("不支持的混淆方式:{0}", shadowsocksr.Protocol));
                }

                data.obfs_param = shadowsocksr.OBFSParam;

                return(Newtonsoft.Json.JsonConvert.SerializeObject(data));
            }