/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session to authenticate.</param> /// <returns> /// Result of authentication process. /// </returns> public override AuthenticationResult Authenticate(Session session) { session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.MessageReceived += Session_MessageReceived; session.RegisterMessage("SSH_MSG_USERAUTH_PK_OK"); foreach (var keyFile in this.KeyFiles) { this._authenticationCompleted.Reset(); this._isSignatureRequired = false; var message = new RequestMessagePublicKey(ServiceName.Connection, this.Username, keyFile.HostKey.Name, keyFile.HostKey.Data); if (this.KeyFiles.Count < 2) { // If only one key file provided then send signature for very first request var signatureData = new SignatureData(message, session.SessionId).GetBytes(); message.Signature = keyFile.HostKey.Sign(signatureData); } // Send public key authentication request session.SendMessage(message); session.WaitHandle(this._authenticationCompleted); if (this._isSignatureRequired) { this._authenticationCompleted.Reset(); var signatureMessage = new RequestMessagePublicKey(ServiceName.Connection, this.Username, keyFile.HostKey.Name, keyFile.HostKey.Data); var signatureData = new SignatureData(message, session.SessionId).GetBytes(); signatureMessage.Signature = keyFile.HostKey.Sign(signatureData); // Send public key authentication request with signature session.SendMessage(signatureMessage); } session.WaitHandle(this._authenticationCompleted); if (this._authenticationResult == AuthenticationResult.Success) { break; } } session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; session.MessageReceived -= Session_MessageReceived; session.UnRegisterMessage("SSH_MSG_USERAUTH_PK_OK"); return(this._authenticationResult); }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session to authenticate.</param> /// <returns></returns> public override AuthenticationResult Authenticate(Session session) { this._session = session; session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.MessageReceived += Session_MessageReceived; session.RegisterMessage("SSH_MSG_USERAUTH_PASSWD_CHANGEREQ"); session.SendMessage(this._requestMessage); session.WaitHandle(this._authenticationCompleted); session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; session.MessageReceived -= Session_MessageReceived; if (this._exception != null) { throw this._exception; } return(this._authenticationResult); }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session to authenticate.</param> /// <returns> /// Result of authentication process. /// </returns> public override AuthenticationResult Authenticate(Session session) { session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.MessageReceived += Session_MessageReceived; session.RegisterMessage("SSH_MSG_USERAUTH_PK_OK"); foreach (var keyFile in this.KeyFiles) { this._authenticationCompleted.Reset(); this._isSignatureRequired = false; var message = new RequestMessagePublicKey(ServiceName.Connection, this.Username, keyFile.HostKey.Name, keyFile.HostKey.Data); if (this.KeyFiles.Count < 2) { // If only one key file provided then send signature for very first request var signatureData = new SignatureData(message, session.SessionId).GetBytes(); message.Signature = keyFile.HostKey.Sign(signatureData); } // Send public key authentication request session.SendMessage(message); session.WaitHandle(this._authenticationCompleted); if (this._isSignatureRequired) { this._authenticationCompleted.Reset(); var signatureMessage = new RequestMessagePublicKey(ServiceName.Connection, this.Username, keyFile.HostKey.Name, keyFile.HostKey.Data); var signatureData = new SignatureData(message, session.SessionId).GetBytes(); signatureMessage.Signature = keyFile.HostKey.Sign(signatureData); // Send public key authentication request with signature session.SendMessage(signatureMessage); } session.WaitHandle(this._authenticationCompleted); if (this._authenticationResult == AuthenticationResult.Success) { break; } } session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; session.MessageReceived -= Session_MessageReceived; session.UnRegisterMessage("SSH_MSG_USERAUTH_PK_OK"); return this._authenticationResult; }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session.</param> /// <returns></returns> public override AuthenticationResult Authenticate(Session session) { session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.SendMessage(new RequestMessageNone(ServiceName.Connection, this.Username)); session.WaitHandle(this._authenticationCompleted); session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; return this._authenticationResult; }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session.</param> /// <returns></returns> public override AuthenticationResult Authenticate(Session session) { session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.SendMessage(new RequestMessageNone(ServiceName.Connection, this.Username)); session.WaitHandle(this._authenticationCompleted); session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; return(this._authenticationResult); }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"><paramref name="session"/> is null.</exception> public override AuthenticationResult Authenticate(Session session) { if (session == null) { throw new ArgumentNullException("session"); } session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.SendMessage(new RequestMessageNone(ServiceName.Connection, this.Username)); session.WaitHandle(this._authenticationCompleted); session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; return(this._authenticationResult); }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session to authenticate.</param> /// <returns></returns> public override AuthenticationResult Authenticate(Session session) { this._session = session; session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.MessageReceived += Session_MessageReceived; session.RegisterMessage("SSH_MSG_USERAUTH_PASSWD_CHANGEREQ"); session.SendMessage(this._requestMessage); session.WaitHandle(this._authenticationCompleted); session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; session.MessageReceived -= Session_MessageReceived; if (this._exception != null) { throw this._exception; } return this._authenticationResult; }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session to authenticate.</param> /// <returns></returns> public override AuthenticationResult Authenticate(Session session) { if (this.PrivateKeyAgent.Value == null) return AuthenticationResult.Failure; session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.MessageReceived += Session_MessageReceived; session.RegisterMessage("SSH_MSG_USERAUTH_PK_OK"); foreach (var keyInfo in this.PrivateKeyAgent.Value.ListSsh2()) { var key = keyInfo.Key; this._authenticationCompleted.Reset(); this._isSignatureRequired = false; var message = new RequestMessagePublicKey(ServiceName.Connection, this.Username, key.Name, key.Data); // Send public key authentication request session.SendMessage(message); session.WaitHandle(this._authenticationCompleted); if (this._isSignatureRequired) { this._authenticationCompleted.Reset(); var signatureMessage = new RequestMessagePublicKey(ServiceName.Connection, this.Username, key.Name, key.Data); var signatureData = new SignatureData(message, session.SessionId).GetBytes(); var signature = this.PrivateKeyAgent.Value.SignSsh2(key.Data, signatureData); if (signature != null) { signatureMessage.Signature = signature; // Send public key authentication request with signature session.SendMessage(signatureMessage); } else { this._authenticationResult = AuthenticationResult.Failure; this._authenticationCompleted.Set(); } } session.WaitHandle(this._authenticationCompleted); if (this._authenticationResult == AuthenticationResult.Success) { break; } } session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; session.MessageReceived -= Session_MessageReceived; session.UnRegisterMessage("SSH_MSG_USERAUTH_PK_OK"); return this._authenticationResult; }
/// <summary> /// Authenticates the specified session. /// </summary> /// <param name="session">The session to authenticate.</param> /// <returns></returns> public override AuthenticationResult Authenticate(Session session) { if (this.PrivateKeyAgent.Value == null) { return(AuthenticationResult.Failure); } session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived; session.MessageReceived += Session_MessageReceived; session.RegisterMessage("SSH_MSG_USERAUTH_PK_OK"); foreach (var keyInfo in this.PrivateKeyAgent.Value.ListSsh2()) { var key = keyInfo.Key; this._authenticationCompleted.Reset(); this._isSignatureRequired = false; var message = new RequestMessagePublicKey(ServiceName.Connection, this.Username, key.Name, key.Data); // Send public key authentication request session.SendMessage(message); session.WaitHandle(this._authenticationCompleted); if (this._isSignatureRequired) { this._authenticationCompleted.Reset(); var signatureMessage = new RequestMessagePublicKey(ServiceName.Connection, this.Username, key.Name, key.Data); var signatureData = new SignatureData(message, session.SessionId).GetBytes(); var signature = this.PrivateKeyAgent.Value.SignSsh2(key.Data, signatureData); if (signature != null) { signatureMessage.Signature = signature; // Send public key authentication request with signature session.SendMessage(signatureMessage); } else { this._authenticationResult = AuthenticationResult.Failure; this._authenticationCompleted.Set(); } } session.WaitHandle(this._authenticationCompleted); if (this._authenticationResult == AuthenticationResult.Success) { break; } } session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived; session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived; session.MessageReceived -= Session_MessageReceived; session.UnRegisterMessage("SSH_MSG_USERAUTH_PK_OK"); return(this._authenticationResult); }