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(); return(null); } }
public void Disconnect(string msg) { if (_closed) { return; } SSH1DataWriter w = new SSH1DataWriter(); w.Write(msg); SSH1Packet p = SSH1Packet.FromPlainPayload(PacketType.SSH_MSG_DISCONNECT, w.ToByteArray()); p.WriteTo(_stream, _tCipher); _stream.Flush(); _closed = true; _stream.Close(); }
internal override AuthenticationResult Connect(AbstractSocket s) { _stream = s; // Phase2 receives server keys ReceiveServerKeys(); if (_param.KeyCheck != null && !_param.KeyCheck(_cInfo)) { _stream.Close(); return(AuthenticationResult.Failure); } // Phase3 generates session key byte[] session_key = GenerateSessionKey(); // Phase4 establishes the session key try { _packetBuilder.SetSignal(false); SendSessionKey(session_key); InitCipher(session_key); } finally { _packetBuilder.SetSignal(true); } ReceiveKeyConfirmation(); // Phase5 user authentication SendUserName(_param.UserName); if (ReceiveAuthenticationRequirement() == AUTH_REQUIRED) { if (_param.AuthenticationType == AuthenticationType.Password) { SendPlainPassword(); } else if (_param.AuthenticationType == AuthenticationType.PublicKey) { DoRSAChallengeResponse(); } bool auth = ReceiveAuthenticationResult(); if (!auth) { throw new SSHException(Strings.GetString("AuthenticationFailed")); } } _packetBuilder.Handler = new CallbackSSH1PacketHandler(this); return(AuthenticationResult.Success); }
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; } }
public AuthenticationResult DoConnect(AbstractSocket target) { _stream = target; KeyExchanger kex = new KeyExchanger(this, null); if(!kex.SynchronousKexExchange()) { _stream.Close(); return GranadosRT.Routrek.SSHC.AuthenticationResult.Failure; } //Step3 user authentication ServiceRequest("ssh-userauth"); _authenticationResult = UserAuth(); return _authenticationResult; }
public AuthenticationResult DoConnect(AbstractSocket target) { _stream = target; // Phase2 receives server keys ReceiveServerKeys(); if(_param.KeyCheck!=null && !_param.KeyCheck(_cInfo)) { _stream.Close(); return GranadosRT.Routrek.SSHC.AuthenticationResult.Failure; } // Phase3 generates session key byte[] session_key = GenerateSessionKey(); // Phase4 establishes the session key try { _packetBuilder.SetSignal(false); SendSessionKey(session_key); InitCipher(session_key); } finally { _packetBuilder.SetSignal(true); } ReceiveKeyConfirmation(); // Phase5 user authentication SendUserName(_param.UserName); if(ReceiveAuthenticationRequirement()==AUTH_REQUIRED) { if(_param.AuthenticationType==AuthenticationType.Password) { SendPlainPassword(); } else if(_param.AuthenticationType==AuthenticationType.PublicKey) { DoRSAChallengeResponse(); } bool auth = ReceiveAuthenticationResult(); if(!auth) throw new Exception(Strings.GetString("AuthenticationFailed")); } _packetBuilder.Handler = new CallbackSSH1PacketHandler(this); return GranadosRT.Routrek.SSHC.AuthenticationResult.Success; }