FailureMessage.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. namespace Renci.SshNet.Messages.Authentication
  3. {
  4. /// <summary>
  5. /// Represents SSH_MSG_USERAUTH_FAILURE message.
  6. /// </summary>
  7. public class FailureMessage : Message
  8. {
  9. /// <inheritdoc />
  10. public override string MessageName
  11. {
  12. get
  13. {
  14. return "SSH_MSG_USERAUTH_FAILURE";
  15. }
  16. }
  17. /// <inheritdoc />
  18. public override byte MessageNumber
  19. {
  20. get
  21. {
  22. return 51;
  23. }
  24. }
  25. /// <summary>
  26. /// Gets or sets the allowed authentications if available.
  27. /// </summary>
  28. /// <value>
  29. /// The allowed authentications.
  30. /// </value>
  31. public string[] AllowedAuthentications { get; set; }
  32. /// <summary>
  33. /// Gets failure message.
  34. /// </summary>
  35. public string Message { get; private set; }
  36. /// <summary>
  37. /// Gets a value indicating whether authentication is partially successful.
  38. /// </summary>
  39. /// <value>
  40. /// <see langword="true"/> if partially successful; otherwise, <see langword="false"/>.
  41. /// </value>
  42. public bool PartialSuccess { get; private set; }
  43. /// <summary>
  44. /// Called when type specific data need to be loaded.
  45. /// </summary>
  46. protected override void LoadData()
  47. {
  48. AllowedAuthentications = ReadNamesList();
  49. PartialSuccess = ReadBoolean();
  50. if (PartialSuccess)
  51. {
  52. #if NET || NETSTANDARD2_1_OR_GREATER
  53. Message = string.Join(',', AllowedAuthentications);
  54. #else
  55. Message = string.Join(",", AllowedAuthentications);
  56. #endif // NET || NETSTANDARD2_1_OR_GREATER
  57. }
  58. }
  59. /// <summary>
  60. /// Called when type specific data need to be saved.
  61. /// </summary>
  62. protected override void SaveData()
  63. {
  64. throw new NotImplementedException();
  65. }
  66. internal override void Process(Session session)
  67. {
  68. session.OnUserAuthenticationFailureReceived(this);
  69. }
  70. /// <inheritdoc/>
  71. public override string ToString()
  72. {
  73. return $"SSH_MSG_USERAUTH_FAILURE {string.Join(",", AllowedAuthentications)} ({nameof(PartialSuccess)}:{PartialSuccess})";
  74. }
  75. }
  76. }