runtime icon indicating copy to clipboard operation
runtime copied to clipboard

HttpClient is not providing complete certificate chain on windows

Open 3lcarry opened this issue 7 years ago • 11 comments

Hi, We are facing issue when authenticate against a server expecting client certificate + intermediate certificate. The HttpClient is only sending the client certificate and the pfx file is build containing the 3 certificates

On the attached file you can see an example of the issue, using curl sample under the curl folder is possible to authenticate against the server validating the intermediate certificate but using the HttpClient provided is not working

CertificateAuthentication.zip

3lcarry avatar Jul 30 '19 09:07 3lcarry

cc: @bartonjs

stephentoub avatar Jul 30 '19 13:07 stephentoub

Hi @stephentoub @bartonjs any update on this issue?

unaizorrilla avatar Jul 31 '19 11:07 unaizorrilla

any update on this issue?

Since it was opened only yesterday? No.

stephentoub avatar Jul 31 '19 12:07 stephentoub

It's my understanding that it doesn't matter that the entire chain is in the PFX, but that Windows TLS does the chain walk itself at the very end to decide what to put on the wire.

To ensure the intermediate(s) get sent, you could load the PFX, add the certs without a known private key to the CurrentUser\CA or LocalMachine\CA certificate store, and then use HttpClient. The CA store is (I'm 99% sure) just a cache of intermediates, it provides no trust.

bartonjs avatar Jul 31 '19 14:07 bartonjs

Hi @bartonjs ,

Thank you for your hint, I was able to solve this, just a note for someone having a similar issue on Azure Webapps, for normal web app if you install the public certificates and load them using the appsetting WEBSITE_LOAD_CERTIFICATES works fine

But for Web apps inside an Azure App Services Environment (ASE) you need to load them using the app setting WEBSITE_LOAD_ROOT_CERTIFICATES and specifying each one you need to load

Thank you

3lcarry avatar Aug 01 '19 15:08 3lcarry

It's my understanding that it doesn't matter that the entire chain is in the PFX, but that Windows TLS does the chain walk itself at the very end to decide what to put on the wire. To ensure the intermediate(s) get sent, you could load the PFX, add the certs without a known private key to the CurrentUser\CA or LocalMachine\CA certificate store, and then use HttpClient. The CA store is (I'm 99% sure) just a cache of intermediates, it provides no trust.

@bartonjs So, this is just a problem on Windows? Does Linux (OpenSsl) send the whole chain?

It seems that if this is a Windows problem, then it requires changes to the Windows OS (SCHANNEL) to fix? Or there is something we can do at the .NET layer to fix this?

davidsh avatar Aug 27 '19 18:08 davidsh

So, this is just a problem on Windows? Does Linux (OpenSsl) send the whole chain?

We made the Linux and macOS SslStreams behave similarly to the Windows SslStream in this regard, once the cert is picked from the collection the rest of the collection is ignored, a chain is built internally, and then only that chain data is used for sending intermediates.

Or there is something we can do at the .NET layer to fix this?

On Linux and macOS it would be possible to take the entire/rest-of the collection and add it to X509Chain.ChainPolicy.ExtraStore so that loading a PFX as a collection and passing the whole collection could enable the scenario to work.

I don't know if the interface with SChannel allows passing in "extra" certs for the chain build, or asserting "this is the chain I want you to use", or anything like that. (Effectively, my knowledge of SChannel is limited to its name)

bartonjs avatar Aug 27 '19 21:08 bartonjs

I don't know if the interface with SChannel allows passing in "extra" certs for the chain build, or asserting "this is the chain I want you to use", or anything like that. (Effectively, my knowledge of SChannel is limited to its name)

We do use X509Chain.ChainPolicy.ExtraStore when we build a chain in other circumstances, i.e. receiving a server certificate.

See this code used in WinHttpHandler: We use this to rebuild a .NET chain object after getting a native certificate chain object: https://github.com/dotnet/corefx/blob/master/src/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCertificateHelper.cs

Maybe we can do something similar when handling PFX files and client certificates? In fact:

On Linux and macOS it would be possible to take the entire/rest-of the collection and add it to X509Chain.ChainPolicy.ExtraStore so that loading a PFX as a collection and passing the whole collection could enable the scenario to work.

Why not just do this for all platforms and not just Linux, MacOS?

davidsh avatar Aug 27 '19 21:08 davidsh

Why not just do this for all platforms and not just Linux, MacOS?

Again, I don't know what SChannel takes. If it's just 1 PCCERT_CONTEXT then there's no point in building the chain before calling them. If it's a a PCCERT_CONTEXT* rgCerts and a DWORD cCerts (or a cert and an HSTORE, or whatever), then maybe we should build the chain and provide the intermediates.

My statement is more "this problem is solvable on macOS and Linux; I'm looking to you to see if you can make it work on Windows."

bartonjs avatar Aug 28 '19 20:08 bartonjs

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.