-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix certificate ctx on windows and macOS #39818
Conversation
Tagging subscribers to this area: @dotnet/ncl |
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNetworkStreamTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Linux.cs
Outdated
Show resolved
Hide resolved
} | ||
|
||
// OS failed to build the chain but we have at least some intermediates. | ||
// We will try to add them to "Intermediate Certification Authorities" store. |
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.
Do you really want to add all intermediates? Or just the ones that the OS ends up using in a chain?
e.g. Add all of intermediates to chain.ChainPolicy.ExtraStore and build again; then add anything relevant (preferably using a diffing algorithm so that it doesn't potentially reset custom store property overrides).
Using a second chain object (you could copy the policy object over) would make the diff easy, just walk each position and compare that cert.RawData values SequenceEqual.
Ideally, after each add you'd rerun the offline/no-extra build to see if you can avoid invalidating existing higher-scoped entries.
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.
(While a diffing algorithm and a while loop sound potentially expensive, most chains are three items long, so there aren't many iterations)
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.
I was considering to add some more complicated logic. But as you said if most chains are 3 long, it does not matter that much. I assumed that adding intermediate once to store is cheap enough so I decided not to care.
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.
There's one thing to check:
- Add an intermediate to the store
- Open the intermediates store in MMC (e.g. add snap-in, certificates, local computer, then pick Intermediate Certificate Authorities / Certificates in the nav tree)
- Pick that same certificate, right click, Properties
- Pick "Enable only the following purposes"
- Toggle some checkmarks
- Use the API as you have it
- Right click on the Certificates entry in the nav bar and refresh
- Reopen the properties dialog.
If the property resets, we need to do complex stuff here. If it doesn't, we're good. (I think we do "merge properties", which should (generally) be safe, but it's good to test that before we run the risk of altering machine state)
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.
that assumes same CA set between runs, right? (right now we generate unique set for each test run and I had situation where it would build up before adding cleanup to the tests)
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.
It assumes that we ever get something in the intermediates
collection that's already in the store. E.g. if what we need is a 4 hop chain:
- root -> intermed1 -> intermed2 -> end-entity
And intermed1 is already in the store, but intermed2 wasn't; we'll end up calling store.Add(intermed1) which will cause the merge logic to apply. Since it changes system persisted state we need to be careful to ensure it's only additive, not destructive.
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.
here is what I did:
- modified the test helper to save/load certificates from pfx and I disabled the cleanup
- I run the test and I check both CA.
- I removed root CA, run tests and verified that it triggers the adding logic
- I removed root again and I modified properties on intermediate and I also added friendly name
- run test again. Root CA was added again and intermediate preserved with my modifications
so the conclusion is that adding existing certificate is not destructive.
src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Security/tests/FunctionalTests/TestHelper.cs
Outdated
Show resolved
Hide resolved
I made suggested changes and also fix macOS. That needed more structural changes as the flow is different. |
...libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Windows.cs
Show resolved
Hide resolved
...libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Security/src/System/Net/Security/SecureChannel.cs
Show resolved
Hide resolved
src/libraries/System.Net.Security/src/System/Net/Security/Pal.OSX/SafeFreeSslCredentials.cs
Outdated
Show resolved
Hide resolved
can you please take another look @bartonjs ? |
This is follow up on #38364
After some search, it seems like there is really no way how to give certificate chain to Schannel.
So instead, we try to add certificates to intermediate CA store. So when Schannel/CAPI needs them, they can get them without network IO.
I updated existing tests to fail if peer does not send full chain (-1)
Fixes #35844