Search code examples
c#sslwindows-store-appswin-universal-app

Windows.Web.Http.HttpClient issue connecting to same server with different client certificates


I have encountered an issue with Windows.Web.Http.HttpClient when I have multiple connections using https with different client certificates, to the same server endpoint.

I have a setup a bit like:

Connection A: connect to https://www.myserver.com/path?querystring - with the HttpBaseProtocolFilter used to create the HttpClient instance configured for 'client certificate A'.

This all works fine.

Now I create another connection, using a new HttpClient instance to the same server (different query string), and this time the filter is configured for 'client certificate B'.

This connection seems to get through to the server, but it looks like the server is getting the wrong client certificate. I have no access to the server or its logs, but from the errors I do get I wonder if perhaps it is getting 'Client Certificate A' instead.

I note the problem goes away if I put a '.' character after the '.com' part of the server name in the second connection. This makes me suspicious that there is some caching somewhere based on server name.

This is failing on a Windows 8.1 Surface tablet. It seems to work ok on my development laptop. The app I'm building is a Windows Store App, so this may also be part of the problem.

Has anyone any knowledge of how client certificates are cached, or whether ssl/tls connections are 'local' to a HttpClient instance?

Can a Windows App Store app (C#) clear/disable/disconnect any existing ssl/tls session?

Any pointers welcome.

PS: The app I'm building is a 'monitoring' app that can connect to a server using different client certificates to access different 'accounts'. The app is intended to show an aggregated view of multiple accounts, thus the requirement to use a number of different client certificates against the same endpoint. This all works for the Android/iOS version of the app, but I cannot get a Windows version working.. (oh, and the server/account access mechanism is not under my control in any way )


Solution

  • I note the problem goes away if I put a '.' character after the '.com' part of the server name in the second connection. This makes me suspicious that there is some caching somewhere based on server name.

    It seems that cache behavior of http client cause this issue...

    You can try the following way to turn-off the cache.

    HTTPClient every time returns the same string

    or following SO post also helps you.

    How to stop credential caching on Windows.Web.Http.HttpClient?