Beispiel #1
0
        public ConfigForm(ShadowsocksController controller, UpdateChecker updateChecker, int focusIndex)
        {
            Font = SystemFonts.MessageBoxFont;
            InitializeComponent();
            lstServers.Font = CreateFont();

            nudServerPort.Minimum = IPEndPoint.MinPort;
            nudServerPort.Maximum = IPEndPoint.MaxPort;
            nudUdpPort.Minimum    = IPEndPoint.MinPort;
            nudUdpPort.Maximum    = IPEndPoint.MaxPort;

            Icon           = Icon.FromHandle(Resources.ssw128.GetHicon());
            _controller    = controller;
            _updateChecker = updateChecker;
            if (updateChecker.LatestVersionURL == null)
            {
                llbUpdate.Visible = false;
            }

            foreach (string name in EncryptorFactory.GetEncryptor().Keys)
            {
                EncryptorInfo info = EncryptorFactory.GetEncryptorInfo(name);
                if (info.display)
                {
                    cmbEncryption.Items.Add(name);
                }
            }
            UpdateTexts();
            controller.ConfigChanged += controller_ConfigChanged;

            LoadCurrentConfiguration();
            if (_modifiedConfiguration.index >= 0 && _modifiedConfiguration.index < _modifiedConfiguration.configs.Count)
            {
                _oldSelectedId = _modifiedConfiguration.configs[_modifiedConfiguration.index].id;
            }
            if (focusIndex == -1)
            {
                int index = _modifiedConfiguration.index + 1;
                if (index < 0 || index > _modifiedConfiguration.configs.Count)
                {
                    index = _modifiedConfiguration.configs.Count;
                }

                focusIndex = index;
            }

            ShowWindow();

            if (focusIndex >= 0 && focusIndex < _modifiedConfiguration.configs.Count)
            {
                SetServerListSelectedIndex(focusIndex);
                LoadSelectedServer();
            }

            UpdateServersListBoxTopIndex();
        }
        public ConfigForm(ShadowsocksController _controller, UpdateChecker _updateChecker)
        {
            this.controller    = _controller;
            this.updateChecker = _updateChecker;
            InitializeComponent();
            this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
            if (updateChecker.LatestVersionURL == null)
            {
                llbUpdate.Visible = false;
            }
            this.lstServers.MouseWheel += lstServers_MouseWheel;
            this.DoubleBuffered         = true;

            nudServerPort.Minimum = IPEndPoint.MinPort;
            nudServerPort.Maximum = IPEndPoint.MaxPort;
            nudUdpPort.Minimum    = IPEndPoint.MinPort;
            nudUdpPort.Maximum    = IPEndPoint.MaxPort;


            foreach (string name in EncryptorFactory.GetEncryptor())
            {
                EncryptorInfo info = EncryptorFactory.GetEncryptorInfo(name);
                if (info.display)
                {
                    cmbEncryption.Items.Add(name);
                }
            }


            controller.ConfigChanged += controller_ConfigChanged;

            UpdateTexts();
            LoadConfiguration();

            int dpi_mul = Util.Utils.GetDpiMul();

            DrawLogo(350 * dpi_mul / 4);

            if (!settings.isHideTips)
            {
                picQRcode.Visible = true;
            }

            displayItemsCount = (lstServers.Height - 4) / lstServers.ItemHeight;
            if (settings.Servers.Count > 21)
            {
                displayItemsCount--;
            }

            if (settings.index > -1 && settings.index < settings.Servers.Count)
            {
                currentServerID = settings.Servers[settings.index].id;
            }
        }
 private void InitEncryptorInfo(string method)
 {
     method        = method.ToLower();
     _method       = method;
     ciphers       = getCiphers();
     CipherInfo    = ciphers[_method];
     _innerLibName = CipherInfo.InnerLibName;
     _cipher       = CipherInfo.Type;
     if (_cipher == 0)
     {
         throw new System.Exception("method not found");
     }
     keyLen = CipherInfo.KeySize;
     ivLen  = CipherInfo.IvSize;
 }
 protected void InitEncryptorInfo(string method)
 {
     method        = method.ToLower();
     _method       = method;
     ciphers       = getCiphers();
     CipherInfo    = ciphers[_method];
     _innerLibName = CipherInfo.InnerLibName;
     _cipher       = CipherInfo.Type;
     if (_cipher == 0)
     {
         throw new System.Exception("method not found");
     }
     keyLen   = CipherInfo.KeySize;
     saltLen  = CipherInfo.SaltSize;
     tagLen   = CipherInfo.TagSize;
     nonceLen = CipherInfo.NonceSize;
 }
