| | | 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 public key algorithm as ASCII encoded byte array. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <value> |
| | | 12 | | /// The name of the public key algorithm. |
| | | 13 | | /// </value> |
| | 6816 | 14 | | public byte[] PublicKeyAlgorithmName { get; private set; } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets the public key data. |
| | | 18 | | /// </summary> |
| | 5452 | 19 | | public byte[] PublicKeyData { get; private set; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets or sets public key signature. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <value> |
| | | 25 | | /// The signature. |
| | | 26 | | /// </value> |
| | 7496 | 27 | | public byte[] Signature { get; set; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the size of the message in bytes. |
| | | 31 | | /// </summary> |
| | | 32 | | /// <value> |
| | | 33 | | /// The size of the messages in bytes. |
| | | 34 | | /// </value> |
| | | 35 | | protected override int BufferCapacity |
| | | 36 | | { |
| | | 37 | | get |
| | 1364 | 38 | | { |
| | 1364 | 39 | | var capacity = base.BufferCapacity; |
| | 1364 | 40 | | capacity += 1; // Signature flag |
| | 1364 | 41 | | capacity += 4; // PublicKeyAlgorithmName length |
| | 1364 | 42 | | capacity += PublicKeyAlgorithmName.Length; // PublicKeyAlgorithmName |
| | 1364 | 43 | | capacity += 4; // PublicKeyData length |
| | 1364 | 44 | | capacity += PublicKeyData.Length; // PublicKeyData |
| | | 45 | | |
| | 1364 | 46 | | if (Signature != null) |
| | 680 | 47 | | { |
| | 680 | 48 | | capacity += 4; // Signature length |
| | 680 | 49 | | capacity += Signature.Length; // Signature |
| | 680 | 50 | | } |
| | | 51 | | |
| | 1364 | 52 | | return capacity; |
| | 1364 | 53 | | } |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Initializes a new instance of the <see cref="RequestMessagePublicKey"/> class. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <param name="serviceName">Name of the service.</param> |
| | | 60 | | /// <param name="username">Authentication username.</param> |
| | | 61 | | /// <param name="keyAlgorithmName">Name of private key algorithm.</param> |
| | | 62 | | /// <param name="keyData">Private key data.</param> |
| | | 63 | | public RequestMessagePublicKey(ServiceName serviceName, string username, string keyAlgorithmName, byte[] keyData |
| | 1364 | 64 | | : base(serviceName, username, "publickey") |
| | 1364 | 65 | | { |
| | 1364 | 66 | | PublicKeyAlgorithmName = Ascii.GetBytes(keyAlgorithmName); |
| | 1364 | 67 | | PublicKeyData = keyData; |
| | 1364 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Initializes a new instance of the <see cref="RequestMessagePublicKey"/> class. |
| | | 72 | | /// </summary> |
| | | 73 | | /// <param name="serviceName">Name of the service.</param> |
| | | 74 | | /// <param name="username">Authentication username.</param> |
| | | 75 | | /// <param name="keyAlgorithmName">Name of private key algorithm.</param> |
| | | 76 | | /// <param name="keyData">Private key data.</param> |
| | | 77 | | /// <param name="signature">Private key signature.</param> |
| | | 78 | | public RequestMessagePublicKey(ServiceName serviceName, string username, string keyAlgorithmName, byte[] keyData |
| | 0 | 79 | | : this(serviceName, username, keyAlgorithmName, keyData) |
| | 0 | 80 | | { |
| | 0 | 81 | | Signature = signature; |
| | 0 | 82 | | } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Called when type specific data need to be saved. |
| | | 86 | | /// </summary> |
| | | 87 | | protected override void SaveData() |
| | 1364 | 88 | | { |
| | 1364 | 89 | | base.SaveData(); |
| | | 90 | | |
| | 1364 | 91 | | Write(Signature != null); |
| | 1364 | 92 | | WriteBinaryString(PublicKeyAlgorithmName); |
| | 1364 | 93 | | WriteBinaryString(PublicKeyData); |
| | 1364 | 94 | | if (Signature != null) |
| | 680 | 95 | | { |
| | 680 | 96 | | WriteBinaryString(Signature); |
| | 680 | 97 | | } |
| | 1364 | 98 | | } |
| | | 99 | | |
| | | 100 | | /// <inheritdoc/> |
| | | 101 | | public override string ToString() |
| | 1364 | 102 | | { |
| | 1364 | 103 | | return $"{base.ToString()} {Ascii.GetString(PublicKeyAlgorithmName)} {(Signature != null ? "with" : "without |
| | 1364 | 104 | | } |
| | | 105 | | } |
| | | 106 | | } |