RequestMessageHost.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Text;
  2. namespace Renci.SshNet.Messages.Authentication
  3. {
  4. /// <summary>
  5. /// Represents "hostbased" SSH_MSG_USERAUTH_REQUEST message.
  6. /// </summary>
  7. internal class RequestMessageHost : RequestMessage
  8. {
  9. /// <summary>
  10. /// Gets the name of the authentication method.
  11. /// </summary>
  12. /// <value>
  13. /// The name of the method.
  14. /// </value>
  15. public override string MethodName
  16. {
  17. get
  18. {
  19. return "hostbased";
  20. }
  21. }
  22. /// <summary>
  23. /// Gets the public key algorithm for host key
  24. /// </summary>
  25. public string PublicKeyAlgorithm { get; private set; }
  26. /// <summary>
  27. /// Gets or sets the public host key and certificates for client host.
  28. /// </summary>
  29. /// <value>
  30. /// The public host key.
  31. /// </value>
  32. public byte[] PublicHostKey { get; private set; }
  33. /// <summary>
  34. /// Gets or sets the name of the client host.
  35. /// </summary>
  36. /// <value>
  37. /// The name of the client host.
  38. /// </value>
  39. public string ClientHostName { get; private set; }
  40. /// <summary>
  41. /// Gets or sets the client username on the client host
  42. /// </summary>
  43. /// <value>
  44. /// The client username.
  45. /// </value>
  46. public string ClientUsername { get; private set; }
  47. /// <summary>
  48. /// Gets or sets the signature.
  49. /// </summary>
  50. /// <value>
  51. /// The signature.
  52. /// </value>
  53. public byte[] Signature { get; set; }
  54. /// <summary>
  55. /// Initializes a new instance of the <see cref="RequestMessageHost"/> class.
  56. /// </summary>
  57. /// <param name="serviceName">Name of the service.</param>
  58. /// <param name="username">Authentication username.</param>
  59. /// <param name="publicKeyAlgorithm">The public key algorithm.</param>
  60. /// <param name="publicHostKey">The public host key.</param>
  61. /// <param name="clientHostName">Name of the client host.</param>
  62. /// <param name="clientUsername">The client username.</param>
  63. public RequestMessageHost(ServiceName serviceName, string username, string publicKeyAlgorithm, byte[] publicHostKey, string clientHostName, string clientUsername)
  64. : base(serviceName, username)
  65. {
  66. this.PublicKeyAlgorithm = publicKeyAlgorithm;
  67. this.PublicHostKey = publicHostKey;
  68. this.ClientHostName = clientHostName;
  69. this.ClientUsername = clientUsername;
  70. }
  71. /// <summary>
  72. /// Called when type specific data need to be saved.
  73. /// </summary>
  74. protected override void SaveData()
  75. {
  76. base.SaveData();
  77. this.WriteAscii(this.PublicKeyAlgorithm);
  78. this.WriteBinaryString(this.PublicHostKey);
  79. this.Write(this.ClientHostName);
  80. this.Write(this.ClientUsername);
  81. if (this.Signature != null)
  82. this.WriteBinaryString(this.Signature);
  83. }
  84. }
  85. }