Skip to content

Commit 8ea108a

Browse files
Drop legacy algorithms part 1 (#1442)
This drops some of the algorithms long-considered legacy/insecure. The idea is both to improve the theoretical security of the library by not offering these algorithms, and to improve the practical security of the library by not having hand-written, barely tested crypto code. The overarching goal is for the library to have minimal exposure to crypto implementation, relying firstly on the .NET base libraries, and secondly on third-party providers, such as BouncyCastle. This change covers deleting the cipher algorithms arcfour, blowfish, twofish, cast. It covers deleting the MD5-based and truncated HMAC algorithms. These were all disabled in OpenSSH server (sshd) in 2014[^1]: > sshd(8): The default set of ciphers and MACs has been altered to > remove unsafe algorithms. In particular, CBC ciphers and arcfour* > are disabled by default. > > The full set of algorithms remains available if configured > explicitly via the Ciphers and MACs sshd_config options. and in the client in 2016[^2]: > This release disables a number of legacy cryptographic algorithms > by default in ssh: > > * Several ciphers blowfish-cbc, cast128-cbc, all arcfour variants > and the rijndael-cbc aliases for AES. > > * MD5-based and truncated HMAC algorithms. > > These algorithms are already disabled by default in sshd. This change also drops PKCS5Padding, which is a line-for-line copy of PKCS7Padding, and StreamCipher, which is now unused (and useless anyway). [^1]: https://www.openssh.com/txt/release-6.7 [^2]: https://www.openssh.com/txt/release-7.2 Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
1 parent 9a950b5 commit 8ea108a

File tree

21 files changed

+9
-3781
lines changed

21 files changed

+9
-3781
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ The main types provided by this library are:
7676
* aes192-cbc
7777
* aes256-cbc
7878
* 3des-cbc
79-
* blowfish-cbc
80-
* twofish-cbc
81-
* twofish192-cbc
82-
* twofish128-cbc
83-
* twofish256-cbc
84-
* arcfour
85-
* arcfour128
86-
* arcfour256
87-
* cast128-cbc
8879

8980
## Key Exchange Methods
9081

@@ -134,18 +125,10 @@ Private keys can be encrypted using one of the following cipher methods:
134125
**SSH.NET** supports the following MAC algorithms:
135126
* hmac-sha2-256
136127
* hmac-sha2-512
137-
* hmac-sha2-512-96
138-
* hmac-sha2-256-96
139128
* hmac-sha1
140-
* hmac-sha1-96
141-
* hmac-md5
142-
* hmac-md5-96
143129
* hmac-sha2-256-etm<span></span>@openssh.com
144130
* hmac-sha2-512-etm<span></span>@openssh.com
145131
* hmac-sha1-etm<span></span>@openssh.com
146-
* hmac-sha1-96-etm<span></span>@openssh.com
147-
* hmac-md5-etm<span></span>@openssh.com
148-
* hmac-md5-96-etm<span></span>@openssh.com
149132

150133
## Compression
151134

src/Renci.SshNet/Abstractions/CryptoAbstraction.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22

3-
using Renci.SshNet.Security.Cryptography;
4-
53
namespace Renci.SshNet.Abstractions
64
{
75
internal static class CryptoAbstraction
@@ -62,55 +60,5 @@ public static System.Security.Cryptography.SHA512 CreateSHA512()
6260
{
6361
return System.Security.Cryptography.SHA512.Create();
6462
}
65-
66-
public static System.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key)
67-
{
68-
return new System.Security.Cryptography.HMACMD5(key);
69-
}
70-
71-
public static HMACMD5 CreateHMACMD5(byte[] key, int hashSize)
72-
{
73-
return new HMACMD5(key, hashSize);
74-
}
75-
76-
public static System.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key)
77-
{
78-
return new System.Security.Cryptography.HMACSHA1(key);
79-
}
80-
81-
public static HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize)
82-
{
83-
return new HMACSHA1(key, hashSize);
84-
}
85-
86-
public static System.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key)
87-
{
88-
return new System.Security.Cryptography.HMACSHA256(key);
89-
}
90-
91-
public static HMACSHA256 CreateHMACSHA256(byte[] key, int hashSize)
92-
{
93-
return new HMACSHA256(key, hashSize);
94-
}
95-
96-
public static System.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key)
97-
{
98-
return new System.Security.Cryptography.HMACSHA384(key);
99-
}
100-
101-
public static HMACSHA384 CreateHMACSHA384(byte[] key, int hashSize)
102-
{
103-
return new HMACSHA384(key, hashSize);
104-
}
105-
106-
public static System.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key)
107-
{
108-
return new System.Security.Cryptography.HMACSHA512(key);
109-
}
110-
111-
public static HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize)
112-
{
113-
return new HMACSHA512(key, hashSize);
114-
}
11563
}
11664
}

src/Renci.SshNet/ConnectionInfo.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Security.Cryptography;
66
using System.Text;
77

