Exemplo n.º 1
0
        //establishes a SSH connection in subject to ConnectionParameter
        public static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, StreamSocket underlying_socket)
        {
            if (param.UserName == null) throw new InvalidOperationException(resLoader.GetString("UsernameUnset"));
            if (param.Password == null) throw new InvalidOperationException(resLoader.GetString("PasswordUnset"));

            ProtocolNegotiationHandler pnh = new ProtocolNegotiationHandler(param);
            PlainSocket s = new PlainSocket(underlying_socket, pnh);
            s.RepeatAsyncRead();
            return ConnectMain(param, receiver, pnh, s);
        }
Exemplo n.º 2
0
        private static SSHConnection ConnectMain(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            pnh.Wait();

            if (pnh.State != ReceiverState.Ready) throw new Exception(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.DoConnect(s) != GranadosRT.Routrek.SSHC.AuthenticationResult.Failure)
                return con;
            else
            {
                s.Close();
                throw new Exception(Strings.GetString("AuthenticationFailed"));
                //return null;
            }
        }
Exemplo n.º 3
0
        public static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            if (param.UserName == null) throw new InvalidOperationException(resLoader.GetString("UsernameUnset"));
            if (param.Password == null) throw new InvalidOperationException(resLoader.GetString("PasswordUnset"));

            return ConnectMain(param, receiver, pnh, s);
        }
Exemplo n.º 4
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 SSH2Connection.Connect(param, receiver, pnh, s);
        }
Exemplo n.º 5
0
        public 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);
        }