-
Notifications
You must be signed in to change notification settings - Fork 5k
X509Certificate2(X509Certificate) missing #15713
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
Comments
/cc: @ericstj @weshaggard @stephentoub @CIPop @SidharthNabar @terrajobst @mconnew Related: #15708. I don't think it is possible to upconvert an X509Certificate to an X509Certificate2. The other way works since X509Certificate2 derives from X509Certificate. Actually, we are considering changing the API signature of what SslStream takes to use X509Certificate2 in a manner similar to how WinHttpHandler.ServerCertificateCallback takes a Func which uses X509Certificate2. However, doing a change like that will break .NET Desktop API source compat. But it is something we are discussing. |
/cc: @bartonjs |
desktop framework allows conversion via X509Certificate2(X509Certificate) |
@morganbr It seems like a reasonable thing to me, was there a reason for leaving it out of the contract that you can recall? |
From my use-case with SslStream I've noticed another interesting thing. The validation callback with signature X509Certificate is passed a X509Certificate2 (on windows desktop and windows coreclr). |
@bartonjs We've had the same problem during the implementation for SslStream. Since X509Certificate is deprecated but it is locked down by the Desktop API surface, the implementation in CoreFX forces all certificates to be X509Certificate2 and will throw if a cast from X509Certificate to X509Certificate2 is not possible. @tmds As a workaround, in CoreFX (at least for Windows) it's safe to cast to an X509Certificate2. |
The conversion constructor and copy constructor have a very nasty side effect on desktop that we didn't want to have in Core -- they necessarily both have handles to the same underlying native object. That means we can't handle things like deleting ephemeral keys or changing properties correctly on both objects. |
@CIPop my comment and your comment above are saying something different |
Running this code:
Gives the same output on .NET Framework and .NET Core:
|
@tmds There are a couple workarounds that you could utilize:
But, hopefully, I can just get the object type upgrade change through :). |
Since the only instantiator of X509Certificate (non-2) objects in Core has been removed; I'm going to close this issue. If you find that you are still encountering problems you can't work around, please reopen. |
I am using SslStream with a userCertificateValidationCallback. The callback is passed a X509Certificate which I would like to convert to a X509Certificate2. The constructor to convert the certificate is missing/not yet implemented.
Somewhat related: perhaps SslStream should pass a X509Certificate2 instead of a X509Certificate to the userCertificateValidationCallback?
The text was updated successfully, but these errors were encountered: