-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider deprecating or annotating a few S.S.C.X509Certificates members #47977
Comments
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsThere are a few APIs in System.Security.Cryptography.X509Certificates that it might be worth obsoleting, or some variation of
|
I guess to "proposalify" this: public class X509Certificate2
{
+ [SupportedOSPlatform("windows")]
public bool Archived { get; set; }
+ [SupportedOSPlatform("windows")]
public string FriendlyName { get; set; }
+ [Obsolete("This is no longer the recommended way of retrieving the private key. Use the appropriate GetPrivateKey or CopyWithPrivateKey method instead.")]
public AsymmetricAlgorithm PrivateKey { get; set; }
+ [Obsolete("X509Certificate2 is immutable on this platform. Use a different constructor overload instead.")]
public X509Certificate2();
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(byte[] rawData);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(byte[] rawData, SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(byte[] rawData, string? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(string fileName);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(string fileName, System.Security.SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(string fileName, string? password, X509KeyStorageFlags keyStorageFlags);
}
public class X509Certificate
{
+ [Obsolete("X509Certificate is immutable on this platform. Use a different constructor overload instead.")]
public X509Certificate();
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor instead.")]
public void Import(byte[] rawData);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor instead.")]
public void Import(byte[] rawData, SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor instead.")]
public void Import(byte[] rawData, string? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor instead.")]
public void Import(string fileName);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor instead.")]
public void Import(string fileName, System.Security.SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor instead.")]
public void Import(string fileName, string? password, X509KeyStorageFlags keyStorageFlags);
}
public class PublicKey
{
+ [Obsolete("The key property is no longer recommended for use. Use the appropriate GetPublicKey method instead.")]
public AsymmetricAlgorithm Key { get; }
} |
Have we put Obsolete on X509Certificate2.PrivateKey and PublicKey.Key yet? Though to fully obsolete PublicKey we would probably want to put GetRSAPublicKey/etc on it. (Or just feel we got far enough there by adding SPKI export) |
Not yet.
That one makes sense to me since there are good APIs to success it, so I added it.
I'm less convinced there is a good replacement for that. The SPKI APIs work, but feel a little clunky using X509Certificate2 cert = new X509Certificate2();
using RSA rsa = RSA.Create();
byte[] spki = cert.PublicKey.ExportSubjectPublicKeyInfo();
rsa.ImportSubjectPublicKeyInfo(spki, out _); Perhaps we can open a separate proposal for that (opened #48510) Another one that strikes me as a bit weird is the parameterless constructor for |
Yeah, it just produces a certificate in the same state as one gets in after Dispose(), so it's probably not all that useful. Obsolete away! |
How accidentally convenient that I skipped over this one to get the new methods in. Thanks 😄. |
public class X509Certificate2
{
public bool Archived {
get;
+ [SupportedOSPlatform("windows")]
set;
}
public string FriendlyName
{
get;
+ [SupportedOSPlatform("windows")]
set;
}
+ [Obsolete("This is no longer the recommended way of retrieving the private key. Use the appropriate GetPrivateKey or CopyWithPrivateKey method instead.")]
public AsymmetricAlgorithm PrivateKey { get; set; }
+ [Obsolete("X509Certificate2 is immutable on this platform. Use a different constructor overload instead.")]
public X509Certificate2();
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(byte[] rawData);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(byte[] rawData, SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(byte[] rawData, string? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(string fileName);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(string fileName, System.Security.SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate2 is immutable on this platform. Use the equivalent constructor instead.")]
public override void Import(string fileName, string? password, X509KeyStorageFlags keyStorageFlags);
}
public class X509Certificate
{
+ [Obsolete("X509Certificate is immutable on this platform. Use a different constructor overload instead.")]
public X509Certificate();
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor on X509Certificate2 instead.")]
public void Import(byte[] rawData);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor on X509Certificate2 instead.")]
public void Import(byte[] rawData, SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor on X509Certificate2 instead.")]
public void Import(byte[] rawData, string? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor on X509Certificate2 instead.")]
public void Import(string fileName);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor on X509Certificate2 instead.")]
public void Import(string fileName, System.Security.SecureString? password, X509KeyStorageFlags keyStorageFlags);
+ [Obsolete("X509Certificate is immutable on this platform. Use the equivalent constructor on X509Certificate2 instead.")]
public void Import(string fileName, string? password, X509KeyStorageFlags keyStorageFlags);
}
public class PublicKey
{
+ [Obsolete("The key property is no longer recommended for use. Use the appropriate GetPublicKey method instead.")]
public AsymmetricAlgorithm Key { get; }
} |
There are a few APIs in System.Security.Cryptography.X509Certificates that might be worth obsoleting, or some variation of
{Un}SupportedOSPlatformAttribute
on them.X509Certificate2.FriendlyName
- Consider marking this[SupportedOSPlatformAttribute("windows")]
. This API returns an empty string on non-Windows, and throws when being set on non-Windows.X509Certificate2.Archived
- Consider marking this[SupportedOSPlatformAttribute("windows")]
. This API returnsfalse
on non-Windows, and throws when being set on non-Windows.X509Certificate.Import
- Consider deprecating or obsoleting this. All overloads for this API are going to throw.The text was updated successfully, but these errors were encountered: