Table of Contents

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

certificateExtractor IRootCertificateExtractor

The service used to fetch server certificates.

logger ILogger<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

IReadOnlyDictionary<string, string>

Methods

ExportToPem(X509Certificate2)

Export a certificate to a PEM format string

public static string ExportToPem(X509Certificate2 cert)

Parameters

cert X509Certificate2

The 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

rootUri Uri

The https URL of the server.

Returns

string

The certificate in PEM format.

Exceptions

ArgumentNullException

rootUri is null.

KeyNotFoundException

No usable certificate could be obtained for the URI (the cause is logged).