Add support for AES128-CBC, AES192-CBC and AES256-CBC

This commit is contained in:
olegkap_cp
2010-09-10 19:51:04 +00:00
parent 4e26ff3954
commit 31e8e2f429
5 changed files with 43 additions and 15 deletions
@@ -33,9 +33,6 @@ namespace Renci.SshClient.Messages.Transport
this.HostKey = this.ReadString();
this.F = this.ReadBigInteger();
this.Signature = this.ReadString();
// TODO: Determine which algorithms to use from signature
}
protected override void SaveData()
@@ -67,7 +67,7 @@
<Compile Include="Messages\Connection\GlobalRequestNames.cs" />
<Compile Include="Security\Algorithm.cs" />
<Compile Include="Security\Cipher.cs" />
<Compile Include="Security\CipherAES128.cs" />
<Compile Include="Security\CipherAES.cs" />
<Compile Include="Security\CipherTripleDES.cs" />
<Compile Include="Security\Compression.cs" />
<Compile Include="Channels\ChannelSftp.cs" />
@@ -5,7 +5,7 @@ using System.Security.Cryptography;
namespace Renci.SshClient.Security
{
internal class CipherAES128 : Cipher, IDisposable
internal abstract class CipherAES : Cipher, IDisposable
{
private SymmetricAlgorithm _algorithm;
@@ -34,9 +34,12 @@ namespace Renci.SshClient.Security
}
}
public CipherAES128()
protected abstract int KeyBitsSize { get; }
public CipherAES()
{
this._algorithm = new System.Security.Cryptography.RijndaelManaged();
this._algorithm.KeySize = this.KeyBitsSize;
this._algorithm.Mode = System.Security.Cryptography.CipherMode.CBC;
this._algorithm.Padding = System.Security.Cryptography.PaddingMode.None;
}
@@ -111,7 +114,7 @@ namespace Renci.SshClient.Security
}
}
~CipherAES128()
~CipherAES()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
@@ -121,4 +124,27 @@ namespace Renci.SshClient.Security
#endregion
}
internal class CipherAES128CBC : CipherAES
{
protected override int KeyBitsSize
{
get { return 128; }
}
}
internal class CipherAES192CBC : CipherAES
{
protected override int KeyBitsSize
{
get { return 192; }
}
}
internal class CipherAES256CBC : CipherAES
{
protected override int KeyBitsSize
{
get { return 256; }
}
}
}
+9 -6
View File
@@ -538,13 +538,16 @@ namespace Renci.SshClient
// Read rest of the packet data
int bytesToRead = (int)(packetLength - (blockSize - 4));
if (this._keyExhcange.ServerCipher == null)
if (bytesToRead > 0)
{
decryptedData.AddRange(this.Read(bytesToRead));
}
else
{
decryptedData.AddRange(this._keyExhcange.ServerCipher.Decrypt(this.Read(bytesToRead)));
if (this._keyExhcange.ServerCipher == null)
{
decryptedData.AddRange(this.Read(bytesToRead));
}
else
{
decryptedData.AddRange(this._keyExhcange.ServerCipher.Decrypt(this.Read(bytesToRead)));
}
}
var paddingLength = decryptedData[4];
+4 -2
View File
@@ -31,7 +31,9 @@ namespace Renci.SshClient
Settings.Encryptions = new Dictionary<string, Func<Cipher>>()
{
{"3des-cbc", () => { return new CipherTripleDES();}},
//{"aes128-cbc", () => { return new CipherAES128();}}, // TODO: This cipher does not work
{"aes128-cbc", () => { return new CipherAES128CBC();}},
{"aes192-cbc", () => { return new CipherAES192CBC();}},
{"aes256-cbc", () => { return new CipherAES256CBC();}},
};
@@ -57,7 +59,7 @@ namespace Renci.SshClient
Settings.CompressionAlgorithms = new Dictionary<string, Func<Session, Compression>>()
{
{"none", (session) => { return null;}},
{"zlib", (session) => { return new CompressionZlibOpenSsh(session);}},
{"zlib", (session) => { return new CompressionZlib(session);}},
{"zlib@openssh.com", (session) => { return new CompressionZlibOpenSsh(session);}},
};