예제 #1
0
        public Entry RegisterChannelEventReceiver(SSHChannel ch, ISSHChannelEventReceiver r) {
            lock (this) {
                Entry e = new Entry(ch, r, _channel_sequence++);

                if (_first == null)
                    _first = e;
                else {
                    e.Next = _first;
                    _first = e;
                }

                _count++;
                return e;
            }
        }
예제 #2
0
 public SshTunnelStream(SSHChannel channel)
 {
     this.m_Channel = channel;
 }
예제 #3
0
 internal void RegisterChannel(int local_id, SSHChannel ch) {
     FindChannelEntry(local_id).Channel = ch;
 }
예제 #4
0
 public void EstablishPortforwarding(ISSHChannelEventReceiver rec, SSHChannel channel)
 {
   this.m_Channel = channel;
 }
예제 #5
0
 public Entry(SSHChannel ch, ISSHChannelEventReceiver r, int seq) {
     _channel = ch;
     _receiver = r;
     _localID = seq;
 }
예제 #6
0
    /// <summary>
    /// Connect to remote host:port over SSH tunnel
    /// </summary>
    public void Connect(string host, int port, int timeout)
    {
      try
      {
        //remember remote target
        m_RemoteTarget = new IPEndPoint(ResolveHost(host), port);

        //connect to SSH server
        if (!connectAsync(m_RemoteTarget.Address, SSHServerPort).Wait(timeout))
          throw new ErlException(ERL_CONN_CANT_CONNECT_TO_HOST_ERROR.Args("SSH", host, port));

        //get password from user
        var pass                 = ErlTransportPasswordSource.GetPassword(this, NodeName, SSHUserName);

        //set params
        var param                = new SSHConnectionParameter();
        param.EventTracer        = this; //to receive detailed events
        param.UserName           = SSHUserName;
        param.Password           = pass;
        param.Protocol           = SSHProtocol.SSH2;
        param.AuthenticationType = (AuthenticationType)
                                   Enum.Parse(typeof (SSH.AuthenticationType), SSHAuthenticationType);

        if (param.AuthenticationType == AuthenticationType.PublicKey)
          param.IdentityFile = SSHPrivateKeyFilePath;

        //former algorithm is given priority in the algorithm negotiation
        param.PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[]
                                            {PublicKeyAlgorithm.RSA, PublicKeyAlgorithm.DSA};
        param.PreferableCipherAlgorithms  = new CipherAlgorithm[]
        {
          CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES, CipherAlgorithm.AES192CTR,
          CipherAlgorithm.AES256CTR, CipherAlgorithm.AES128CTR
        };

        param.WindowSize            = 0x1000; //this option is ignored with SSH1

        //Creating a new SSH connection over the underlying socket
        m_Connection                = SSHConnection.Connect(param, this, m_Client);
        m_Connection.AutoDisconnect = true;
        m_IsChannelReady            = 0;

        //Local->Remote port forwarding (we use localhost:0 as local port, because local port is not required for us, we will use this tunnel directly)
        m_Channel = m_Connection.ForwardPort(this, host, port, "localhost", 0);
        var deadLine = DateTime.Now.AddMilliseconds(timeout);
        while (m_IsChannelReady == 0 && deadLine > DateTime.Now)
          System.Threading.Thread.Sleep(50); //wait response

        //if timeouted - throw exception
        if (m_IsChannelReady <= 0)
          throw new ErlException(ERL_CREATE_SSH_TUNNEL_ERROR);

        //create network stream
        m_Stream = new SshTunnelStream(m_Channel);

        //Remote->Local
        // if you want to listen to a port on the SSH server, follow this line:
        //_conn.ListenForwardedPort("0.0.0.0", 10000);

        //NOTE: if you use SSH2, dynamic key exchange feature is supported.
        //((SSH2Connection)_conn).ReexchangeKeys();
      }
      catch (Exception ex)
      {
        OnTrace(ErlTraceLevel.Ctrl, Direction.Inbound, ex.Message);
        throw;
      }
    }
예제 #7
0
 internal void SetChannel(SSHChannel channel) {
     _channel = channel;
 }
예제 #8
0
파일: SCP.cs 프로젝트: PavelTorgashov/nfx
        public override void Run(SSHChannel channel) {
            _channel = channel;

            try {
                WaitAndReset();
                Debug.Assert(_state == State.Failed || _state == State.WaitingFileInfoResponse);
                if (_state == State.Failed)
                    return;

                TransmitFileInfo();
                WaitAndReset();
                Debug.Assert(_state == State.Failed || _state == State.SendingContent);
                if (_state == State.Failed)
                    return;

                TransmitFileContent();
                WaitAndReset();
                Debug.Assert(_state == State.Failed || _state == State.Completed);

                if (_state == State.Completed) {
                    SuccessfullyExit();
                }
            }
            catch (Exception ex) {
                UnsuccessfullyExit(ex);
            }
            finally {
                _param.LocalSource.Close();
            }
        }
예제 #9
0
파일: SCP.cs 프로젝트: PavelTorgashov/nfx
 public override void Run(SSHChannel channel) {
     _channel = channel;
     _channelReadyEvent.WaitOne();
     SendResponse(); //これでやりとりがはじまる
 }
예제 #10
0
파일: SCP.cs 프로젝트: PavelTorgashov/nfx
 public abstract void Run(SSHChannel channel); //start scp operation