Beispiel #5
0
        private void InitKey(string method, string password)
        {
            method  = method.ToLower();
            _method = method;
            string k = method + ":" + password;

            ciphers       = getCiphers();
            _cipherInfo   = ciphers[_method];
            _innerLibName = string.IsNullOrWhiteSpace(_cipherInfo.name) ? method : _cipherInfo.name;
            _cipher       = _cipherInfo.type;
            if (_cipher == 0)
            {
                throw new Exception("method not found");
            }
            keyLen = ciphers[_method].key_size;
            ivLen  = ciphers[_method].iv_size;
            if (!CachedKeys.ContainsKey(k))
            {
                lock (CachedKeys)
                {
                    if (!CachedKeys.ContainsKey(k))
                    {
                        byte[] passbuf = Encoding.UTF8.GetBytes(password);
                        _key = new byte[32];
                        byte[] iv = new byte[16];
                        bytesToKey(passbuf, _key);
                        CachedKeys.Set(k, _key);
                        CachedKeys.Sweep();
                    }
                }
            }
            if (_key == null)
            {
                _key = CachedKeys.Get(k);
            }
            Array.Resize(ref _iv, ivLen);
            randBytes(_iv, ivLen);
        }
        public ConfigForm(ShadowsocksController controller, UpdateChecker updateChecker, int focusIndex)
        {
            this.Font = System.Drawing.SystemFonts.MessageBoxFont;
            InitializeComponent();
            ServersListBox.Font = CreateFont();

            NumServerPort.Minimum = IPEndPoint.MinPort;
            NumServerPort.Maximum = IPEndPoint.MaxPort;
            NumUDPPort.Minimum    = IPEndPoint.MinPort;
            NumUDPPort.Maximum    = IPEndPoint.MaxPort;

            this.Icon          = Icon.FromHandle(Resources.ssw128.GetHicon());
            this.controller    = controller;
            this.updateChecker = updateChecker;
            if (updateChecker.LatestVersionURL == null)
            {
                LinkUpdate.Visible = false;
            }

            foreach (string name in EncryptorFactory.GetEncryptor())
            {
                EncryptorInfo info = EncryptorFactory.GetEncryptorInfo(name);
                if (info.display)
                {
                    EncryptionSelect.Items.Add(name);
                }
            }
            UpdateTexts();
            controller.ConfigChanged += controller_ConfigChanged;

            LoadCurrentConfiguration();
            if (_modifiedConfiguration.index >= 0 && _modifiedConfiguration.index < _modifiedConfiguration.configs.Count)
            {
                _oldSelectedID = _modifiedConfiguration.configs[_modifiedConfiguration.index].id;
            }
            if (focusIndex == -1)
            {
                int index = _modifiedConfiguration.index + 1;
                if (index < 0 || index > _modifiedConfiguration.configs.Count)
                {
                    index = _modifiedConfiguration.configs.Count;
                }

                focusIndex = index;
            }

            //if (_modifiedConfiguration.isHideTips)
            //    PictureQRcode.Visible = false;

            int dpi_mul = Util.Utils.GetDpiMul();

            //ServersListBox.Height = ServersListBox.Height * 4 / dpi_mul;
            ServersListBox.Width = ServersListBox.Width * dpi_mul / 4;
            //ServersListBox.Height = ServersListBox.Height * dpi_mul / 4;
            ServersListBox.Height = checkAdvSetting.Top + checkAdvSetting.Height;
            AddButton.Width       = AddButton.Width * dpi_mul / 4;
            AddButton.Height      = AddButton.Height * dpi_mul / 4;
            DeleteButton.Width    = DeleteButton.Width * dpi_mul / 4;
            DeleteButton.Height   = DeleteButton.Height * dpi_mul / 4;
            UpButton.Width        = UpButton.Width * dpi_mul / 4;
            UpButton.Height       = UpButton.Height * dpi_mul / 4;
            DownButton.Width      = DownButton.Width * dpi_mul / 4;
            DownButton.Height     = DownButton.Height * dpi_mul / 4;

            //IPTextBox.Width = IPTextBox.Width * dpi_mul / 4;
            //ServerPortNumericUpDown.Width = ServerPortNumericUpDown.Width * dpi_mul / 4;
            //PasswordTextBox.Width = PasswordTextBox.Width * dpi_mul / 4;
            //EncryptionSelect.Width = EncryptionSelect.Width * dpi_mul / 4;
            //TCPProtocolComboBox.Width = TCPProtocolComboBox.Width * dpi_mul / 4;
            //ObfsCombo.Width = ObfsCombo.Width * dpi_mul / 4;
            //TextObfsParam.Width = TextObfsParam.Width * dpi_mul / 4;
            //RemarksTextBox.Width = RemarksTextBox.Width * dpi_mul / 4;
            //TextGroup.Width = TextGroup.Width * dpi_mul / 4;
            //TextLink.Width = TextLink.Width * dpi_mul / 4;
            //TextUDPPort.Width = TextUDPPort.Width * dpi_mul / 4;

            //int font_height = 9;
            //EncryptionSelect.Height = EncryptionSelect.Height - font_height + font_height * dpi_mul / 4;
            //TCPProtocolComboBox.Height = TCPProtocolComboBox.Height - font_height + font_height * dpi_mul / 4;
            //ObfsCombo.Height = ObfsCombo.Height - font_height + font_height * dpi_mul / 4;

            //OKButton.Width = OKButton.Width * dpi_mul / 4;
            OKButton.Height = OKButton.Height * dpi_mul / 4;
            //MyCancelButton.Width = MyCancelButton.Width * dpi_mul / 4;
            MyCancelButton.Height = MyCancelButton.Height * dpi_mul / 4;

            DrawLogo(350 * dpi_mul / 4);
            //DrawLogo(350);

            ShowWindow();

            if (focusIndex >= 0 && focusIndex < _modifiedConfiguration.configs.Count)
            {
                SetServerListSelectedIndex(focusIndex);
                LoadSelectedServer();
            }

            UpdateServersListBoxTopIndex();
        }
        public ConfigForm(ShadowsocksController controller, int focusIndex)
        {
            this.Font = System.Drawing.SystemFonts.MessageBoxFont;
            InitializeComponent();
            lstServers.Font = CreateFont();

            nudServerPort.Minimum = IPEndPoint.MinPort;
            nudServerPort.Maximum = IPEndPoint.MaxPort;
            nudUdpPort.Minimum    = IPEndPoint.MinPort;
            nudUdpPort.Maximum    = IPEndPoint.MaxPort;

            this.Icon       = Icon.FromHandle(Resources.ssw128.GetHicon());
            this.controller = controller;

            foreach (string name in EncryptorFactory.GetEncryptor())
            {
                EncryptorInfo info = EncryptorFactory.GetEncryptorInfo(name);
                if (info.display)
                {
                    cmbEncryption.Items.Add(name);
                }
            }
            UpdateTexts();
            controller.ConfigChanged += controller_ConfigChanged;

            LoadCurrentConfiguration();
            if (_modifiedConfiguration.index >= 0 && _modifiedConfiguration.index < _modifiedConfiguration.configs.Count)
            {
                _oldSelectedID = _modifiedConfiguration.configs[_modifiedConfiguration.index].id;
            }
            if (focusIndex == -1)
            {
                int index = _modifiedConfiguration.index + 1;
                if (index < 0 || index > _modifiedConfiguration.configs.Count)
                {
                    index = _modifiedConfiguration.configs.Count;
                }

                focusIndex = index;
            }

            int dpi_mul = Util.Utils.GetDpiMul();

            //comment
            ////ServersListBox.Height = ServersListBox.Height * 4 / dpi_mul;
            //lstServers.Width = lstServers.Width * dpi_mul / 4;
            ////ServersListBox.Height = ServersListBox.Height * dpi_mul / 4;
            //lstServers.Height = chkAdvSetting.Top + chkAdvSetting.Height;
            //btnAdd.Width = btnAdd.Width * dpi_mul / 4;
            //btnAdd.Height = btnAdd.Height * dpi_mul / 4;
            //btnDelete.Width = btnDelete.Width * dpi_mul / 4;
            //btnDelete.Height = btnDelete.Height * dpi_mul / 4;
            //btnUp.Width = btnUp.Width * dpi_mul / 4;
            //btnUp.Height = btnUp.Height * dpi_mul / 4;
            //btnDown.Width = btnDown.Width * dpi_mul / 4;
            //btnDown.Height = btnDown.Height * dpi_mul / 4;

            ////IPTextBox.Width = IPTextBox.Width * dpi_mul / 4;
            ////ServerPortNumericUpDown.Width = ServerPortNumericUpDown.Width * dpi_mul / 4;
            ////PasswordTextBox.Width = PasswordTextBox.Width * dpi_mul / 4;
            ////EncryptionSelect.Width = EncryptionSelect.Width * dpi_mul / 4;
            ////TCPProtocolComboBox.Width = TCPProtocolComboBox.Width * dpi_mul / 4;
            ////ObfsCombo.Width = ObfsCombo.Width * dpi_mul / 4;
            ////TextObfsParam.Width = TextObfsParam.Width * dpi_mul / 4;
            ////RemarksTextBox.Width = RemarksTextBox.Width * dpi_mul / 4;
            ////TextGroup.Width = TextGroup.Width * dpi_mul / 4;
            ////TextLink.Width = TextLink.Width * dpi_mul / 4;
            ////TextUDPPort.Width = TextUDPPort.Width * dpi_mul / 4;

            ////int font_height = 9;
            ////EncryptionSelect.Height = EncryptionSelect.Height - font_height + font_height * dpi_mul / 4;
            ////TCPProtocolComboBox.Height = TCPProtocolComboBox.Height - font_height + font_height * dpi_mul / 4;
            ////ObfsCombo.Height = ObfsCombo.Height - font_height + font_height * dpi_mul / 4;

            ////OKButton.Width = OKButton.Width * dpi_mul / 4;
            //btnOK.Height = btnOK.Height * dpi_mul / 4;
            ////MyCancelButton.Width = MyCancelButton.Width * dpi_mul / 4;
            //btnCancel.Height = btnCancel.Height * dpi_mul / 4;

            ShowWindow();

            if (focusIndex >= 0 && focusIndex < _modifiedConfiguration.configs.Count)
            {
                SetServerListSelectedIndex(focusIndex);
                LoadSelectedServer();
            }

            UpdateServersListBoxTopIndex();
        }
        public ConfigForm(ShadowsocksController controller, UpdateChecker updateChecker, int focusIndex)
        {
            this.Font = System.Drawing.SystemFonts.MessageBoxFont;
            InitializeComponent();

            this.Icon          = Icon.FromHandle(Resources.ssw128.GetHicon());
            this.controller    = controller;
            this.updateChecker = updateChecker;
            if (updateChecker.LatestVersionURL == null)
            {
                LinkUpdate.Visible = false;
            }

            foreach (string name in EncryptorFactory.GetEncryptor())
            {
                EncryptorInfo info = EncryptorFactory.GetEncryptorInfo(name);
                if (info.display)
                {
                    EncryptionSelect.Items.Add(name);
                }
            }
            UpdateTexts();
            controller.ConfigChanged += controller_ConfigChanged;

            LoadCurrentConfiguration();
            if (_modifiedConfiguration.index >= 0 && _modifiedConfiguration.index < _modifiedConfiguration.configs.Count)
            {
                _oldSelectedID = _modifiedConfiguration.configs[_modifiedConfiguration.index].id;
            }
            if (focusIndex == -1)
            {
                focusIndex = _modifiedConfiguration.configs.Count - 1;
            }
            if (focusIndex >= 0 && focusIndex < _modifiedConfiguration.configs.Count)
            {
                SetServerListSelectedIndex(focusIndex);
            }

            if (_modifiedConfiguration.isHideTips)
            {
                PictureQRcode.Visible = false;
            }

            int dpi_mul = Util.Utils.GetDpiMul();

            ServersListBox.Width  = ServersListBox.Width * dpi_mul / 4;
            ServersListBox.Height = ServersListBox.Height * dpi_mul / 4;
            AddButton.Width       = AddButton.Width * dpi_mul / 4;
            AddButton.Height      = AddButton.Height * dpi_mul / 4;
            DeleteButton.Width    = DeleteButton.Width * dpi_mul / 4;
            DeleteButton.Height   = DeleteButton.Height * dpi_mul / 4;
            UpButton.Width        = UpButton.Width * dpi_mul / 4;
            UpButton.Height       = UpButton.Height * dpi_mul / 4;
            DownButton.Width      = DownButton.Width * dpi_mul / 4;
            DownButton.Height     = DownButton.Height * dpi_mul / 4;

            //IPTextBox.Width = IPTextBox.Width * dpi_mul / 4;
            //ServerPortTextBox.Width = ServerPortTextBox.Width * dpi_mul / 4;
            //PasswordTextBox.Width = PasswordTextBox.Width * dpi_mul / 4;
            //EncryptionSelect.Width = EncryptionSelect.Width * dpi_mul / 4;
            //TCPProtocolComboBox.Width = TCPProtocolComboBox.Width * dpi_mul / 4;
            //ObfsCombo.Width = ObfsCombo.Width * dpi_mul / 4;
            //TextObfsParam.Width = TextObfsParam.Width * dpi_mul / 4;
            //RemarksTextBox.Width = RemarksTextBox.Width * dpi_mul / 4;
            //TextGroup.Width = TextGroup.Width * dpi_mul / 4;
            //TextLink.Width = TextLink.Width * dpi_mul / 4;
            //TextUDPPort.Width = TextUDPPort.Width * dpi_mul / 4;
            //Font new_font = new Font("Arial", (float)(9.0 * dpi_mul / 4));
            //this.Font = new_font;
            //IPTextBox.Font = new_font;
            //ServerPortTextBox.Font = new_font;
            //PasswordTextBox.Font = new_font;
            //EncryptionSelect.Font = new_font;
            //TCPProtocolComboBox.Font = new_font;
            //ObfsCombo.Font = new_font;
            //TextObfsParam.Font = new_font;
            //RemarksTextBox.Font = new_font;
            //TextGroup.Font = new_font;
            //TextLink.Font = new_font;
            //TextUDPPort.Font = new_font;

            int font_height = 9;

            EncryptionSelect.Height    = EncryptionSelect.Height - font_height + font_height * dpi_mul / 4;
            TCPProtocolComboBox.Height = TCPProtocolComboBox.Height - font_height + font_height * dpi_mul / 4;
            ObfsCombo.Height           = ObfsCombo.Height - font_height + font_height * dpi_mul / 4;

            //MyCancelButton.Height = MyCancelButton.Height * dpi_mul / 4;
            MyCancelButton.Width = MyCancelButton.Width * dpi_mul / 4;
            OKButton.Width       = OKButton.Width * dpi_mul / 4;
            //OKButton.Height = OKButton.Height * dpi_mul / 4;

            GenQR(TextLink.Text);
        }