8-
using Renci.SshNet.Abstractions;
98
using Renci.SshNet.Common;
109
using Renci.SshNet.Compression;
1110
using Renci.SshNet.Messages.Authentication;
@@ -397,37 +396,18 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
397396
Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)));
398397
Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)));
399398
Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => new TripleDesCipher(key, new CbcCipherMode(iv), padding: null)));
400-
Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => new BlowfishCipher(key, new CbcCipherMode(iv), padding: null)));
401-
Encryptions.Add("twofish-cbc", new CipherInfo(256, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), padding: null)));
402-
Encryptions.Add("twofish192-cbc", new CipherInfo(192, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), padding: null)));
403-
Encryptions.Add("twofish128-cbc", new CipherInfo(128, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), padding: null)));
404-
Encryptions.Add("twofish256-cbc", new CipherInfo(256, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), padding: null)));
405-
Encryptions.Add("arcfour", new CipherInfo(128, (key, iv) => new Arc4Cipher(key, dischargeFirstBytes: false)));
406-
Encryptions.Add("arcfour128", new CipherInfo(128, (key, iv) => new Arc4Cipher(key, dischargeFirstBytes: true)));
407-
Encryptions.Add("arcfour256", new CipherInfo(256, (key, iv) => new Arc4Cipher(key, dischargeFirstBytes: true)));
408-
Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => new CastCipher(key, new CbcCipherMode(iv), padding: null)));
409-
410-
#pragma warning disable IDE0200 // Remove unnecessary lambda expression; We want to prevent instantiating the HashAlgorithm objects.
399+
411400
HmacAlgorithms = new Dictionary<string, HashInfo>
412401
{
413402
/* Encrypt-and-MAC (encrypt-and-authenticate) variants */
414-
{ "hmac-sha2-256", new HashInfo(32*8, key => CryptoAbstraction.CreateHMACSHA256(key), isEncryptThenMAC: false) },
415-
{ "hmac-sha2-512", new HashInfo(64*8, key => CryptoAbstraction.CreateHMACSHA512(key), isEncryptThenMAC: false) },
416-
{ "hmac-sha2-512-96", new HashInfo(64*8, key => CryptoAbstraction.CreateHMACSHA512(key, 96), isEncryptThenMAC: false) },
417-
{ "hmac-sha2-256-96", new HashInfo(32*8, key => CryptoAbstraction.CreateHMACSHA256(key, 96), isEncryptThenMAC: false) },
418-
{ "hmac-sha1", new HashInfo(20*8, key => CryptoAbstraction.CreateHMACSHA1(key), isEncryptThenMAC: false) },
419-
{ "hmac-sha1-96", new HashInfo(20*8, key => CryptoAbstraction.CreateHMACSHA1(key, 96), isEncryptThenMAC: false) },
420-
{ "hmac-md5", new HashInfo(16*8, key => CryptoAbstraction.CreateHMACMD5(key), isEncryptThenMAC: false) },
421-
{ "hmac-md5-96", new HashInfo(16*8, key => CryptoAbstraction.CreateHMACMD5(key, 96), isEncryptThenMAC: false) },
403+
{ "hmac-sha2-256", new HashInfo(32*8, key => new HMACSHA256(key)) },
404+
{ "hmac-sha2-512", new HashInfo(64*8, key => new HMACSHA512(key)) },
405+
{ "hmac-sha1", new HashInfo(20*8, key => new HMACSHA1(key)) },
422406
/* Encrypt-then-MAC variants */
423-
{ "hmac-sha2-256-etm@openssh.com", new HashInfo(32*8, key => CryptoAbstraction.CreateHMACSHA256(key), isEncryptThenMAC: true) },
424-
{ "hmac-sha2-512-etm@openssh.com", new HashInfo(64*8, key => CryptoAbstraction.CreateHMACSHA512(key), isEncryptThenMAC: true) },
425-
{ "hmac-sha1-etm@openssh.com", new HashInfo(20*8, key => CryptoAbstraction.CreateHMACSHA1(key), isEncryptThenMAC: true) },
426-
{ "hmac-sha1-96-etm@openssh.com", new HashInfo(20*8, key => CryptoAbstraction.CreateHMACSHA1(key, 96), isEncryptThenMAC: true) },
427-
{ "hmac-md5-etm@openssh.com", new HashInfo(16*8, key => CryptoAbstraction.CreateHMACMD5(key), isEncryptThenMAC: true) },
428-
{ "hmac-md5-96-etm@openssh.com", new HashInfo(16*8, key => CryptoAbstraction.CreateHMACMD5(key, 96), isEncryptThenMAC: true) },
407+
{ "hmac-sha2-256-etm@openssh.com", new HashInfo(32*8, key => new HMACSHA256(key), isEncryptThenMAC: true) },
408+
{ "hmac-sha2-512-etm@openssh.com", new HashInfo(64*8, key => new HMACSHA512(key), isEncryptThenMAC: true) },
409+
{ "hmac-sha1-etm@openssh.com", new HashInfo(20*8, key => new HMACSHA1(key), isEncryptThenMAC: true) },
429410
};
430-
#pragma warning restore IDE0200 // Remove unnecessary lambda expression
431411

432412
HostKeyAlgorithms = new Dictionary<string, Func<byte[], KeyHostAlgorithm>>
433413
{

src/Renci.SshNet/Security/Cryptography/Ciphers/Arc4Cipher.cs

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)