Пример #1
0
 public KeyExchanger(SSH2Connection con, byte[] sessionID)
 {
     _con = con;
     _param = con.Param;
     _cInfo = (SSH2ConnectionInfo)con.ConnectionInfo;
     _sessionID = sessionID;
     _status = Status.INITIAL;
 }
Пример #2
0
 private static void SendMyVersion(AbstractSocket stream, SSHConnectionParameter param)
 {
     string cv = SSHUtil.ClientVersionString(param.Protocol);
     if(param.Protocol==SSHProtocol.SSH1)
         cv += param.SSH1VersionEOL;
     else
         cv += "\r\n";
     byte[] data = Encoding.ASCII.GetBytes(cv);
     stream.Write(data, 0, data.Length);
 }
Пример #3
0
        public SSH2Connection(SSHConnectionParameter param, ISSHConnectionEventReceiver r, string serverversion, string clientversion)
            : base(param, r)
        {
            _cInfo = new SSH2ConnectionInfo();
            _cInfo._serverVersionString = serverversion;
            _cInfo._clientVersionString = clientversion;

            _packetBuilder = new SSH2PacketBuilder(new SynchronizedSSH2PacketHandler());
        }
Пример #4
0
        internal static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            if(param.UserName==null) throw new InvalidOperationException("UserName property is not set");
            if(param.Password==null) throw new InvalidOperationException("Password property is not set");

            return ConnectMain(param, receiver, pnh, s);
        }
Пример #5
0
        private static SSHConnection ConnectMain(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            pnh.Wait();

            if(pnh.State!=ReceiverState.Ready) throw new SSHException(pnh.ErrorMessage);

            string sv = pnh.ServerVersion;

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

            s.SetHandler(con.PacketBuilder);
            SendMyVersion(s, param);

            if(con.Connect(s)!=AuthenticationResult.Failure)
                return con;
            else {
                s.Close();
                return null;
            }
        }
Пример #6
0
        //establishes a SSH connection in subject to ConnectionParameter
        public static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, Socket underlying_socket)
        {
            if(param.UserName==null) throw new InvalidOperationException("UserName property is not set");
            if(param.Password==null) throw new InvalidOperationException("Password property is not set");

            ProtocolNegotiationHandler pnh = new ProtocolNegotiationHandler(param);
            PlainSocket s = new PlainSocket(underlying_socket, pnh);
            s.RepeatAsyncRead();
            return ConnectMain(param, receiver, pnh, s);
        }
Пример #7
0
        /**
         * opens another SSH connection via port-forwarded connection
         */
        public SSHConnection OpenPortForwardedAnotherConnection(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, string host, int port)
        {
            ProtocolNegotiationHandler pnh = new ProtocolNegotiationHandler(param);
            ChannelSocket s = new ChannelSocket(pnh);

            SSHChannel ch = ForwardPort(s, host, port, "localhost", 0);
            s.SSHChennal = ch;
            return SSHConnection.Connect(param, receiver, pnh, s);
        }
Пример #8
0
        protected override void Negotiate()
        {
            SSHConnectionParameter con = new SSHConnectionParameter();
            con.Protocol = _param.Method==ConnectionMethod.SSH1? SSHProtocol.SSH1 : SSHProtocol.SSH2;
            con.CheckMACError = GEnv.Options.SSHCheckMAC;
            con.UserName = _param.Account;
            con.Password = _password;
            con.AuthenticationType = _param.AuthType==AuthType.KeyboardInteractive? AuthenticationType.KeyboardInteractive : _param.AuthType==AuthType.Password? AuthenticationType.Password : AuthenticationType.PublicKey;
            con.IdentityFile = _param.IdentityFile;
            con.TerminalWidth = _size.Width;
            con.TerminalHeight = _size.Height;
            con.TerminalName = EnumDescAttribute.For(typeof(TerminalType)).GetDescription(_param.TerminalType);
            con.WindowSize = GEnv.Options.SSHWindowSize;
            con.PreferableCipherAlgorithms = LocalSSHUtil.ParseCipherAlgorithm(GEnv.Options.CipherAlgorithmOrder);
            con.PreferableHostKeyAlgorithms = LocalSSHUtil.ParsePublicKeyAlgorithm(GEnv.Options.HostKeyAlgorithmOrder);
            if(_keycheck!=null) con.KeyCheck += new HostKeyCheckCallback(this.CheckKey);

            SSHTerminalConnection r = new SSHTerminalConnection(_param, _size.Width, _size.Height);
            SSHConnection ssh = SSHConnection.Connect(con, r, _socket);
            if(ssh!=null) {
                if(GEnv.Options.RetainsPassphrase)
                    _param.Passphrase = _password; //�ڑ��������̂݃Z�b�g
                r.FixConnection(ssh);
                if(ssh.AuthenticationResult==AuthenticationResult.Success) r.OpenShell();
                r.UsingSocks = _socks!=null;
                r.SetServerInfo(_param.Host, this.IPAddress);
                _result = new ConnectionTag(r);
            }
            else {
                throw new IOException(GEnv.Strings.GetString("Message.SSHConnector.Cancelled"));
            }
        }
