Class RootPemCertificates
- Namespace
- Arc4u.gRPC.ChannelCertificate
- Assembly
- Arc4u.gRPC.dll
Provides, and caches by host name, the PEM encoded certificate of gRPC servers, typically to trust a private root certificate on a channel.
[Export]
[Shared]
public class RootPemCertificates
- Inheritance
-
RootPemCertificates
- Inherited Members
Remarks
Registered as a shared (singleton) service through the Export attribute. The certificate is fetched with an IRootCertificateExtractor.
Constructors
RootPemCertificates(IRootCertificateExtractor, ILogger<RootPemCertificates>)
Creates the collection.
public RootPemCertificates(IRootCertificateExtractor certificateExtractor, ILogger<RootPemCertificates> logger)
Parameters
certificateExtractorIRootCertificateExtractorThe service used to fetch server certificates.
loggerILogger<RootPemCertificates>The logger for technical messages.
Properties
Pems
Gets the PEM certificates already retrieved, keyed by host name.
public IReadOnlyDictionary<string, string> Pems { get; }
Property Value
Methods
ExportToPem(X509Certificate2)
Export a certificate to a PEM format string
public static string ExportToPem(X509Certificate2 cert)
Parameters
certX509Certificate2The certificate to export
Returns
- string
A PEM encoded string
GetPemFor(Uri)
Gets the PEM encoded certificate of the server behind rootUri, fetching and caching it by host on first use.
public string GetPemFor(Uri rootUri)
Parameters
rootUriUriThe https URL of the server.
Returns
- string
The certificate in PEM format.
Exceptions
- ArgumentNullException
rootUriis null.- KeyNotFoundException
No usable certificate could be obtained for the URI (the cause is logged).