mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
Fix DSS key authentication, Rename KeyFile to PrivateKeyFile
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public KeyFile KeyFile { get; set; }
|
||||
public PrivateKeyFile KeyFile { get; set; }
|
||||
|
||||
public ConnectionInfo()
|
||||
{
|
||||
|
||||
+19
-14
@@ -7,7 +7,7 @@ using Renci.SshClient.Security;
|
||||
|
||||
namespace Renci.SshClient
|
||||
{
|
||||
public class KeyFile
|
||||
public class PrivateKeyFile
|
||||
{
|
||||
private Regex _beginKeyLine = new Regex(@"----[ ]*BEGIN (?<keyName>.+) PRIVATE KEY[ ]*----");
|
||||
private Regex _headerLine = new Regex(@"(?<headerTag>[^:]{1,64}):[ ](?<headerValue>[^:]+(?<continue>\\)?)");
|
||||
@@ -37,12 +37,27 @@ namespace Renci.SshClient
|
||||
return this._key.GetSignature(sessionId);
|
||||
}
|
||||
|
||||
public KeyFile()
|
||||
public PrivateKeyFile(Stream privateKey)
|
||||
{
|
||||
|
||||
this.Open(privateKey, null);
|
||||
}
|
||||
|
||||
public void Open(Stream privateKey, string passPhrase)
|
||||
public PrivateKeyFile(string fileName)
|
||||
{
|
||||
this.Open(File.Open(fileName, FileMode.Open), null);
|
||||
}
|
||||
|
||||
public PrivateKeyFile(string fileName, string passPhrase)
|
||||
{
|
||||
this.Open(File.Open(fileName, FileMode.Open), passPhrase);
|
||||
}
|
||||
|
||||
public PrivateKeyFile(Stream privateKey, string passPhrase)
|
||||
{
|
||||
this.Open(privateKey, passPhrase);
|
||||
}
|
||||
|
||||
private void Open(Stream privateKey, string passPhrase)
|
||||
{
|
||||
var headerTag = string.Empty;
|
||||
var headerValue = string.Empty;
|
||||
@@ -134,15 +149,5 @@ namespace Renci.SshClient
|
||||
this._key.Load(System.Convert.FromBase64String(data.ToString()), passPhrase);
|
||||
}
|
||||
|
||||
public void Open(string fileName)
|
||||
{
|
||||
this.Open(File.Open(fileName, FileMode.Open), null);
|
||||
}
|
||||
|
||||
public void Open(string fileName, string passPhrase)
|
||||
{
|
||||
this.Open(File.Open(fileName, FileMode.Open), passPhrase);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@
|
||||
<Compile Include="Security\KeyExchangeDiffieHellman.cs" />
|
||||
<Compile Include="Security\KeyExchangeFailedEventArgs.cs" />
|
||||
<Compile Include="Security\KeyExchangeSendMessageEventArgs.cs" />
|
||||
<Compile Include="KeyFile.cs" />
|
||||
<Compile Include="PrivateKeyFile.cs" />
|
||||
<Compile Include="Messages\Connection\ChannelMessage.cs" />
|
||||
<Compile Include="Messages\Connection\RequestNames.cs" />
|
||||
<Compile Include="Security\UserAuthentication.cs" />
|
||||
@@ -199,7 +199,6 @@
|
||||
<Compile Include="Shell.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
<Folder Include="Shell\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace Renci.SshClient.Security
|
||||
private byte[] _p;
|
||||
private byte[] _q;
|
||||
private byte[] _g;
|
||||
private byte[] _x;
|
||||
private byte[] _publicKey;
|
||||
private byte[] _privateKey;
|
||||
|
||||
public override string Name
|
||||
{
|
||||
@@ -62,13 +62,13 @@ namespace Renci.SshClient.Security
|
||||
this._publicKey = binr.ReadBytes(elems);
|
||||
|
||||
elems = CryptoPrivateKeyDss.GetIntegerSize(binr);
|
||||
this._x = binr.ReadBytes(elems);
|
||||
this._privateKey = binr.ReadBytes(elems);
|
||||
}
|
||||
}
|
||||
|
||||
public override CryptoPublicKey GetPublicKey()
|
||||
{
|
||||
return new CryptoPublicKeyDss(this._p, this._q, this._g, this._x);
|
||||
return new CryptoPublicKeyDss(this._p, this._q, this._g, this._publicKey);
|
||||
}
|
||||
|
||||
public override IEnumerable<byte> GetSignature(IEnumerable<byte> key)
|
||||
@@ -79,7 +79,7 @@ namespace Renci.SshClient.Security
|
||||
{
|
||||
DSAParameters DSAKeyInfo = new DSAParameters();
|
||||
|
||||
DSAKeyInfo.X = this._x.TrimLeadinZero().ToArray();
|
||||
DSAKeyInfo.X = this._privateKey.TrimLeadinZero().ToArray();
|
||||
DSAKeyInfo.P = this._p.TrimLeadinZero().ToArray();
|
||||
DSAKeyInfo.Q = this._q.TrimLeadinZero().ToArray();
|
||||
DSAKeyInfo.G = this._g.TrimLeadinZero().ToArray();
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Renci.SshClient.Security
|
||||
private IEnumerable<byte> _p;
|
||||
private IEnumerable<byte> _q;
|
||||
private IEnumerable<byte> _g;
|
||||
private IEnumerable<byte> _x;
|
||||
private IEnumerable<byte> _publicKey;
|
||||
|
||||
public override string Name
|
||||
{
|
||||
@@ -24,12 +24,12 @@ namespace Renci.SshClient.Security
|
||||
|
||||
}
|
||||
|
||||
public CryptoPublicKeyDss(IEnumerable<byte> p, IEnumerable<byte> q, IEnumerable<byte> g, IEnumerable<byte> x)
|
||||
public CryptoPublicKeyDss(IEnumerable<byte> p, IEnumerable<byte> q, IEnumerable<byte> g, IEnumerable<byte> publicKey)
|
||||
{
|
||||
this._p = p;
|
||||
this._q = q;
|
||||
this._g = g;
|
||||
this._x = x;
|
||||
this._publicKey = publicKey;
|
||||
}
|
||||
|
||||
public override void Load(IEnumerable<byte> data)
|
||||
@@ -52,7 +52,7 @@ namespace Renci.SshClient.Security
|
||||
|
||||
var xl = BitConverter.ToUInt32(br.ReadBytes(4).Reverse().ToArray(), 0);
|
||||
|
||||
_x = br.ReadBytes((int)xl);
|
||||
_publicKey = br.ReadBytes((int)xl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Renci.SshClient.Security
|
||||
{
|
||||
dsa.ImportParameters(new DSAParameters
|
||||
{
|
||||
X = _x.TrimLeadinZero().ToArray(),
|
||||
X = _publicKey.TrimLeadinZero().ToArray(),
|
||||
P = _p.TrimLeadinZero().ToArray(),
|
||||
Q = _q.TrimLeadinZero().ToArray(),
|
||||
G = _g.TrimLeadinZero().ToArray(),
|
||||
@@ -117,7 +117,7 @@ namespace Renci.SshClient.Security
|
||||
P = this._p,
|
||||
Q = this._q,
|
||||
G = this._g,
|
||||
Public = this._x,
|
||||
Public = this._publicKey,
|
||||
}.GetBytes();
|
||||
}
|
||||
|
||||
@@ -144,6 +144,5 @@ namespace Renci.SshClient.Security
|
||||
this.Write(this.Public.GetSshString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace Renci.SshClient.Security
|
||||
|
||||
Message.RegisterMessageType<InformationRequestMessage>(MessageTypes.UserAuthenticationInformationRequest);
|
||||
|
||||
|
||||
// TODO: Complete full public key implemention which includes other messages
|
||||
var message = new PublicKeyRequestMessage
|
||||
{
|
||||
@@ -38,15 +37,12 @@ namespace Renci.SshClient.Security
|
||||
Username = this.Session.ConnectionInfo.Username,
|
||||
PublicKeyAlgorithmName = this.Session.ConnectionInfo.KeyFile.AlgorithmName,
|
||||
PublicKeyData = this.Session.ConnectionInfo.KeyFile.PublicKey,
|
||||
Signature = new byte[] { },
|
||||
//Signature = this.Session.ConnectionInfo.KeyFile.GetSignature(this.Session.SessionId),
|
||||
//Signature = new byte[] { },
|
||||
};
|
||||
|
||||
var signatureData = new SignatureData(message, this.Session.SessionId.GetSshString()).GetBytes();
|
||||
|
||||
var signature = this.Session.ConnectionInfo.KeyFile.GetSignature(signatureData);
|
||||
|
||||
message.Signature = signature;
|
||||
message.Signature = this.Session.ConnectionInfo.KeyFile.GetSignature(signatureData);
|
||||
|
||||
this.Session.SendMessage(message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user