Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the client-side .Net SSL session cache

I am writing a little test tool, which uses HttpWebRequest to load test a server. I want for each time I try to call HttpWebRequest.GetResponse() for it establish a fresh SSL session instead of using the one in the cache. Note: I am supplying a client certificate, and using Mutual Authentication for the SSL Session.

Is there a way to clear the SSL Session cache referred to in http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.clientcertificates.aspx ?

like image 645
DVisser Avatar asked Mar 09 '11 19:03

DVisser


People also ask

What happens if I clear SSL cache?

Clearing the SSL state eliminates the problems of caching certificates since it wipes out the cache. Doing this shouldn't be necessary in day-to-day computing, since resetting your computer or, in some cases, closing your browser, will also clear your SSL state.

What is SSL session cache?

Cached sessions allow the client to reuse a session in a subsequent connection. The SSL Cache Size setting controls how many entries can be cached. Set this to a number less than or equal to the maximum connections setting for the server. The default cache size for security profiles created in EAServer Manager is 30.

Do SSL certificates get cached?

Your ISP does not cache any SSL cert. But they cache DNS entries and NS entries on their NameServers. So if they still resolve to the old DNS entries you will be welcomed with an SSL error. This also means that your setup isn't working properly and you definitely should install a SSL cert on your origin server.


2 Answers

The ServicePoint class has an internal method called ReleaseAllConnectionGroups that sets KeepAlive = false on all the connections then releases them. This answer includes all the reflection needed, but setting KeepAlive = false on every HttpWebRequest will keep the client-side .Net SSL session cache clear.

SslEmptyCache may be required to clear caching of SSL-SessionID and/or tickets done by SCHANNEL at the native-code level.

like image 130
user423430 Avatar answered Oct 20 '22 01:10

user423430


I think you're looking for the HttpRequestCacheLevel Enumeration value NoCacheNoStore

http://msdn.microsoft.com/en-us/library/system.net.cache.httprequestcachelevel.aspx

You can then overwrite the HttpRequestCachePolicy

http://msdn.microsoft.com/en-us/library/system.net.webrequest.cachepolicy.aspx

like image 20
iivel Avatar answered Oct 20 '22 01:10

iivel