Skip to content

Commit

Permalink
Obsolete ExchangeAlgorithmType, CipherAlgorithmType and HashAlgorithm…
Browse files Browse the repository at this point in the history
…Type and their usage (dotnet#105875)

* Obsolete KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream.

* Fix build of S.N.S

* Tentatively unobsolete enum types

* Revert "Tentatively unobsolete enum types"

This reverts commit f5f6435.

* Obsolete other usages of enums

* 9.0

* Suppressions

* Change #ifdef checks to 10.0

* Update compatibility suppressions

* Regenerated suppresions

* Fix build

---------

Co-authored-by: wfurt <[email protected]>
  • Loading branch information
2 people authored and lambdageek committed Oct 3, 2024
1 parent be3bd8c commit 70583d4
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0055`__ | The underlying hardware instruction does not perform a signed saturate narrowing operation, and it always returns an unsigned result. Use the unsigned overload instead. |
| __`SYSLIB0056`__ | LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm. |
| __`SYSLIB0057`__ | Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates. |
| __`SYSLIB0058`__ | KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead. |

## Analyzer Warnings

Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ internal static class Obsoletions
internal const string X509CtorCertDataObsoleteMessage = "Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.";
internal const string X509CtorCertDataObsoleteDiagId = "SYSLIB0057";

internal const string TlsCipherAlgorithmEnumsMessage = "KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.";
internal const string TlsCipherAlgorithmEnumsDiagId = "SYSLIB0058";

// When adding a new diagnostic ID, add it to the table in docs\project\list-of-diagnostics.md as well.
// Keep new const identifiers above this comment.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,29 @@ public enum SecurityMasks
public partial class SecurityPackageContextConnectionInformation
{
internal SecurityPackageContextConnectionInformation() { }
#if NET10_0_OR_GREATER
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public System.Security.Authentication.CipherAlgorithmType AlgorithmIdentifier { get { throw null; } }
#if NET10_0_OR_GREATER
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public int CipherStrength { get { throw null; } }
#if NET10_0_OR_GREATER
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public int ExchangeStrength { get { throw null; } }
#if NET10_0_OR_GREATER
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public System.Security.Authentication.HashAlgorithmType Hash { get { throw null; } }
#if NET10_0_OR_GREATER
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public int HashStrength { get { throw null; } }
#if NET10_0_OR_GREATER
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public int KeyExchangeAlgorithm { get { throw null; } }
public System.DirectoryServices.Protocols.SecurityProtocol Protocol { get { throw null; } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public class SecurityPackageContextConnectionInformation
{
// Not marked as readonly to enable passing to Unsafe.As in GetPinnableReference.
private SecurityProtocol _securityProtocol;
#pragma warning disable SYSLIB0058 // Use NegotiatedCipherSuite.
private readonly CipherAlgorithmType _identifier;
private readonly int _strength;
private readonly HashAlgorithmType _hashAlgorithm;
#pragma warning restore SYSLIB0058 // Use NegotiatedCipherSuite.
private readonly int _hashStrength;
private readonly int _keyExchangeAlgorithm;
private readonly int _exchangeStrength;
Expand All @@ -83,17 +85,34 @@ internal SecurityPackageContextConnectionInformation()
}

public SecurityProtocol Protocol => _securityProtocol;

#if NET10_0_OR_GREATER
[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public CipherAlgorithmType AlgorithmIdentifier => _identifier;

#if NET10_0_OR_GREATER
[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public int CipherStrength => _strength;

#if NET10_0_OR_GREATER
[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public HashAlgorithmType Hash => _hashAlgorithm;

#if NET10_0_OR_GREATER
[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public int HashStrength => _hashStrength;

#if NET10_0_OR_GREATER
[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public int KeyExchangeAlgorithm => _keyExchangeAlgorithm;

#if NET10_0_OR_GREATER
[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public int ExchangeStrength => _exchangeStrength;

internal ref readonly byte GetPinnableReference() => ref Unsafe.As<SecurityProtocol, byte>(ref _securityProtocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ protected void TraceConnection(Stream stream)
{
if (stream is SslStream sslStream)
{
#pragma warning disable SYSLIB0058 // Use NegotiatedCipherSuite.
Trace(
$"{this}. Id:{Id}, " +
$"SslProtocol:{sslStream.SslProtocol}, NegotiatedApplicationProtocol:{sslStream.NegotiatedApplicationProtocol}, " +
$"NegotiatedCipherSuite:{sslStream.NegotiatedCipherSuite}, CipherAlgorithm:{sslStream.CipherAlgorithm}, CipherStrength:{sslStream.CipherStrength}, " +
$"HashAlgorithm:{sslStream.HashAlgorithm}, HashStrength:{sslStream.HashStrength}, " +
$"KeyExchangeAlgorithm:{sslStream.KeyExchangeAlgorithm}, KeyExchangeStrength:{sslStream.KeyExchangeStrength}, " +
$"LocalCertificate:{sslStream.LocalCertificate}, RemoteCertificate:{sslStream.RemoteCertificate}");
#pragma warning restore SYSLIB0058 // Use NegotiatedCipherSuite.
}
else
{
Expand Down
11 changes: 7 additions & 4 deletions src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ protected SocketException(System.Runtime.Serialization.SerializationInfo seriali
}
namespace System.Security.Authentication
{
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public enum CipherAlgorithmType
{
None = 0,
Expand All @@ -539,13 +540,15 @@ public enum CipherAlgorithmType
Aes = 26129,
Rc4 = 26625,
}
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public enum ExchangeAlgorithmType
{
None = 0,
RsaSign = 9216,
RsaKeyX = 41984,
DiffieHellman = 43522,
}
[Obsolete("KeyExchangeAlgorithm, KeyExchangeStrength, CipherAlgorithm, CipherAlgorithmStrength, HashAlgorithm and HashStrength properties of SslStream are obsolete. Use NegotiatedCipherSuite instead.", DiagnosticId = "SYSLIB0058", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public enum HashAlgorithmType
{
None = 0,
Expand All @@ -563,11 +566,11 @@ public enum SslProtocols
Ssl2 = 12,
[System.ObsoleteAttribute("SslProtocols.Ssl3 has been deprecated and is not supported.")]
Ssl3 = 48,
[System.ObsoleteAttribute("TLS versions 1.0 and 1.1 have known vulnerabilities and are not recommended. Use a newer TLS version instead, or use SslProtocols.None to defer to OS defaults.", DiagnosticId="SYSLIB0039", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("TLS versions 1.0 and 1.1 have known vulnerabilities and are not recommended. Use a newer TLS version instead, or use SslProtocols.None to defer to OS defaults.", DiagnosticId = "SYSLIB0039", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
Tls = 192,
[System.ObsoleteAttribute("SslProtocols.Default has been deprecated and is not supported.")]
Default = 240,
[System.ObsoleteAttribute("TLS versions 1.0 and 1.1 have known vulnerabilities and are not recommended. Use a newer TLS version instead, or use SslProtocols.None to defer to OS defaults.", DiagnosticId="SYSLIB0039", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("TLS versions 1.0 and 1.1 have known vulnerabilities and are not recommended. Use a newer TLS version instead, or use SslProtocols.None to defer to OS defaults.", DiagnosticId = "SYSLIB0039", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
Tls11 = 768,
Tls12 = 3072,
Tls13 = 12288,
Expand All @@ -577,8 +580,8 @@ namespace System.Security.Authentication.ExtendedProtection
{
public abstract partial class ChannelBinding : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
{
protected ChannelBinding() : base (default(bool)) { }
protected ChannelBinding(bool ownsHandle) : base (default(bool)) { }
protected ChannelBinding() : base(default(bool)) { }
protected ChannelBinding(bool ownsHandle) : base(default(bool)) { }
public abstract int Size { get; }
}
public enum ChannelBindingKind
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Net;
using System.Runtime.InteropServices;

Expand All @@ -24,6 +25,7 @@ public enum SslProtocols
Default = Ssl3 | Tls
}

[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public enum ExchangeAlgorithmType
{
None = 0,
Expand All @@ -32,6 +34,7 @@ public enum ExchangeAlgorithmType
DiffieHellman = (Interop.Crypt32.ALG_CLASS_KEY_EXCHANGE | Interop.Crypt32.ALG_TYPE_DH | Interop.Crypt32.ALG_SID_DH_EPHEM),
}

[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public enum CipherAlgorithmType
{
None = 0, // No encryption
Expand All @@ -46,6 +49,7 @@ public enum CipherAlgorithmType
Null = (Interop.Crypt32.ALG_CLASS_ENCRYPT), // 0-bit NULL cipher algorithm
}

[Obsolete(Obsoletions.TlsCipherAlgorithmEnumsMessage, DiagnosticId = Obsoletions.TlsCipherAlgorithmEnumsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public enum HashAlgorithmType
{
None = 0,
Expand Down
Loading

0 comments on commit 70583d4

Please sign in to comment.