| | | 1 | | namespace Renci.SshNet.Messages.Authentication |
| | | 2 | | { |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents "hostbased" SSH_MSG_USERAUTH_REQUEST message. |
| | | 5 | | /// </summary> |
| | | 6 | | internal sealed class RequestMessageHost : RequestMessage |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Gets the public key algorithm for host key as ASCII encoded byte array. |
| | | 10 | | /// </summary> |
| | 0 | 11 | | public byte[] PublicKeyAlgorithm { get; } |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Gets the public host key and certificates for client host. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <value> |
| | | 17 | | /// The public host key. |
| | | 18 | | /// </value> |
| | 0 | 19 | | public byte[] PublicHostKey { get; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the name of the client host as ASCII encoded byte array. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <value> |
| | | 25 | | /// The name of the client host. |
| | | 26 | | /// </value> |
| | 0 | 27 | | public byte[] ClientHostName { get; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the client username on the client host as UTF-8 encoded byte array. |
| | | 31 | | /// </summary> |
| | | 32 | | /// <value> |
| | | 33 | | /// The client username. |
| | | 34 | | /// </value> |
| | 0 | 35 | | public byte[] ClientUsername { get; } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the signature. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <value> |
| | | 41 | | /// The signature. |
| | | 42 | | /// </value> |
| | 0 | 43 | | public byte[] Signature { get; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets the size of the message in bytes. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <value> |
| | | 49 | | /// The size of the messages in bytes. |
| | | 50 | | /// </value> |
| | | 51 | | protected override int BufferCapacity |
| | | 52 | | { |
| | | 53 | | get |
| | 0 | 54 | | { |
| | 0 | 55 | | var capacity = base.BufferCapacity; |
| | 0 | 56 | | capacity += 4; // PublicKeyAlgorithm length |
| | 0 | 57 | | capacity += PublicKeyAlgorithm.Length; // PublicKeyAlgorithm |
| | 0 | 58 | | capacity += 4; // PublicHostKey length |
| | 0 | 59 | | capacity += PublicHostKey.Length; // PublicHostKey |
| | 0 | 60 | | capacity += 4; // ClientHostName length |
| | 0 | 61 | | capacity += ClientHostName.Length; // ClientHostName |
| | 0 | 62 | | capacity += 4; // ClientUsername length |
| | 0 | 63 | | capacity += ClientUsername.Length; // ClientUsername |
| | 0 | 64 | | capacity += 4; // Signature length |
| | 0 | 65 | | capacity += Signature.Length; // Signature |
| | 0 | 66 | | return capacity; |
| | 0 | 67 | | } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Initializes a new instance of the <see cref="RequestMessageHost"/> class. |
| | | 72 | | /// </summary> |
| | | 73 | | /// <param name="serviceName">Name of the service.</param> |
| | | 74 | | /// <param name="username">Authentication username.</param> |
| | | 75 | | /// <param name="publicKeyAlgorithm">The public key algorithm.</param> |
| | | 76 | | /// <param name="publicHostKey">The public host key.</param> |
| | | 77 | | /// <param name="clientHostName">Name of the client host.</param> |
| | | 78 | | /// <param name="clientUsername">The client username.</param> |
| | | 79 | | /// <param name="signature">The signature.</param> |
| | | 80 | | public RequestMessageHost(ServiceName serviceName, string username, string publicKeyAlgorithm, byte[] publicHost |
| | 0 | 81 | | : base(serviceName, username, "hostbased") |
| | 0 | 82 | | { |
| | 0 | 83 | | PublicKeyAlgorithm = Ascii.GetBytes(publicKeyAlgorithm); |
| | 0 | 84 | | PublicHostKey = publicHostKey; |
| | 0 | 85 | | ClientHostName = Ascii.GetBytes(clientHostName); |
| | 0 | 86 | | ClientUsername = Utf8.GetBytes(clientUsername); |
| | 0 | 87 | | Signature = signature; |
| | 0 | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Called when type specific data need to be saved. |
| | | 92 | | /// </summary> |
| | | 93 | | protected override void SaveData() |
| | 0 | 94 | | { |
| | 0 | 95 | | base.SaveData(); |
| | | 96 | | |
| | 0 | 97 | | WriteBinaryString(PublicKeyAlgorithm); |
| | 0 | 98 | | WriteBinaryString(PublicHostKey); |
| | 0 | 99 | | WriteBinaryString(ClientHostName); |
| | 0 | 100 | | WriteBinaryString(ClientUsername); |
| | 0 | 101 | | WriteBinaryString(Signature); |
| | 0 | 102 | | } |
| | | 103 | | } |
| | | 104 | | } |