RequestMessagePublicKey.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. namespace Renci.SshNet.Messages.Authentication
  2. {
  3. /// <summary>
  4. /// Represents "publickey" SSH_MSG_USERAUTH_REQUEST message.
  5. /// </summary>
  6. public class RequestMessagePublicKey : 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 "publickey";
  19. }
  20. }
  21. /// <summary>
  22. /// Gets the name of the public key algorithm.
  23. /// </summary>
  24. /// <value>
  25. /// The name of the public key algorithm.
  26. /// </value>
  27. public string PublicKeyAlgorithmName { get; private set; }
  28. /// <summary>
  29. /// Gets the public key data.
  30. /// </summary>
  31. public byte[] PublicKeyData { get; private set; }
  32. /// <summary>
  33. /// Gets or sets public key signature.
  34. /// </summary>
  35. /// <value>
  36. /// The signature.
  37. /// </value>
  38. public byte[] Signature { get; set; }
  39. /// <summary>
  40. /// Initializes a new instance of the <see cref="RequestMessagePublicKey"/> class.
  41. /// </summary>
  42. /// <param name="serviceName">Name of the service.</param>
  43. /// <param name="username">Authentication username.</param>
  44. /// <param name="keyAlgorithmName">Name of private key algorithm.</param>
  45. /// <param name="keyData">Private key data.</param>
  46. public RequestMessagePublicKey(ServiceName serviceName, string username, string keyAlgorithmName, byte[] keyData)
  47. : base(serviceName, username)
  48. {
  49. this.PublicKeyAlgorithmName = keyAlgorithmName;
  50. this.PublicKeyData = keyData;
  51. }
  52. /// <summary>
  53. /// Initializes a new instance of the <see cref="RequestMessagePublicKey"/> class.
  54. /// </summary>
  55. /// <param name="serviceName">Name of the service.</param>
  56. /// <param name="username">Authentication username.</param>
  57. /// <param name="keyAlgorithmName">Name of private key algorithm.</param>
  58. /// <param name="keyData">Private key data.</param>
  59. /// <param name="signature">Private key signature.</param>
  60. public RequestMessagePublicKey(ServiceName serviceName, string username, string keyAlgorithmName, byte[] keyData, byte[] signature)
  61. : this(serviceName, username, keyAlgorithmName, keyData)
  62. {
  63. this.Signature = signature;
  64. }
  65. /// <summary>
  66. /// Called when type specific data need to be saved.
  67. /// </summary>
  68. protected override void SaveData()
  69. {
  70. base.SaveData();
  71. if (this.Signature == null)
  72. {
  73. this.Write(false);
  74. }
  75. else
  76. {
  77. this.Write(true);
  78. }
  79. this.WriteAscii(this.PublicKeyAlgorithmName);
  80. this.WriteBinaryString(this.PublicKeyData);
  81. if (this.Signature != null)
  82. this.WriteBinaryString(this.Signature);
  83. }
  84. }
  85. }