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
Support ECDiffieHellman on X509Certificate2 #42180
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @jeffhandley |
...libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Helpers.cs
Show resolved
Hide resolved
...raphy.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
Show resolved
Hide resolved
Hm. CNG is behaving differently between Win10 and Win8.1/7. I suppose this is related to CNG's strong opinion that EC keys are either ECDH or ECDSA. |
...urity.Cryptography.X509Certificates/src/Internal/Cryptography/CertificateExtensionsCommon.cs
Show resolved
Hide resolved
...s/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.OSX/X509Pal.cs
Outdated
Show resolved
Hide resolved
...urity.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509Encoder.cs
Outdated
Show resolved
Hide resolved
...ity.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs
Outdated
Show resolved
Hide resolved
...Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/PublicKey.cs
Outdated
Show resolved
Hide resolved
...raphy.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.X509Certificates/tests/PublicKeyTests.cs
Outdated
Show resolved
Hide resolved
Windows 8.1 and below needs to be explicitly told that the public key it is handling is for key agreement purposes.
Depends on your definition of "make sense" 😄. Apparently the private keys default to ECDH but the public keys were defaulting to ECDSA, and whatever lookup it did in the CryptFindOID universe returned multiple hits, ECDSA first... and that flag says "if something can't encrypt, I don't want it".. and while ECDH can't encrypt, it's purpose is eventually encryption, so it's marked as "encryption". Does any of that make sense? Not especially 😄. Does the code read cleanly? Sure. Does it make tests pass? Apparently 😄. |
...tography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509CertificateReader.cs
Outdated
Show resolved
Hide resolved
...ity.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs
Outdated
Show resolved
Hide resolved
...Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/PublicKey.cs
Outdated
Show resolved
Hide resolved
...Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/PublicKey.cs
Outdated
Show resolved
Hide resolved
...raphy.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
Outdated
Show resolved
Hide resolved
...raphy.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
Outdated
Show resolved
Hide resolved
...rity.Cryptography.X509Certificates/tests/CertificateCreation/CertificateRequestUsageTests.cs
Outdated
Show resolved
Hide resolved
...rity.Cryptography.X509Certificates/tests/CertificateCreation/CertificateRequestUsageTests.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.X509Certificates/tests/PublicKeyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.X509Certificates/tests/PublicKeyTests.cs
Show resolved
Hide resolved
PublicKey should at least be able to create a SPKI for any algorithm.
Verify we can sign arbitrary SPKIs.
Add a test that we can still round-trip keys that contain invalid parameters but are well structured.
@bartonjs thanks as always for the thoughtful feedback. I think I have addressed all of the points you have made so far. |
Guessing macOS is going to blow up with a bad DSA at usage time, not import time. No idea what what it is actually doing with an 8-bit DSA key. |
...raphy.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
Outdated
Show resolved
Hide resolved
Well, p is 0, so that's a 0-bit key, no? 😄. I'd probably delete one of the integers out of the DSA-Params struct so it doesn't decode correctly, making the whole "bad DSA" SPKI
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again: Thanks, @vcsjones!
This adds
ECDiffieHellman
functionality toX509Certificate2
. In addition, this also adds arbitrarySubjectPublicKeyInfo
support forPublicKey
.This also makes some under-the-hood changes. Previously, we were always able to know what type of algorithm was used with a given certificate based on the certificate SPKI's OID. In the case of id-ecPublicKey, this is not true anymore. Other plumbing changes include changes to support
ImportFromPem
onX509Certificate2
.Work left to be done:
Closes #413