Class RootCertificateExtractor
- Namespace
- Arc4u.gRPC.ChannelCertificate
- Assembly
- Arc4u.gRPC.dll
Default IRootCertificateExtractor: sends a request to the server and captures the certificate in the TLS validation callback.
[Export(typeof(IRootCertificateExtractor))]
public class RootCertificateExtractor : IRootCertificateExtractor, IDisposable
- Inheritance
-
RootCertificateExtractor
- Implements
- Inherited Members
Remarks
The certificate is only captured when the connection is negotiated: as the underlying HttpClient reuses its connections, a later call for the same server may not trigger the callback and return null. The extractor owns an HttpClient that is released by Dispose().
Constructors
RootCertificateExtractor(ILogger<RootCertificateExtractor>)
Creates the extractor.
public RootCertificateExtractor(ILogger<RootCertificateExtractor> logger)
Parameters
loggerILogger<RootCertificateExtractor>The logger for technical messages.
Methods
Dispose()
Releases the HttpClient used to contact the servers.
public void Dispose()
FetchCertificateFor(Uri)
Sends a GET request to the URL and returns the server certificate captured during the handshake.
public X509Certificate2? FetchCertificateFor(Uri rootUrl)
Parameters
rootUrlUriThe https URL of the server.
Returns
- X509Certificate2
The certificate, or null when it could not be obtained.
Remarks
Any failure of the request is logged and results in null. The certificate is returned only when the server certificate is valid for the platform trust (no SSL policy error).
Exceptions
- ArgumentException
The scheme of
rootUrlis not https.