Class HttpRevocationSource
- Namespace
- MiPdf.Signatures
- Assembly
- MiPdf.dll
Fetches issuer certificates (AIA caIssuers), OCSP responses (RFC 6960, HTTP POST) and CRLs (CRL distribution points) over HTTP. Responses are cached per instance; reuse the instance to benefit from the cache.
public sealed class HttpRevocationSource : IRevocationSource
- Inheritance
-
HttpRevocationSource
- Implements
- Inherited Members
Remarks
The URLs come from certificates inside the document and are therefore untrusted. By default only public internet addresses can be reached (checked for every connection, including redirects), so that uploaded documents cannot be used to probe internal services (SSRF). Set AllowPrivateNetworks for an internal CA, or restrict the hosts with AllowedHosts. A caller-supplied HttpClient is used as is, without these checks.
Constructors
HttpRevocationSource(HttpClient?)
Creates a revocation source.
public HttpRevocationSource(HttpClient? httpClient = null)
Parameters
httpClientHttpClientOptional HttpClient (proxies, timeouts, ...). It is used as is, without the address checks of AllowPrivateNetworks and AllowedHosts. Default: an internal client with a 30-second timeout.
Properties
AllowPrivateNetworks
Allow connections to private, loopback and link-local addresses (default false).
public bool AllowPrivateNetworks { get; init; }
Property Value
AllowedHosts
If set, only these host names may be contacted.
public IReadOnlyCollection<string>? AllowedHosts { get; init; }
Property Value
CacheDuration
How long downloaded CRLs and issuer certificates are cached (OCSP responses are not cached). Default 15 minutes.
public TimeSpan CacheDuration { get; set; }
Property Value
MaxCacheEntries
Maximum number of cached responses (default 500).
public int MaxCacheEntries { get; set; }
Property Value
MaxCrlSize
CRLs larger than this are skipped (some CAs publish CRLs of more than 100 MB). Default 5 MB.
public long MaxCrlSize { get; set; }
Property Value
Methods
GetCrls(X509Certificate2)
Downloads the CRL from the first HTTP CRL distribution point of the certificate (PEM is converted to DER); an empty list if there is none.
public IReadOnlyList<byte[]> GetCrls(X509Certificate2 certificate)
Parameters
certificateX509Certificate2
Returns
Exceptions
- PdfException
The server returned an HTTP error or the CRL exceeds MaxCrlSize.
GetIssuers(X509Certificate2)
Downloads the issuer certificate(s) from the HTTP caIssuers URLs of the certificate's AIA extension (at most three URLs, stopping at the first that yields a certificate); an empty list if there are none.
public IReadOnlyList<X509Certificate2> GetIssuers(X509Certificate2 certificate)
Parameters
certificateX509Certificate2
Returns
Exceptions
- PdfException
A server returned an HTTP error or a response that is too large.
GetOcspResponse(X509Certificate2, X509Certificate2)
Sends an OCSP request (HTTP POST) to the first HTTP OCSP URL of the certificate's AIA extension and returns the DER-encoded response; null if the certificate names no OCSP responder.
public byte[]? GetOcspResponse(X509Certificate2 certificate, X509Certificate2 issuer)
Parameters
certificateX509Certificate2issuerX509Certificate2
Returns
- byte[]
Exceptions
- PdfException
The responder returned an HTTP error, a response that is too large or a non-successful OCSP status.