A static class for creating a new SSH connection
Ejemplo n.º 1
0
 protected SSHChannel(SSHConnection con, ChannelType type, int local_id)
 {
     con.ChannelCollection.RegisterChannel(local_id, this);
     _connection = con;
     _type = type;
     _localID = local_id;
 }
Ejemplo n.º 2
0
 protected SSHChannel(SSHConnection con, ChannelType type, int local_id)
 {
     con.ChannelCollection.RegisterChannel(local_id, this);
     _connection = con;
     _type       = type;
     _localID    = local_id;
 }
Ejemplo n.º 3
0
        private static SSHConnection ConnectMain(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, VersionExchangeHandler pnh, AbstractGranadosSocket s)
        {
            DataFragment data = pnh.WaitResponse();
            string       sv   = pnh.ServerVersion;

            SSHConnection con = null;

            if (param.Protocol == SSHProtocol.SSH1)
            {
                con = new SSH1Connection(param, s, receiver, sv, SSHUtil.ClientVersionString(param.Protocol));
            }
            else
            {
                con = new SSH2Connection(param, s, receiver, sv, SSHUtil.ClientVersionString(param.Protocol));
            }

            con.TraceReceptionEvent("server version-string", sv.Trim());
            pnh.Close();
            s.SetHandler(con.PacketBuilder);
            con.SendMyVersion(param);

            if (con.Connect() != AuthenticationResult.Failure)
            {
                return(con);
            }
            else
            {
                s.Close();
                return(null);
            }
        }
Ejemplo n.º 4
0
        //�I���̃n���h�����O �񓯊��ɕʃX���b�h����Ă΂��̂Œ���
        public void ConnectionClosed(SSHConnection connection)
        {
            IDictionaryEnumerator e = _profileToConnection.GetEnumerator();
            while (e.MoveNext()) {
                if (connection == e.Value) {
                    ChannelProfile prof = (ChannelProfile)e.Key;
                    _profileToConnection.Remove(e.Key);
                    bool manual = false;
                    lock (this) {
                        manual = _manualClosingConnections.Contains(connection);
                        if (manual)
                            _manualClosingConnections.Remove(connection);
                    }

                    if (!manual) {
                        Util.InterThreadWarning(Env.Strings.GetString("Message.ConnectionManager.Disconnected"));
                    }

                    Env.MainForm.Invoke(new RefreshProfileStatusDelegate(Env.MainForm.RefreshProfileStatus), prof);

                    break;
                }
            }
        }
 //SSHConnection�m�����ɌĂ�
 public void SetSSHConnection(SSHConnection connection)
 {
     _connection = connection;
     _connection.AutoDisconnect = true; //�Ō�̃`���l���ؒf�ŃR�l�N�V������ؒf
 }
Ejemplo n.º 6
0
 //SSHConnection確立時に呼ぶ
 public void SetSSHConnection(SSHConnection connection)
 {
     _connection = connection;
     _connection.AutoDisconnect = true; //最後のチャネル切断でコネクションも切断
 }
Ejemplo n.º 7
0
 public void ConnectionError(SSHConnection connection, Exception error) {
     Debug.WriteLine(error.StackTrace);
     Util.InterThreadWarning(error.Message);
     ConnectionClosed(connection);
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            /*
            string cn = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
            string t1 = Routrek.SSHC.Strings.GetString("NotSSHServer");
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja");
            Routrek.SSHC.Strings.Reload();
            string t2 = Routrek.SSHC.Strings.GetString("NotSSHServer");
            */

            #if false //RSA keygen
            //RSA KEY GENERATION TEST
            byte[] testdata = Encoding.ASCII.GetBytes("CHRISTIAN VIERI");
            RSAKeyPair kp = RSAKeyPair.GenerateNew(2048, new Random());
            byte[] sig = kp.Sign(testdata);
            kp.Verify(sig, testdata);

            new SSH2UserAuthKey(kp).WritePublicPartInOpenSSHStyle(new FileStream("C:\\IOPort\\newrsakey", FileMode.Create));
            //SSH2UserAuthKey newpk = SSH2PrivateKey.FromSECSHStyleFile("C:\\IOPort\\newrsakey", "nedved");
            #endif

            #if false //DSA keygen
            //DSA KEY GENERATION TEST
            byte[] testdata = Encoding.ASCII.GetBytes("CHRISTIAN VIERI 0000");
            DSAKeyPair kp = DSAKeyPair.GenerateNew(2048, new Random());
            byte[] sig = kp.Sign(testdata);
            kp.Verify(sig, testdata);
            new SSH2UserAuthKey(kp).WritePublicPartInOpenSSHStyle(new FileStream("C:\\IOPort\\newdsakey", FileMode.Create));
            //SSH2PrivateKey newpk = SSH2PrivateKey.FromSECSHStyleFile("C:\\IOPort\\newdsakey", "nedved");
            #endif

            SSHConnectionParameter f = new SSHConnectionParameter();
            f.UserName = "******";
            #if false //SSH1
            //SSH1
            f.Password = "";
            f.Protocol = SSHProtocol.SSH2;
            f.AuthenticationType = AuthenticationType.Password;
            f.PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
            #else //SSH2
            f.Password = "";
            f.Protocol = SSHProtocol.SSH2;
            f.AuthenticationType = AuthenticationType.Password;
            f.WindowSize = 0x1000;
            #endif
            Reader reader = new Reader();
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //s.Blocking = false;
            s.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.1"), 22));
            _conn = SSHConnection.Connect(f, reader, s);
            reader._conn = _conn;
            #if false //Remote->Local
            _conn.ListenForwardedPort("0.0.0.0", 29472);
            #elif false //Local->Remote
            SSHChannel ch = _conn.ForwardPort(reader, "www.yahoo.co.jp", 80, "localhost", 0);
            reader._pf = ch;
            while(!reader._ready) System.Threading.Thread.Sleep(100);
            reader._pf.Transmit(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n\r\n"));
            #elif false //SSH over SSH
            f.Password = "******";
            SSHConnection con2 = _conn.OpenPortForwardedAnotherConnection(f, reader, "kuromatsu", 22);
            reader._conn = con2;
            SSHChannel ch = con2.OpenShell(reader);
            reader._pf = ch;
            #else //normal shell
            SSHChannel ch = _conn.OpenShell(reader);
            reader._pf = ch;
            #endif

            //Debug.WriteLine(_conn.ConnectionInfo.DumpHostKeyInKnownHostsStyle());
            SSHConnectionInfo ci = _conn.ConnectionInfo;

            Thread.Sleep(1000);
            //((SSH2Connection)_conn).ReexchangeKeys();

            byte[] b = new byte[1];
            while(true) {
                int input = System.Console.Read();

                b[0] = (byte)input;
                //Debug.WriteLine(input);
                reader._pf.Transmit(b);
            }
        }
Ejemplo n.º 9
0
 public SynchronizedSSHChannel(SSHChannel ch) {
     _channel = ch;
     _connection = _channel.Connection;
     _closed = false;
 }
Ejemplo n.º 10
0
 public void FixConnection(SSHConnection con) {
     _connection = con;
     Env.Log.LogConnectionOpened(this.ChannelProfile, _id);
 }
Ejemplo n.º 11
0
 public void AttachTransmissionSide(SSHConnection con)
 {
     _sshSocket.SetSSHConnection(con);
     if (con.AuthenticationResult == AuthenticationResult.Success) {
         SSHSocket ss = (SSHSocket)_sshSocket; //Keyboard-Interactiveがらみでちょっと不自然になってるな
         ISSHSubsystemParameter subsystem = (ISSHSubsystemParameter)_sshLoginParameter.GetAdapter(typeof(ISSHSubsystemParameter));
         if (subsystem != null)
             ss.OpenSubsystem(subsystem.SubsystemName);
         else //ふつうのシェル
             ss.OpenShell();
     }
 }
Ejemplo n.º 12
0
 public void Connect(Socket s)
 {
     _params.WindowSize = 0x1000;
     _params.IdentityFile = SSH2PrivateKeyFile;
     _conn = SSHConnection.Connect(_params, this, s);
     _pf = _conn.OpenShell(this);
     SSHConnectionInfo ci = _conn.ConnectionInfo;
 }
Ejemplo n.º 13
0
 public void AttachTransmissionSide(SSHConnection con)
 {
     _sshSocket.SetSSHConnection(con);
     if (con.AuthenticationResult == AuthenticationResult.Success) {
         SSHSocket ss = (SSHSocket)_sshSocket; //Keyboard-Interactive����݂ł�����ƕs���R�ɂȂ��Ă��
         ISSHSubsystemParameter subsystem = (ISSHSubsystemParameter)_sshLoginParameter.GetAdapter(typeof(ISSHSubsystemParameter));
         if (subsystem != null)
             ss.OpenSubsystem(subsystem.SubsystemName);
         else //�ӂ‚��̃V�F��
             ss.OpenShell();
     }
 }