Esempio n. 1
0
        // Konstruktor zur Verbindungseinstellung mittels Zertifikat
        public SSH(string ipadress, string port, string username, string certificate, string passphrase)
        {
            // Variablen überprüfen
            if (ipadress == ResourceText.EMPTY)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionIP));
            }
            if (username == ResourceText.EMPTY)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionUser));
            }
            if (Tool.String2Int(port, 22) > _maxport)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionPort));
            }
            if (certificate == ResourceText.EMPTY)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionCertificate));
            }

            // Klassenvariablen beschreiben
            _ipaddress   = ipadress;
            _port        = port;
            _username    = username;
            _certificate = certificate;
            _passphrase  = Chiper.Decrypt(passphrase, ResourceText.Passphrase);

            // Zertifikat basierte Verbindung erstellen
            _connection = new ConnectionInfo(ipadress, Tool.String2Int(port, 22), username, new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[] { new PrivateKeyFile(@certificate, passphrase) }));
        }
Esempio n. 2
0
        // Konstruktor zur Verbindungseinstellung mittels Benutzer und Passwort
        public SSH(string ipaddress, string port, string username, string password = null)
        {
            // Eingabevariablen überprüfen
            if (ipaddress == ResourceText.EMPTY || ipaddress.Length > Convert.ToInt16(ResourceText.sshIPAddressLength))
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionIP));
            }
            if (username == ResourceText.EMPTY || username.Length > Convert.ToInt16(ResourceText.sshFieldMaxLength))
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionUser));
            }
            if (Tool.String2Int(port, Convert.ToInt16(ResourceText.sshPORT)) > _maxport || Tool.String2Int(port, Convert.ToInt16(ResourceText.sshPORT)) < _minport)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionPort));
            }

            // Klassenvariablen mit übergebenen Werten an Konstruktor beschreiben
            _ipaddress = ipaddress;
            _username  = username;
            _port      = port;

            try
            {
                // Versuchen übergebenes Passwort zu entschlüsseln
                _password = Chiper.Decrypt(password, ResourceText.Passphrase);
            }
            catch
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionPasswortDecrypt));
            }

            // Passwort basierte Verbindung erstellen
            _connection = new ConnectionInfo(ipaddress, Tool.String2Int(port, 22), username, new AuthenticationMethod[] { new PasswordAuthenticationMethod(username, password) });
        }
Esempio n. 3
0
        private static void Encode(string message, Chiper encoder, Chiper decoder)
        {
            Console.WriteLine(message);

            string encoded = encoder.Encode(message);

            Console.WriteLine(encoded);

            string decoded = decoder.Encode(encoded);

            Console.WriteLine(decoded);

            Console.ReadLine();
        }
Esempio n. 4
0
        private static string EncodeFromFile(Chiper chiper, string fileName, int lines = ALL_LINES)
        {
            string[] content = File.ReadAllLines(fileName);
            if (lines == ALL_LINES)
            {
                lines = content.Length;
            }

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < lines; i++)
            {
                builder.AppendLine(
                    chiper.Encode(content[i]));
            }
            string encoded = builder.ToString();

            Console.WriteLine(encoded);
            Console.ReadLine();
            return(encoded);
        }
Esempio n. 5
0
        private void buttonCertificateAdd_Click(object sender, EventArgs e)
        {
            DialogResult datapattern = DialogResult.OK;
            bool         resolve     = false;
            bool         noresolve   = false;

            // Überprüfen ob Zertifikat eingegeben
            if (_certificate == null)
            {
                datapattern = MessageBox.Show(ResourceText.MsgNoFileSelected, ResourceText.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // Überprüfen ob Eingabefelder leer sind
            if (!Tool.CheckString(textBoxCertificateName) ||
                !Tool.CheckString(textBoxCertificatePassphrase) ||
                !Tool.CheckString(textBoxCertificateServer) ||
                !Tool.CheckString(textBoxCertificatePort))
            {
                return;
            }

            // Überprüfen ob Eingabefelder gleich den Standardeingabefeldern
            if (textBoxCertificateName.Text == ResourceText.ValueCertificate &&
                textBoxCertificatePassphrase.Text == ResourceText.ValuePassword)
            {
                datapattern = MessageBox.Show(ResourceText.MsgSameData, ResourceText.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            }

            // Überprüfen ob bei Standardeingabe Abbruch erfolgen soll
            if (datapattern == DialogResult.No)
            {
                return;
            }

            if (textBoxCertificateServer.Text == ResourceText.ValueServer)
            {
                textBoxCertificateServer.Text = ResourceText.AuthServer;
            }

            // Überprüfen ob Porteingabe zulässig (1 - 65535)
            if (!Tool.CheckString(textBoxCertificatePort, 1, 65536))
            {
                return;
            }

            // Überprüfen ob Server TextBox kein Standard Initiator enthält
            if (textBoxCertificateServer.Text != ResourceText.AuthServer)
            {
                // Überprüfen ob eingegebene IP-Addresse zulässig
                if (!Network.CheckIP(textBoxCertificateServer.Text))
                {
                    if (!Network.CheckHost(textBoxCertificateServer.Text))
                    {
                        textBoxCertificateServer.BackColor = Color.Red;
                        textBoxCertificateServer.SelectAll();

                        MessageBox.Show(ResourceText.MsgServerFault, ResourceText.Warning, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        return;
                    }
                    else
                    {
                        if (Network.PingHost(textBoxCertificateServer.Text, 4))
                        {
                            resolve = true;
                        }
                    }
                }
                else
                {
                    if (Network.PingIP(textBoxCertificateServer.Text, 4))
                    {
                        resolve = true;
                    }
                }
            }
            else
            {
                noresolve = true;
            }

            if (!Handler.FileCopy(_certificate, Application.StartupPath + ResourceText.AuthCertificatePath, true))
            {
                MessageBox.Show(ResourceText.MsgFileCopyFault, ResourceText.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int listviewid = listViewCertificate.Items.Count;

            string[] listviewitem = { listviewid.ToString(), textBoxCertificateName.Text, ResourceText.SpacerPassword, textBoxCertificateServer.Text, textBoxCertificatePort.Text };

            // ListView mit neuem Eintrag ergänzen
            ListViewItem item;

            item = new ListViewItem(listviewitem);
            listViewCertificate.Items.Add(item);

            // ListView Eintrag Server erreichbarkeit prüfen
            if (resolve == true && noresolve == false)
            {
                listViewCertificate.Items[listviewid].ForeColor = Color.Green;
            }
            else if (resolve == false && noresolve == false)
            {
                listViewCertificate.Items[listviewid].ForeColor = Color.Red;
            }

            // Account Liste mit neuem Eintrag ergänzen
            _systemparameter.SystemCertificate[listviewid] = new Dictionary <string, string>();
            _systemparameter.SystemCertificate[listviewid].Add(ResourceText.keyMode, ResourceText.AuthModeCERT);
            _systemparameter.SystemCertificate[listviewid].Add(ResourceText.keyCertificate, textBoxCertificateName.Text);
            _systemparameter.SystemCertificate[listviewid].Add(ResourceText.keyCertificateName, Path.GetFileName(_certificate));
            _systemparameter.SystemCertificate[listviewid].Add(ResourceText.keyPassphrase, Chiper.Encrypt(textBoxCertificatePassphrase.Text, ResourceText.Passphrase));
            _systemparameter.SystemCertificate[listviewid].Add(ResourceText.keyServer, textBoxCertificateServer.Text);
            _systemparameter.SystemCertificate[listviewid].Add(ResourceText.keyPort, textBoxCertificatePort.Text);

            // TextBoxen mit Standardparameteren belegen
            textboxinit();

            _certificate = null;
        }