Exemplo n.º 1
0
        public void AuthenticateWithKey(string username, string key, string password = null)
        {
            if (!_client.IsConnected)
            {
                throw new Exception("Client is not connected");
            }

            var sshKey = new Chilkat.SshKey();

            if (password != null)
            {
                sshKey.Password = password;
            }

            if (!sshKey.FromOpenSshPrivateKey(key))
            {
                throw new SshException(ErrorType.SshKeyParsingError, _client.LastErrorText);
            }

            if (!_client.AuthenticatePk(username, sshKey))
            {
                throw new SshException(ErrorType.SshAuthenticationError, _client.LastErrorText);
            }

            IsAuthenticated = true;
        }
Exemplo n.º 2
0
 public LinuxComputer(int maxConcurrent) : base(maxConcurrent, null)
 {
     _domainName = "dummy";
     _port       = 22;
     _username   = "******";
     _privateKey.FromOpenSshPrivateKey("dummy, read key from somewhere");
     _rootPath = "/home/dummy/superprocessor";
     _charset  = "urf-8";
 }
Exemplo n.º 3
0
        public static void publickeyAuth()
        {
            Chilkat.Ssh ssh = new Chilkat.Ssh();

            //  Any string automatically begins a fully-functional 30-day trial.
            bool success = ssh.UnlockComponent("Anything for 30-day trial");

            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            //  Set some timeouts, in milliseconds:
            ssh.ConnectTimeoutMs = 5000;
            ssh.IdleTimeoutMs    = 15000;

            //  Connect to the SSH server.
            //  The standard SSH port = 22
            //  The hostname may be a hostname or IP address.
            int    port;
            string hostname;

            hostname = "172.24.16.155";
            port     = 22;
            success  = ssh.Connect(hostname, port);
            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Chilkat.SshKey key = new Chilkat.SshKey();

            //  Read the PEM file into a string variable:
            //  (This does not load the PEM file into the key.  The LoadText
            //  method is a convenience method for loading the full contents of ANY text
            //  file into a string variable.)
            string privKey = key.LoadText("private.ppk");

            if (key.LastMethodSuccess != true)
            {
                Console.WriteLine(key.LastErrorText);
                return;
            }

            //  Load a private key from a PEM string:
            //  (Private keys may be loaded from OpenSSH and Putty formats.
            //  Both encrypted and unencrypted private key file formats
            //  are supported.  This example loads an unencrypted private
            //  key in OpenSSH format.  PuTTY keys typically use the .ppk
            //  file extension, while OpenSSH keys use the PEM format.
            //  (For PuTTY keys, call FromPuttyPrivateKey instead.)
            success = key.FromOpenSshPrivateKey(privKey);
            if (success != true)
            {
                Console.WriteLine(key.LastErrorText);
                return;
            }

            //  Authenticate with the SSH server using the login and
            //  private key.  (The corresponding public key should've
            //  been installed on the SSH server beforehand.)
            success = ssh.AuthenticatePk("myLogin", key);
            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Console.WriteLine(ssh.LastErrorText);
            Console.WriteLine("Public-Key Authentication Successful!");
        }
Exemplo n.º 4
0
        public void Open()
        {
            try
            {
                if (session != null && IsOpen())
                {
                    return;
                }

                bool success;

                session = new Chilkat.SshTunnel();

                success = session.UnlockComponent("ITAYHESSH_d674QVQunRnj");
                if (success != true)
                {
                    throw new DuradosException(session.LastErrorText);
                }

                //  The destination host/port is the database server.
                //  The DestHostname may be the domain name or
                //  IP address (in dotted decimal notation) of the database
                //  server.
                session.DestPort     = remotePort;
                session.DestHostname = "localhost";

                //  Provide information about the location of the SSH server,
                //  and the authentication to be used with it. This is the
                //  login information for the SSH server (not the database server).
                session.SshHostname = tunnel.RemoteHost;
                session.SshPort     = tunnel.Port;
                session.SshLogin    = tunnel.User;
                if (string.IsNullOrEmpty(tunnel.Password))
                {
                    Chilkat.SshKey sshKey = new Chilkat.SshKey();
                    //string sss = sshKey.LoadText(@"G:\Dev\Relly - new\Duradus.Web.Mvc.App\Modubiz2012.pem");
                    string keyText = tunnel.PrivateKey;
                    success = sshKey.FromOpenSshPrivateKey(keyText);
                    //string fff = sshKey.ToOpenSshPrivateKey(false);
                    success = session.SetSshAuthenticationKey(sshKey);
                    if (success)
                    {
                    }
                }
                else
                {
                    session.SshPassword = tunnel.Password;
                }

                //  Start accepting connections in a background thread.
                //  The SSH tunnels are autonomously run in a background
                //  thread.  There is one background thread for accepting
                //  connections, and another for managing the tunnel pool.
                int listenPort;
                listenPort = localPort;
                success    = session.BeginAccepting(listenPort);
                if (success != true)
                {
                    throw new DuradosException(session.LastErrorText);
                }

                //  At this point you may connect to the database server through
                //  the SSH tunnel.  Your database connection string would
                //  use "localhost" for the hostname and 3316 for the port.
                //  We're not going to show the database coding here,
                //  because it can vary depending on the API you're using
                //  (ADO, ODBC, OLE DB, etc. )
            }
            catch (Exception exception)
            {
                throw new DuradosException("Could not  open SSH tunnel", exception);
            }
        }