Skip to content

Commit 05fc5df

Browse files
authored
Obsolete non-specific key blob support on ECDiffieHellmanPublicKey
1 parent 356e01e commit 05fc5df

10 files changed

+24
-0
lines changed

Diff for: docs/project/list-of-diagnostics.md

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
9797
| __`SYSLIB0040`__ | EncryptionPolicy.NoEncryption and AllowEncryption significantly reduce security and should not be used in production code. |
9898
| __`SYSLIB0041`__ | The default hash algorithm and iteration counts in Rfc2898DeriveBytes constructors are outdated and insecure. Use a constructor that accepts the hash algorithm and the number of iterations. |
9999
| __`SYSLIB0042`__ | ToXmlString and FromXmlString have no implementation for ECC types, and are obsolete. Use a standard import and export format such as ExportSubjectPublicKeyInfo or ImportSubjectPublicKeyInfo for public keys and ExportPkcs8PrivateKey or ImportPkcs8PrivateKey for private keys. |
100+
| __`SYSLIB0043`__ | ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor do not have a consistent and interoperable implementation on all platforms. Use ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() instead. |
100101

101102
## Analyzer Warnings
102103

Diff for: src/libraries/Common/src/System/Obsoletions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,8 @@ internal static class Obsoletions
138138

139139
internal const string EccXmlExportImportMessage = "ToXmlString and FromXmlString have no implementation for ECC types, and are obsolete. Use a standard import and export format such as ExportSubjectPublicKeyInfo or ImportSubjectPublicKeyInfo for public keys and ExportPkcs8PrivateKey or ImportPkcs8PrivateKey for private keys.";
140140
internal const string EccXmlExportImportDiagId = "SYSLIB0042";
141+
142+
internal const string EcDhPublicKeyBlobMessage = "ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor do not have a consistent and interoperable implementation on all platforms. Use ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() instead.";
143+
internal const string EcDhPublicKeyBlobDiagId = "SYSLIB0043";
141144
}
142145
}

Diff for: src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroidPublicKey.cs

+2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public override string ToXmlString()
3131
throw new PlatformNotSupportedException();
3232
}
3333

34+
#pragma warning disable 0672 // Member overrides an obsolete member.
3435
public override byte[] ToByteArray()
36+
#pragma warning restore 0672
3537
{
3638
throw new PlatformNotSupportedException();
3739
}

Diff for: src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSslPublicKey.cs

+2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public override string ToXmlString()
3838
throw new PlatformNotSupportedException();
3939
}
4040

41+
#pragma warning disable 0672 // Member overrides an obsolete member.
4142
public override byte[] ToByteArray()
43+
#pragma warning restore 0672
4244
{
4345
throw new PlatformNotSupportedException();
4446
}

Diff for: src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs

+2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ public override string ToXmlString()
262262
/// There is no key blob format for OpenSSL ECDH like there is for Cng ECDH. Instead of allowing
263263
/// this to return a potentially confusing empty byte array, we opt to throw instead.
264264
/// </summary>
265+
#pragma warning disable 0672 // Member overrides an obsolete member.
265266
public override byte[] ToByteArray()
267+
#pragma warning restore 0672
266268
{
267269
throw new PlatformNotSupportedException();
268270
}

