未验证 提交 4cfe07ce 编写于 作者: K Kevin Jones 提交者: GitHub

Obsolete ToXmlString and FromXmlString on ECC types

Co-authored-by: NJeremy Barton <jbarton@microsoft.com>
上级 819b654e
......@@ -96,6 +96,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0039`__ | 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. |
| __`SYSLIB0040`__ | EncryptionPolicy.NoEncryption and AllowEncryption significantly reduce security and should not be used in production code. |
| __`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. |
| __`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. |
## Analyzer Warnings
......
......@@ -135,5 +135,8 @@ internal static class Obsoletions
internal const string Rfc2898OutdatedCtorMessage = "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.";
internal const string Rfc2898OutdatedCtorDiagId = "SYSLIB0041";
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.";
internal const string EccXmlExportImportDiagId = "SYSLIB0042";
}
}
......@@ -24,7 +24,9 @@ internal ECDiffieHellmanAndroidPublicKey(ECParameters parameters)
_key = new ECAndroid(parameters);
}
#pragma warning disable 0672 // Member overrides an obsolete member.
public override string ToXmlString()
#pragma warning restore 0672
{
throw new PlatformNotSupportedException();
}
......
......@@ -31,7 +31,9 @@ internal ECDiffieHellmanOpenSslPublicKey(ECParameters parameters)
_key = new ECOpenSsl(parameters);
}
#pragma warning disable 0672 // Member overrides an obsolete member.
public override string ToXmlString()
#pragma warning restore 0672
{
throw new PlatformNotSupportedException();
}
......
......@@ -251,7 +251,9 @@ public ECDiffieHellmanSecurityTransformsPublicKey(ECParameters ecParameters)
_ecc.ImportParameters(ecParameters);
}
#pragma warning disable 0672 // Member overrides an obsolete member.
public override string ToXmlString()
#pragma warning restore 0672
{
throw new PlatformNotSupportedException();
}
......
......@@ -996,12 +996,14 @@ public sealed partial class ECDiffieHellmanCng : System.Security.Cryptography.EC
public override byte[] ExportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters) { throw null; }
public override System.Security.Cryptography.ECParameters ExportExplicitParameters(bool includePrivateParameters) { throw null; }
public override System.Security.Cryptography.ECParameters ExportParameters(bool includePrivateParameters) { throw null; }
[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}")]
public void FromXmlString(string xml, System.Security.Cryptography.ECKeyXmlFormat format) { }
public override void GenerateKey(System.Security.Cryptography.ECCurve curve) { }
public override void ImportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<byte> passwordBytes, System.ReadOnlySpan<byte> source, out int bytesRead) { throw null; }
public override void ImportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<char> password, System.ReadOnlySpan<byte> source, out int bytesRead) { throw null; }
public override void ImportParameters(System.Security.Cryptography.ECParameters parameters) { }
public override void ImportPkcs8PrivateKey(System.ReadOnlySpan<byte> source, out int bytesRead) { throw null; }
[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}")]
public string ToXmlString(System.Security.Cryptography.ECKeyXmlFormat format) { throw null; }
public override bool TryExportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<byte> passwordBytes, System.Security.Cryptography.PbeParameters pbeParameters, System.Span<byte> destination, out int bytesWritten) { throw null; }
public override bool TryExportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters, System.Span<byte> destination, out int bytesWritten) { throw null; }
......@@ -1016,8 +1018,10 @@ public sealed partial class ECDiffieHellmanCngPublicKey : System.Security.Crypto
public override System.Security.Cryptography.ECParameters ExportParameters() { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static System.Security.Cryptography.ECDiffieHellmanPublicKey FromByteArray(byte[] publicKeyBlob, System.Security.Cryptography.CngKeyBlobFormat format) { throw null; }
[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}")]
public static System.Security.Cryptography.ECDiffieHellmanCngPublicKey FromXmlString(string xml) { throw null; }
public System.Security.Cryptography.CngKey Import() { throw null; }
[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}")]
public override string ToXmlString() { throw null; }
}
public enum ECDiffieHellmanKeyDerivationFunction
......@@ -1073,6 +1077,7 @@ public abstract partial class ECDiffieHellmanPublicKey : System.IDisposable
public virtual System.Security.Cryptography.ECParameters ExportParameters() { throw null; }
public virtual byte[] ExportSubjectPublicKeyInfo() { throw null; }
public virtual byte[] ToByteArray() { throw null; }
[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}")]
public virtual string ToXmlString() { throw null; }
public virtual bool TryExportSubjectPublicKeyInfo(System.Span<byte> destination, out int bytesWritten) { throw null; }
}
......@@ -1147,6 +1152,7 @@ public sealed partial class ECDsaCng : System.Security.Cryptography.ECDsa
public override byte[] ExportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters) { throw null; }
public override System.Security.Cryptography.ECParameters ExportExplicitParameters(bool includePrivateParameters) { throw null; }
public override System.Security.Cryptography.ECParameters ExportParameters(bool includePrivateParameters) { throw null; }
[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}")]
public void FromXmlString(string xml, System.Security.Cryptography.ECKeyXmlFormat format) { }
public override void GenerateKey(System.Security.Cryptography.ECCurve curve) { }
protected override byte[] HashData(byte[] data, int offset, int count, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; }
......@@ -1159,6 +1165,7 @@ public sealed partial class ECDsaCng : System.Security.Cryptography.ECDsa
public byte[] SignData(byte[] data, int offset, int count) { throw null; }
public byte[] SignData(System.IO.Stream data) { throw null; }
public override byte[] SignHash(byte[] hash) { throw null; }
[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}")]
public string ToXmlString(System.Security.Cryptography.ECKeyXmlFormat format) { throw null; }
public override bool TryExportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<byte> passwordBytes, System.Security.Cryptography.PbeParameters pbeParameters, System.Span<byte> destination, out int bytesWritten) { throw null; }
public override bool TryExportEncryptedPkcs8PrivateKey(System.ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters, System.Span<byte> destination, out int bytesWritten) { throw null; }
......
......@@ -258,7 +258,9 @@ public ECDiffieHellmanCng(ECCurve curve)
public SafeNCryptSecretHandle DeriveSecretAgreementHandle(CngKey otherPartyPublicKey) => null!;
public SafeNCryptSecretHandle DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey otherPartyPublicKey) => null!;
public byte[] DeriveKeyMaterial(CngKey otherPartyPublicKey) => null!;
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public void FromXmlString(string xml, ECKeyXmlFormat format) { }
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public string ToXmlString(ECKeyXmlFormat format) => null!;
public override ECDiffieHellmanPublicKey PublicKey => null!;
}
......@@ -275,11 +277,17 @@ public static ECDiffieHellmanPublicKey FromByteArray(byte[] publicKeyBlob, CngKe
throw new PlatformNotSupportedException(SR.PlatformNotSupported_CryptographyCng);
}
// Also throws in Windows, no SupportedOSPlatform required.
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static ECDiffieHellmanCngPublicKey FromXmlString(string xml)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_CryptographyCng);
}
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public override string ToXmlString()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_CryptographyCng);
}
}
public sealed partial class ECDsaCng : ECDsa
{
......@@ -309,10 +317,12 @@ public ECDsaCng(ECCurve curve)
public CngAlgorithm HashAlgorithm { get => null!; set { } }
public CngKey Key => null!;
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public void FromXmlString(string xml, ECKeyXmlFormat format) { }
public byte[] SignData(byte[] data) => null!;
public byte[] SignData(byte[] data, int offset, int count) => null!;
public byte[] SignData(System.IO.Stream data) => null!;
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public string ToXmlString(ECKeyXmlFormat format) => null!;
public bool VerifyData(byte[] data, byte[] signature) => false;
public bool VerifyData(byte[] data, int offset, int count, byte[] signature) => false;
......
......@@ -5,11 +5,13 @@ namespace System.Security.Cryptography
{
public sealed partial class ECDiffieHellmanCng : ECDiffieHellman
{
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public void FromXmlString(string xml, ECKeyXmlFormat format)
{
throw new PlatformNotSupportedException();
}
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public string ToXmlString(ECKeyXmlFormat format)
{
throw new PlatformNotSupportedException();
......
......@@ -34,11 +34,13 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public override string ToXmlString()
{
throw new PlatformNotSupportedException();
}
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static ECDiffieHellmanCngPublicKey FromXmlString(string xml)
{
throw new PlatformNotSupportedException();
......
......@@ -33,6 +33,7 @@ public virtual byte[] ToByteArray()
}
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public virtual string ToXmlString()
{
throw new NotImplementedException(SR.NotSupported_SubclassOverride);
......
......@@ -197,7 +197,9 @@ protected override void Dispose(bool disposing)
public override byte[] ToByteArray() => _wrapped.ToByteArray();
#pragma warning disable 0672, SYSLIB0042 // Member overrides an obsolete member, ToXmlString is obsolete.
public override string ToXmlString() => _wrapped.ToXmlString();
#pragma warning restore 0672, SYSLIB0042
public override bool Equals(object? obj) => _wrapped.Equals(obj);
......
......@@ -127,6 +127,7 @@ private byte[] ExportEncryptedPkcs8(ReadOnlySpan<char> pkcs8Password, int kdfCou
out bytesWritten);
}
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public void FromXmlString(string xml, ECKeyXmlFormat format)
=> throw new PlatformNotSupportedException();
......@@ -139,6 +140,7 @@ public byte[] SignData(byte[] data)
public byte[] SignData(Stream data)
=> SignData(data, new HashAlgorithmName(HashAlgorithm.Algorithm));
[Obsolete(Obsoletions.EccXmlExportImportMessage, DiagnosticId = Obsoletions.EccXmlExportImportDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public string ToXmlString(ECKeyXmlFormat format)
=> throw new PlatformNotSupportedException();
......
......@@ -34,7 +34,9 @@ public void TestToXmlString()
byte[] arg = new byte[1] { 1 };
var pk = new TestDerived(arg);
#pragma warning disable SYSLIB0042 // ToXmlString and FromXmlString are obsolete
Assert.Throws<NotImplementedException>(() => pk.ToXmlString());
#pragma warning restore SYSLIB0042
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册