-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Description
If you attempt to create a self signed certificate with CertificateRequest with an ECDsa key and a key usage that makes the certificate ineligible for ECDSA usage, it fails with a less-than-clear exception.
using ECDsa ecdsa = ECDsa.Create();
CertificateRequest req = new CertificateRequest("CN=who", ecdsa, HashAlgorithmName.SHA256);
req.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.KeyAgreement, true));
req.CreateSelfSigned(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(42));Produces:
Unhandled exception. System.ArgumentException: The provided key does not match the public key algorithm for this certificate.
at System.Security.Cryptography.X509Certificates.ECDsaCertificateExtensions.CopyWithPrivateKey(X509Certificate2 certificate, ECDsa privateKey)
at System.Security.Cryptography.X509Certificates.CertificateRequest.CreateSelfSigned(DateTimeOffset notBefore, DateTimeOffset notAfter)
We should validate the key usages and key type in CreateSelfSigned and give a better exception.
Reproduced in Core 3.1 and 5.0 RC1.