|
|
@@ -1,8 +1,6 @@
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Text;
|
|
|
+using System.Text;
|
|
|
|
|
|
using Renci.SshNet.Common;
|
|
|
-using Renci.SshNet.Security.Chaos.NaCl;
|
|
|
using Renci.SshNet.Security.Cryptography;
|
|
|
|
|
|
namespace Renci.SshNet.Security
|
|
|
@@ -15,17 +13,11 @@ namespace Renci.SshNet.Security
|
|
|
/// <summary>
|
|
|
/// Gets the key used in this host key algorithm.
|
|
|
/// </summary>
|
|
|
- /// <value>
|
|
|
- /// The key used in this host key algorithm.
|
|
|
- /// </value>
|
|
|
public Key Key { get; private set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets the signature implementation used in this host key algorithm.
|
|
|
/// </summary>
|
|
|
- /// <value>
|
|
|
- /// The signature implementation used in this host key algorithm.
|
|
|
- /// </value>
|
|
|
public DigitalSignature DigitalSignature { get; private set; }
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -47,11 +39,7 @@ namespace Renci.SshNet.Security
|
|
|
/// Initializes a new instance of the <see cref="KeyHostAlgorithm"/> class.
|
|
|
/// </summary>
|
|
|
/// <param name="name">The signature format identifier.</param>
|
|
|
- /// <param name="key"><inheritdoc cref="Key" path="/summary"/></param>
|
|
|
- /// <remarks>
|
|
|
- /// This constructor is typically passed a private key in order to create an encoded signature for later
|
|
|
- /// verification by the host.
|
|
|
- /// </remarks>
|
|
|
+ /// <param name="key">The key used in this host key algorithm.</param>
|
|
|
public KeyHostAlgorithm(string name, Key key)
|
|
|
: base(name)
|
|
|
{
|
|
|
@@ -63,13 +51,9 @@ namespace Renci.SshNet.Security
|
|
|
/// Initializes a new instance of the <see cref="KeyHostAlgorithm"/> class.
|
|
|
/// </summary>
|
|
|
/// <param name="name">The signature format identifier.</param>
|
|
|
- /// <param name="key"><inheritdoc cref="Key" path="/summary"/></param>
|
|
|
- /// <param name="digitalSignature"><inheritdoc cref="DigitalSignature" path="/summary"/></param>
|
|
|
+ /// <param name="key">The key used in this host key algorithm.</param>
|
|
|
+ /// <param name="digitalSignature">The signature implementation used in this host key algorithm.</param>
|
|
|
/// <remarks>
|
|
|
- /// <para>
|
|
|
- /// This constructor is typically passed a private key in order to create an encoded signature for later
|
|
|
- /// verification by the host.
|
|
|
- /// </para>
|
|
|
/// The key used by <paramref name="digitalSignature"/> is intended to be equal to <paramref name="key"/>.
|
|
|
/// This is not verified.
|
|
|
/// </remarks>
|
|
|
@@ -80,59 +64,6 @@ namespace Renci.SshNet.Security
|
|
|
DigitalSignature = digitalSignature;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Initializes a new instance of the <see cref="KeyHostAlgorithm"/> class
|
|
|
- /// with the given encoded public key data. The data will be decoded into <paramref name="key"/>.
|
|
|
- /// </summary>
|
|
|
- /// <param name="name">The signature format identifier.</param>
|
|
|
- /// <param name="key"><inheritdoc cref="Key" path="/summary"/></param>
|
|
|
- /// <param name="data">Host key encoded data.</param>
|
|
|
- /// <remarks>
|
|
|
- /// This constructor is typically passed a new or reusable <see cref="Security.Key"/> instance in
|
|
|
- /// order to verify an encoded signature sent by the host, created by the private counterpart
|
|
|
- /// to the host's public key, which is encoded in <paramref name="data"/>.
|
|
|
- /// </remarks>
|
|
|
- public KeyHostAlgorithm(string name, Key key, byte[] data)
|
|
|
- : base(name)
|
|
|
- {
|
|
|
- Key = key;
|
|
|
-
|
|
|
- var sshKey = new SshKeyData();
|
|
|
- sshKey.Load(data);
|
|
|
- Key.Public = sshKey.Keys;
|
|
|
-
|
|
|
- DigitalSignature = key.DigitalSignature;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Initializes a new instance of the <see cref="KeyHostAlgorithm"/> class
|
|
|
- /// with the given encoded public key data. The data will be decoded into <paramref name="key"/>.
|
|
|
- /// </summary>
|
|
|
- /// <param name="name">The signature format identifier.</param>
|
|
|
- /// <param name="key"><inheritdoc cref="Key" path="/summary"/></param>
|
|
|
- /// <param name="data">Host key encoded data.</param>
|
|
|
- /// <param name="digitalSignature"><inheritdoc cref="DigitalSignature" path="/summary"/></param>
|
|
|
- /// <remarks>
|
|
|
- /// <para>
|
|
|
- /// This constructor is typically passed a new or reusable <see cref="Security.Key"/> instance in
|
|
|
- /// order to verify an encoded signature sent by the host, created by the private counterpart
|
|
|
- /// to the host's public key, which is encoded in <paramref name="data"/>.
|
|
|
- /// </para>
|
|
|
- /// The key used by <paramref name="digitalSignature"/> is intended to be equal to <paramref name="key"/>.
|
|
|
- /// This is not verified.
|
|
|
- /// </remarks>
|
|
|
- public KeyHostAlgorithm(string name, Key key, byte[] data, DigitalSignature digitalSignature)
|
|
|
- : base(name)
|
|
|
- {
|
|
|
- Key = key;
|
|
|
-
|
|
|
- var sshKey = new SshKeyData();
|
|
|
- sshKey.Load(data);
|
|
|
- Key.Public = sshKey.Keys;
|
|
|
-
|
|
|
- DigitalSignature = digitalSignature;
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Signs and encodes the specified data.
|
|
|
/// </summary>
|
|
|
@@ -162,98 +93,6 @@ namespace Renci.SshNet.Security
|
|
|
return DigitalSignature.Verify(data, signatureData.Signature);
|
|
|
}
|
|
|
|
|
|
- private sealed class SshKeyData : SshData
|
|
|
- {
|
|
|
- private byte[] _name;
|
|
|
- private List<byte[]> _keys;
|
|
|
-
|
|
|
- public BigInteger[] Keys
|
|
|
- {
|
|
|
- get
|
|
|
- {
|
|
|
- var keys = new BigInteger[_keys.Count];
|
|
|
-
|
|
|
- for (var i = 0; i < _keys.Count; i++)
|
|
|
- {
|
|
|
- var key = _keys[i];
|
|
|
- keys[i] = key.ToBigInteger2();
|
|
|
- }
|
|
|
-
|
|
|
- return keys;
|
|
|
- }
|
|
|
- private set
|
|
|
- {
|
|
|
- _keys = new List<byte[]>(value.Length);
|
|
|
-
|
|
|
- foreach (var key in value)
|
|
|
- {
|
|
|
- var keyData = key.ToByteArray().Reverse();
|
|
|
- if (Name == "ssh-ed25519")
|
|
|
- {
|
|
|
- keyData = keyData.TrimLeadingZeros().Pad(Ed25519.PublicKeySizeInBytes);
|
|
|
- }
|
|
|
-
|
|
|
- _keys.Add(keyData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private string Name
|
|
|
- {
|
|
|
- get { return Utf8.GetString(_name, 0, _name.Length); }
|
|
|
- set { _name = Utf8.GetBytes(value); }
|
|
|
- }
|
|
|
-
|
|
|
- protected override int BufferCapacity
|
|
|
- {
|
|
|
- get
|
|
|
- {
|
|
|
- var capacity = base.BufferCapacity;
|
|
|
- capacity += 4; // Name length
|
|
|
- capacity += _name.Length; // Name
|
|
|
-
|
|
|
- foreach (var key in _keys)
|
|
|
- {
|
|
|
- capacity += 4; // Key length
|
|
|
- capacity += key.Length; // Key
|
|
|
- }
|
|
|
-
|
|
|
- return capacity;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public SshKeyData()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public SshKeyData(string name, params BigInteger[] keys)
|
|
|
- {
|
|
|
- Name = name;
|
|
|
- Keys = keys;
|
|
|
- }
|
|
|
-
|
|
|
- protected override void LoadData()
|
|
|
- {
|
|
|
- _name = ReadBinary();
|
|
|
- _keys = new List<byte[]>();
|
|
|
-
|
|
|
- while (!IsEndOfData)
|
|
|
- {
|
|
|
- _keys.Add(ReadBinary());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected override void SaveData()
|
|
|
- {
|
|
|
- WriteBinaryString(_name);
|
|
|
-
|
|
|
- foreach (var key in _keys)
|
|
|
- {
|
|
|
- WriteBinaryString(key);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
internal sealed class SignatureKeyData : SshData
|
|
|
{
|
|
|
/// <summary>
|
|
|
@@ -306,7 +145,7 @@ namespace Renci.SshNet.Security
|
|
|
/// </summary>
|
|
|
protected override void LoadData()
|
|
|
{
|
|
|
- AlgorithmName = Encoding.UTF8.GetString(ReadBinary());
|
|
|
+ AlgorithmName = ReadString();
|
|
|
Signature = ReadBinary();
|
|
|
}
|
|
|
|
|
|
@@ -315,7 +154,7 @@ namespace Renci.SshNet.Security
|
|
|
/// </summary>
|
|
|
protected override void SaveData()
|
|
|
{
|
|
|
- WriteBinaryString(Encoding.UTF8.GetBytes(AlgorithmName));
|
|
|
+ Write(AlgorithmName);
|
|
|
WriteBinaryString(Signature);
|
|
|
}
|
|
|
}
|