Diff for: src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1070,12 +1070,14 @@ public override void ImportParameters(System.Security.Cryptography.ECParameters
10701070
public abstract partial class ECDiffieHellmanPublicKey : System.IDisposable
10711071
{
10721072
protected ECDiffieHellmanPublicKey() { }
1073+
[System.ObsoleteAttribute("ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor do not have a consistent and interoperable implementation on all platforms. Use ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() instead.", DiagnosticId="SYSLIB0043", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
10731074
protected ECDiffieHellmanPublicKey(byte[] keyBlob) { }
10741075
public void Dispose() { }
10751076
protected virtual void Dispose(bool disposing) { }
10761077
public virtual System.Security.Cryptography.ECParameters ExportExplicitParameters() { throw null; }
10771078
public virtual System.Security.Cryptography.ECParameters ExportParameters() { throw null; }
10781079
public virtual byte[] ExportSubjectPublicKeyInfo() { throw null; }
1080+
[System.ObsoleteAttribute("ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor do not have a consistent and interoperable implementation on all platforms. Use ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() instead.", DiagnosticId="SYSLIB0043", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
10791081
public virtual byte[] ToByteArray() { throw null; }
10801082
[System.ObsoleteAttribute("ToXmlString and FromXmlString have no implementation for ECC types, and are obsolete. Use a standard import and export format such as ExportSubjectPublicKeyInfo or ImportSubjectPublicKeyInfo for public keys and ExportPkcs8PrivateKey or ImportPkcs8PrivateKey for private keys.", DiagnosticId="SYSLIB0042", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
10811083
public virtual string ToXmlString() { throw null; }

Diff for: src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs

+4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public sealed partial class ECDiffieHellmanCngPublicKey : ECDiffieHellmanPublicK
1717
/// <summary>
1818
/// Wrap a CNG key
1919
/// </summary>
20+
#pragma warning disable SYSLIB0043 // byte[] constructor on ECDiffieHellmanPublicKey is obsolete
2021
internal ECDiffieHellmanCngPublicKey(byte[] keyBlob, string? curveName, CngKeyBlobFormat format) : base(keyBlob)
22+
#pragma warning restore SYSLIB0043
2123
{
2224
_format = format;
2325
// Can be null for P256, P384, P521, or an explicit blob
@@ -94,7 +96,9 @@ public CngKey Import()
9496
throw new ObjectDisposedException(nameof(ECDiffieHellmanCngPublicKey));
9597
}
9698

99+
#pragma warning disable SYSLIB0043 // ToByteArray is obsolete.
97100
return CngKey.Import(ToByteArray(), _curveName, BlobFormat);
101+
#pragma warning restore SYSLIB0043
98102
}
99103

100104
/// <summary>

Diff for: src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECDiffieHellmanPublicKey.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ protected ECDiffieHellmanPublicKey()
1515
_keyBlob = Array.Empty<byte>();
1616
}
1717

18+
[Obsolete(Obsoletions.EcDhPublicKeyBlobMessage, DiagnosticId = Obsoletions.EcDhPublicKeyBlobDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
1819
protected ECDiffieHellmanPublicKey(byte[] keyBlob!!)
1920
{
2021
_keyBlob = (byte[])keyBlob.Clone();
@@ -27,6 +28,7 @@ public void Dispose()
2728

2829
protected virtual void Dispose(bool disposing) { }
2930

31+
[Obsolete(Obsoletions.EcDhPublicKeyBlobMessage, DiagnosticId = Obsoletions.EcDhPublicKeyBlobDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
3032
public virtual byte[] ToByteArray()
3133
{
3234
return (byte[])_keyBlob.Clone();

Diff for: src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECDiffieHellmanWrapper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ protected override void Dispose(bool disposing)
195195
}
196196
}
197197

198+
#pragma warning disable 0672, SYSLIB0043 // Member overrides an obsolete member, ToByteArray is obsolete.
198199
public override byte[] ToByteArray() => _wrapped.ToByteArray();
200+
#pragma warning restore 0672, SYSLIB0043
199201

200202
#pragma warning disable 0672, SYSLIB0042 // Member overrides an obsolete member, ToXmlString is obsolete.
201203
public override string ToXmlString() => _wrapped.ToXmlString();

Diff for: src/libraries/System.Security.Cryptography/tests/ECDiffieHellmanPublicKeyTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class ECDiffieHellmanPublicKeyTests
1010
{
1111
private class TestDerived : ECDiffieHellmanPublicKey
1212
{
13+
#pragma warning disable SYSLIB0043 // byte ctor is obsolete
1314
public TestDerived(byte[] keyBlob) : base(keyBlob) { }
15+
#pragma warning restore SYSLIB0043
1416
}
1517

1618
[Fact]
@@ -25,7 +27,9 @@ public void TestToByteArray()
2527
byte[] arg = new byte[1] { 1 };
2628
var pk = new TestDerived(arg);
2729

30+
#pragma warning disable SYSLIB0043 // ToByteArray is obsolete
2831
Assert.Equal(1, pk.ToByteArray()[0]);
32+
#pragma warning restore SYSLIB0043
2933
}
3034

3135
[Fact]

0 commit comments

Comments
 (0)