RequestMessagePassword.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. namespace Renci.SshNet.Messages.Authentication
  2. {
  3. /// <summary>
  4. /// Represents "password" SSH_MSG_USERAUTH_REQUEST message.
  5. /// </summary>
  6. internal class RequestMessagePassword : RequestMessage
  7. {
  8. /// <summary>
  9. /// Gets the name of the authentication method.
  10. /// </summary>
  11. /// <value>
  12. /// The name of the method.
  13. /// </value>
  14. public override string MethodName
  15. {
  16. get
  17. {
  18. return "password";
  19. }
  20. }
  21. /// <summary>
  22. /// Gets authentication password.
  23. /// </summary>
  24. public byte[] Password { get; private set; }
  25. /// <summary>
  26. /// Gets new authentication password.
  27. /// </summary>
  28. public byte[] NewPassword { get; private set; }
  29. /// <summary>
  30. /// Initializes a new instance of the <see cref="RequestMessagePassword"/> class.
  31. /// </summary>
  32. /// <param name="serviceName">Name of the service.</param>
  33. /// <param name="username">Authentication username.</param>
  34. /// <param name="password">Authentication password.</param>
  35. public RequestMessagePassword(ServiceName serviceName, string username, byte[] password)
  36. : base(serviceName, username)
  37. {
  38. this.Password = password;
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="RequestMessagePassword"/> class.
  42. /// </summary>
  43. /// <param name="serviceName">Name of the service.</param>
  44. /// <param name="username">Authentication username.</param>
  45. /// <param name="password">Authentication password.</param>
  46. /// <param name="newPassword">New authentication password.</param>
  47. public RequestMessagePassword(ServiceName serviceName, string username, byte[] password, byte[] newPassword)
  48. : this(serviceName, username, password)
  49. {
  50. this.NewPassword = newPassword;
  51. }
  52. /// <summary>
  53. /// Called when type specific data need to be saved.
  54. /// </summary>
  55. protected override void SaveData()
  56. {
  57. base.SaveData();
  58. this.Write(this.NewPassword != null);
  59. this.Write((uint)this.Password.Length);
  60. this.Write(this.Password);
  61. if (this.NewPassword != null)
  62. {
  63. this.Write((uint)this.NewPassword.Length);
  64. this.Write(this.NewPassword);
  65. }
  66. }
  67. }
  68. }