I'm attempting to directly retrieve the SSL certificate for a given domain, so that I can access its fields (such as Issuer, Expiration date, Errors, etc).
All the non-deprecated examples I can find, including from Microsoft, make use of the ServerCertificateCustomValidationCallback
method, such as in the example here: https://learn.microsoft.com/en-us/dotnet/api/System.Net.Http.HttpClientHandler.ServerCertificateCustomValidationCallback?view=net-7.0
The issue is that I want to sequentially execute my code as follows, without relying on any callback function in a separate thread. What I want is for example the following:
...
var cert = await httpClient.SomehowRequestCertificateFromUrl("https://someUrl.com"/);
Console.WriteLine($"The issuer is: {cert.issuer}");
Essentially I want to maintain the same scope at the point I make the request and receive the response, awaiting for the operation to complete. Using the callback method that's typically used, I lose the scope. I don't wish to store the certificate anywhere, I merely want to examine the certificate response from a request within the same scope. Is there any way to achieve what I want?
For reference, I'm creating a .Net Core console application, not using Asp.Net, so I have no need for a callback, and a callback goes against what I want to do.