Пример #9
0
 protected SSHConnection(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver)
 {
     _param = (SSHConnectionParameter)param.Clone();
     _eventReceiver = receiver;
     _channel_entries = new ArrayList(16);
     _autoDisconnect = true;
 }
Пример #10
0
        protected override void Negotiate()
        {
            SSHConnectionParameter con = new SSHConnectionParameter();
            con.Protocol = SSHProtocol.SSH2;
            con.UserName = _profile.SSHAccount;
            con.Password = _password;
            con.AuthenticationType = _profile.AuthType;
            con.IdentityFile = _profile.PrivateKeyFile;
            con.PreferableCipherAlgorithms = SSHUtil.ParseCipherAlgorithm(Env.Options.CipherAlgorithmOrder);
            con.PreferableHostKeyAlgorithms = SSHUtil.ParsePublicKeyAlgorithm(Env.Options.HostKeyAlgorithmOrder);
            con.WindowSize = Env.Options.SSHWindowSize;
            con.CheckMACError = Env.Options.SSHCheckMAC;
            if(_keycheck!=null) con.KeyCheck += new HostKeyCheckCallback(this.CheckKey);

            _result = ChannelFactory.Create(_profile);
            SSHConnection c = SSHConnection.Connect(con, _result, _socket);
            c.AutoDisconnect = false;
            if(c!=null) {
                /*
                if(_profile.ProtocolType==ProtocolType.Udp)
                    OpenUdpDestination(c, (UdpChannelFactory)_result);
                else
                */
                _result.FixConnection(c);
                if(Env.Options.RetainsPassphrase)
                    _profile.Passphrase = _password; //�ڑ��������̂݃Z�b�g
            }
            else {
                throw new IOException(Env.Strings.GetString("Message.ConnectionManager.ConnectionCancelled"));
            }
        }
Пример #11
0
        static void Main(string[] args)
        {
            /*
            string cn = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
            string t1 = Granados.SSHC.Strings.GetString("NotSSHServer");
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja");
            Granados.SSHC.Strings.Reload();
            string t2 = Granados.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);
            }
        }
Пример #12
0
 public ProtocolNegotiationHandler(SSHConnectionParameter param)
 {
     _param = param;
     _errorMessage = Strings.GetString("NotSSHServer");
 }
Пример #13
0
 public object Clone()
 {
     SSHConnectionParameter n = new SSHConnectionParameter();
     n._authtype = _authtype;
     n._cipherAlgorithms = _cipherAlgorithms;
     n._height = _height;
     n._hostkeyAlgorithms = _hostkeyAlgorithms;
     n._identityFile = _identityFile;
     n._keycheck = _keycheck;
     n._maxpacketsize = _maxpacketsize;
     n._password = _password;
     n._protocol = _protocol;
     n._random = _random;
     n._terminalname = _terminalname;
     n._username = _username;
     n._width = _width;
     n._windowsize = _windowsize;
     n._checkMACError = _checkMACError;
     return n;
 }
Пример #14
0
 public ProtocolNegotiationHandler(SSHConnectionParameter param)
 {
     _param        = param;
     _errorMessage = Strings.GetString("NotSSHServer");
 }