From 1a1222c4cecbbae0c411a04fc856a62241f63794 Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Fri, 16 Feb 2024 21:37:08 +0800 Subject: [PATCH 1/2] Drop RIPEMD160 --- README.md | 2 -- .../Abstractions/CryptoAbstraction.cs | 32 ------------------- src/Renci.SshNet/ConnectionInfo.cs | 2 -- src/Renci.SshNet/Renci.SshNet.csproj | 6 +--- 4 files changed, 1 insertion(+), 41 deletions(-) diff --git a/README.md b/README.md index e39e4f298..d12af8fc8 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,6 @@ Private keys can be encrypted using one of the following cipher methods: * hmac-sha2-256-96 * hmac-sha2-512 * hmac-sha2-512-96 -* hmac-ripemd160 -* hmac-ripemd160@openssh.com * hmac-md5-etm@openssh.com * hmac-md5-96-etm@openssh.com * hmac-sha1-etm@openssh.com diff --git a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs index ca187833f..ac3d1915c 100644 --- a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs @@ -66,24 +66,6 @@ public static System.Security.Cryptography.SHA512 CreateSHA512() return System.Security.Cryptography.SHA512.Create(); } -#if FEATURE_HASH_RIPEMD160_CREATE || FEATURE_HASH_RIPEMD160_MANAGED - public static System.Security.Cryptography.RIPEMD160 CreateRIPEMD160() - { -#if FEATURE_HASH_RIPEMD160_CREATE -#pragma warning disable CA5350 // Do not use weak cryptographic algorithms - return System.Security.Cryptography.RIPEMD160.Create(); -#pragma warning restore CA5350 // Do not use weak cryptographic algorithms -#else - return new System.Security.Cryptography.RIPEMD160Managed(); -#endif - } -#else - public static global::SshNet.Security.Cryptography.RIPEMD160 CreateRIPEMD160() - { - return new global::SshNet.Security.Cryptography.RIPEMD160(); - } -#endif // FEATURE_HASH_RIPEMD160 - public static System.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key) { #pragma warning disable CA5351 // Do not use broken cryptographic algorithms @@ -141,19 +123,5 @@ public static HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize) { return new HMACSHA512(key, hashSize); } - -#if FEATURE_HMAC_RIPEMD160 - public static System.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key) - { -#pragma warning disable CA5350 // Do not use weak cryptographic algorithms - return new System.Security.Cryptography.HMACRIPEMD160(key); -#pragma warning restore CA5350 // Do not use weak cryptographic algorithms - } -#else - public static global::SshNet.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key) - { - return new global::SshNet.Security.Cryptography.HMACRIPEMD160(key); - } -#endif // FEATURE_HMAC_RIPEMD160 } } diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index d57c08860..3fc6da1be 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -381,8 +381,6 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy { "hmac-sha2-512", new HashInfo(64*8, key => CryptoAbstraction.CreateHMACSHA512(key), isEncryptThenMAC: false) }, { "hmac-sha2-512-96", new HashInfo(64*8, key => CryptoAbstraction.CreateHMACSHA512(key, 96), isEncryptThenMAC: false) }, { "hmac-sha2-256-96", new HashInfo(32*8, key => CryptoAbstraction.CreateHMACSHA256(key, 96), isEncryptThenMAC: false) }, - { "hmac-ripemd160", new HashInfo(160, key => CryptoAbstraction.CreateHMACRIPEMD160(key), isEncryptThenMAC: false) }, - { "hmac-ripemd160@openssh.com", new HashInfo(160, key => CryptoAbstraction.CreateHMACRIPEMD160(key), isEncryptThenMAC: false) }, { "hmac-sha1", new HashInfo(20*8, key => CryptoAbstraction.CreateHMACSHA1(key), isEncryptThenMAC: false) }, { "hmac-sha1-96", new HashInfo(20*8, key => CryptoAbstraction.CreateHMACSHA1(key, 96), isEncryptThenMAC: false) }, { "hmac-md5", new HashInfo(16*8, key => CryptoAbstraction.CreateHMACMD5(key), isEncryptThenMAC: false) }, diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index f1ce038ba..48029e11a 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -29,13 +29,9 @@ - $(DefineConstants);FEATURE_BINARY_SERIALIZATION;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + $(DefineConstants);FEATURE_BINARY_SERIALIZATION - - - - From c447a84562103d0fb35d437c723cbbe7b3644b31 Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Sat, 17 Feb 2024 18:00:28 +0800 Subject: [PATCH 2/2] Replace FEATURE_BINARY_SERIALIZATION with NETFRAMEWORK --- src/Renci.SshNet/Common/NetConfServerException.cs | 12 ++++++------ src/Renci.SshNet/Common/ProxyException.cs | 12 ++++++------ src/Renci.SshNet/Common/ScpException.cs | 12 ++++++------ src/Renci.SshNet/Common/SftpPathNotFoundException.cs | 12 ++++++------ .../Common/SftpPermissionDeniedException.cs | 12 ++++++------ .../Common/SshAuthenticationException.cs | 12 ++++++------ src/Renci.SshNet/Common/SshConnectionException.cs | 12 ++++++------ src/Renci.SshNet/Common/SshException.cs | 12 ++++++------ .../Common/SshOperationTimeoutException.cs | 12 ++++++------ .../Common/SshPassPhraseNullOrEmptyException.cs | 12 ++++++------ src/Renci.SshNet/Renci.SshNet.csproj | 4 ---- .../Security/BouncyCastle/math/BigInteger.cs | 2 +- .../security/SecurityUtilityException.cs | 2 +- 13 files changed, 62 insertions(+), 66 deletions(-) diff --git a/src/Renci.SshNet/Common/NetConfServerException.cs b/src/Renci.SshNet/Common/NetConfServerException.cs index e8614bcb3..ab70a8346 100644 --- a/src/Renci.SshNet/Common/NetConfServerException.cs +++ b/src/Renci.SshNet/Common/NetConfServerException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when there is something wrong with the server capabilities. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class NetConfServerException : SshException { /// @@ -39,7 +39,7 @@ public NetConfServerException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected NetConfServerException(SerializationInfo info, StreamingContext contex : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/ProxyException.cs b/src/Renci.SshNet/Common/ProxyException.cs index 457cec53b..d324c9a3d 100644 --- a/src/Renci.SshNet/Common/ProxyException.cs +++ b/src/Renci.SshNet/Common/ProxyException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when a proxy connection cannot be established. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class ProxyException : SshException { /// @@ -39,7 +39,7 @@ public ProxyException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected ProxyException(SerializationInfo info, StreamingContext context) : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/ScpException.cs b/src/Renci.SshNet/Common/ScpException.cs index 26a7bdd85..564e2994b 100644 --- a/src/Renci.SshNet/Common/ScpException.cs +++ b/src/Renci.SshNet/Common/ScpException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when SCP error occurred. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class ScpException : SshException { /// @@ -39,7 +39,7 @@ public ScpException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected ScpException(SerializationInfo info, StreamingContext context) : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SftpPathNotFoundException.cs b/src/Renci.SshNet/Common/SftpPathNotFoundException.cs index 61af3b2fe..ed628dee0 100644 --- a/src/Renci.SshNet/Common/SftpPathNotFoundException.cs +++ b/src/Renci.SshNet/Common/SftpPathNotFoundException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when file or directory is not found. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SftpPathNotFoundException : SshException { /// @@ -39,7 +39,7 @@ public SftpPathNotFoundException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected SftpPathNotFoundException(SerializationInfo info, StreamingContext con : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SftpPermissionDeniedException.cs b/src/Renci.SshNet/Common/SftpPermissionDeniedException.cs index b040417ff..04301cf32 100644 --- a/src/Renci.SshNet/Common/SftpPermissionDeniedException.cs +++ b/src/Renci.SshNet/Common/SftpPermissionDeniedException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when operation permission is denied. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SftpPermissionDeniedException : SshException { /// @@ -39,7 +39,7 @@ public SftpPermissionDeniedException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected SftpPermissionDeniedException(SerializationInfo info, StreamingContext : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SshAuthenticationException.cs b/src/Renci.SshNet/Common/SshAuthenticationException.cs index e2909bddb..ad5b0b345 100644 --- a/src/Renci.SshNet/Common/SshAuthenticationException.cs +++ b/src/Renci.SshNet/Common/SshAuthenticationException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when authentication failed. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SshAuthenticationException : SshException { /// @@ -39,7 +39,7 @@ public SshAuthenticationException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected SshAuthenticationException(SerializationInfo info, StreamingContext co : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SshConnectionException.cs b/src/Renci.SshNet/Common/SshConnectionException.cs index a5c227b8e..d4c46011d 100644 --- a/src/Renci.SshNet/Common/SshConnectionException.cs +++ b/src/Renci.SshNet/Common/SshConnectionException.cs @@ -1,7 +1,7 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK using Renci.SshNet.Messages.Transport; namespace Renci.SshNet.Common @@ -9,9 +9,9 @@ namespace Renci.SshNet.Common /// /// The exception that is thrown when connection was terminated. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SshConnectionException : SshException { /// @@ -70,7 +70,7 @@ public SshConnectionException(string message, DisconnectReason disconnectReasonC DisconnectReason = disconnectReasonCode; } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -82,6 +82,6 @@ protected SshConnectionException(SerializationInfo info, StreamingContext contex : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SshException.cs b/src/Renci.SshNet/Common/SshException.cs index a2f721ee3..440f44885 100644 --- a/src/Renci.SshNet/Common/SshException.cs +++ b/src/Renci.SshNet/Common/SshException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when SSH exception occurs. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SshException : Exception { /// @@ -39,7 +39,7 @@ public SshException(string message, Exception inner) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected SshException(SerializationInfo info, StreamingContext context) : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SshOperationTimeoutException.cs b/src/Renci.SshNet/Common/SshOperationTimeoutException.cs index f81318872..2e0433d90 100644 --- a/src/Renci.SshNet/Common/SshOperationTimeoutException.cs +++ b/src/Renci.SshNet/Common/SshOperationTimeoutException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when operation is timed out. /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SshOperationTimeoutException : SshException { /// @@ -39,7 +39,7 @@ public SshOperationTimeoutException(string message, Exception innerException) { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected SshOperationTimeoutException(SerializationInfo info, StreamingContext : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Common/SshPassPhraseNullOrEmptyException.cs b/src/Renci.SshNet/Common/SshPassPhraseNullOrEmptyException.cs index 1ddc19193..3da9ca427 100644 --- a/src/Renci.SshNet/Common/SshPassPhraseNullOrEmptyException.cs +++ b/src/Renci.SshNet/Common/SshPassPhraseNullOrEmptyException.cs @@ -1,16 +1,16 @@ using System; -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK using System.Runtime.Serialization; -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK namespace Renci.SshNet.Common { /// /// The exception that is thrown when pass phrase for key file is empty or . /// -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK public class SshPassPhraseNullOrEmptyException : SshException { /// @@ -39,7 +39,7 @@ public SshPassPhraseNullOrEmptyException(string message, Exception innerExceptio { } -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK /// /// Initializes a new instance of the class. /// @@ -51,6 +51,6 @@ protected SshPassPhraseNullOrEmptyException(SerializationInfo info, StreamingCon : base(info, context) { } -#endif // FEATURE_BINARY_SERIALIZATION +#endif // NETFRAMEWORK } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 48029e11a..142f3df99 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -28,10 +28,6 @@ true - - $(DefineConstants);FEATURE_BINARY_SERIALIZATION - - diff --git a/src/Renci.SshNet/Security/BouncyCastle/math/BigInteger.cs b/src/Renci.SshNet/Security/BouncyCastle/math/BigInteger.cs index a98959efe..a947d590d 100644 --- a/src/Renci.SshNet/Security/BouncyCastle/math/BigInteger.cs +++ b/src/Renci.SshNet/Security/BouncyCastle/math/BigInteger.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Security.Org.BouncyCastle.Math { -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] #endif internal class BigInteger diff --git a/src/Renci.SshNet/Security/BouncyCastle/security/SecurityUtilityException.cs b/src/Renci.SshNet/Security/BouncyCastle/security/SecurityUtilityException.cs index 25a442e48..acd208b36 100644 --- a/src/Renci.SshNet/Security/BouncyCastle/security/SecurityUtilityException.cs +++ b/src/Renci.SshNet/Security/BouncyCastle/security/SecurityUtilityException.cs @@ -2,7 +2,7 @@ namespace Renci.SshNet.Security.Org.BouncyCastle.Security { -#if FEATURE_BINARY_SERIALIZATION +#if NETFRAMEWORK [Serializable] #endif internal class SecurityUtilityException