Skip to content

Instantly share code, notes, and snippets.

@funkysi1701
Created March 3, 2020 21:31
[Fact]
public void IsSSLExpiring()
{
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = CustomCallback
};
var client = new HttpClient(handler);
HttpResponseMessage response = client.GetAsync("https://www.example.com").GetAwaiter().GetResult();
Assert.True(response.IsSuccessStatusCode);
}
private bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)
{
var now = DateTime.UtcNow;
var expire = arg2.NotAfter;
var diff = (expire - now).TotalDays;
Assert.InRange(diff, 30, 1000);
return arg4 == SslPolicyErrors.None;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment