Exemplo n.º 1
0
 public SSH1Channel(SSH1Connection con, ChannelType type, int local_id)
     : base(con, type, local_id)
 {
     _connection = con;
 }
Exemplo n.º 2
0
 public SSH1Channel(SSH1Connection con, ChannelType type, int local_id, int remote_id)
     : base(con, type, local_id)
 {
     _connection = con;
     _remoteID   = remote_id;
 }
Exemplo n.º 3
0
 public SSH1Channel(SSH1Connection con, ChannelType type, int local_id, int remote_id)
     : base(con, type, local_id)
 {
     _connection = con;
     _remoteID = remote_id;
 }
Exemplo n.º 4
0
 internal CallbackSSH1PacketHandler(SSH1Connection con)
 {
     _connection = con;
 }
Exemplo n.º 5
0
 public SSH1Channel(SSH1Connection con, ChannelType type, int local_id)
     : base(con, type, local_id)
 {
     _connection = con;
 }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
        /**
         * open a new SSH connection via the .NET socket
         */
        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.AuthenticationType != AuthenticationType.KeyboardInteractive && param.Password == null)
                throw new InvalidOperationException("Password property is not set");

            PlainSocket s = new PlainSocket(underlying_socket, null);
            try {
                SSHProtocolVersionReceiver protoVerReceiver = new SSHProtocolVersionReceiver();
                protoVerReceiver.Receive(s, 5000);
                protoVerReceiver.Verify(param.Protocol);

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

                s.SetHandler(con.Packetizer);
                s.RepeatAsyncRead();
                con.SendMyVersion(param);

                if (con.Connect() == AuthenticationResult.Failure) {
                    s.Close();
                    return null;
                }

                return con;
            }
            catch (Exception) {
                s.Close();
                throw;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Establish a SSH connection
        /// </summary>
        /// <param name="socket">TCP socket which is already connected to the server.</param>
        /// <param name="param">SSH connection parameter</param>
        /// <param name="connectionEventHandlerCreator">a factory function to create a connection event handler (can be null)</param>
        /// <param name="protocolEventLoggerCreator">a factory function to create a protocol log event handler (can be null)</param>
        /// <returns>new connection object</returns>
        public static ISSHConnection Connect(
                    Socket socket,
                    SSHConnectionParameter param,
                    Func<ISSHConnection, ISSHConnectionEventHandler> connectionEventHandlerCreator = null,
                    Func<ISSHConnection, ISSHProtocolEventLogger> protocolEventLoggerCreator = null)
        {
            if (socket == null) {
                throw new ArgumentNullException("socket");
            }
            if (param == null) {
                throw new ArgumentNullException("param");
            }
            if (!socket.Connected) {
                throw new ArgumentException("socket is not connected to the remote host", "socket");
            }
            if (param.UserName == null) {
                throw new ArgumentException("UserName property is not set", "param");
            }
            if (param.AuthenticationType != AuthenticationType.KeyboardInteractive && param.Password == null) {
                throw new ArgumentException("Password property is not set", "param");
            }

            string clientVersion = SSHUtil.ClientVersionString(param.Protocol);

            PlainSocket psocket = new PlainSocket(socket, null);
            try {
                // receive protocol version string
                SSHProtocolVersionReceiver protoVerReceiver = new SSHProtocolVersionReceiver();
                protoVerReceiver.Receive(psocket, 5000);
                // verify the version string
                protoVerReceiver.Verify(param.Protocol);

                ISSHConnection sshConnection;

                if (param.Protocol == SSHProtocol.SSH1) {
                    // create a connection object
                    var con = new SSH1Connection(
                                psocket,
                                param,
                                protoVerReceiver.ServerVersion,
                                clientVersion,
                                connectionEventHandlerCreator,
                                protocolEventLoggerCreator);
                    // start receiving loop
                    psocket.RepeatAsyncRead();
                    // send client version
                    con.SendMyVersion();
                    // establish a SSH connection
                    con.Connect();
                    sshConnection = con;
                }
                else {
                    // create a connection object
                    var con = new SSH2Connection(
                                psocket,
                                param,
                                protoVerReceiver.ServerVersion,
                                clientVersion,
                                connectionEventHandlerCreator,
                                protocolEventLoggerCreator);
                    // start receiving loop
                    psocket.RepeatAsyncRead();
                    // send client version
                    con.SendMyVersion();
                    // establish a SSH connection
                    con.Connect();
                    sshConnection = con;
                }

                return sshConnection;
            }
            catch (Exception) {
                psocket.Close();
                throw;
            }
        }
Exemplo n.º 9
0
 internal CallbackSSH1PacketHandler(SSH1Connection con)
 {
     _connection = con;
 }