3using System.Globalization;
4using System.Threading.Tasks;
21 private const int maxDaysInCache = 7;
30 public static Task<Certificate?>
TryLoadCertificate(
string IdDomain,
string Country,
byte[] KeyReference)
43 public static async Task<Certificate?>
TryLoadCertificate(
string IdDomain,
string Country,
byte[] KeyReference,
46 Country = Country.ToUpper(CultureInfo.InvariantCulture);
47 string KeyReferenceString =
Hashes.
BinaryToString(KeyReference).ToUpper(CultureInfo.InvariantCulture);
49 string Uri =
"https://" + IdDomain +
"/IcaoPki/" + Country +
"/" + KeyReferenceString +
".cer";
51 Client?.
Information(
"Loading certificate from " + Uri);
64 Client?.
Error(
"Unable to parse certificate.");
73 Client?.
Error(ex.Message);
84 public static Task<CertificateList?>
TryLoadCrl(
string Url)
127 string UriKey =
"Cache.Uri." + Url;
128 string TimestampKey =
"Cache.Timestamp." + Url;
129 string ContentTypeKey =
"Cache.ContentType." + Url;
130 DateTime Now = DateTime.UtcNow;
140 if (!
string.IsNullOrEmpty(Base64) &&
141 (Now - Timestamp).TotalDays < maxDaysInCache &&
142 !
string.IsNullOrEmpty(ContentType))
144 byte[] Bin = Convert.FromBase64String(Base64);
149 Client?.
Information(
"Using cached result for " + Url);
Certificate, as defined in RFC 5280, §4.1.
static bool TryParse(byte[] RawCertificate, [NotNullWhen(true)] out Certificate? Parsed)
Tries to parse an ASN.1-encoded Certificate, as defined in RFC 5280, §4.1.
Internal store of ICAO certificates
static Task< Certificate?> TryLoadCertificate(string IdDomain, string Country, byte[] KeyReference)
Tries to load an ICAO certificate, provided its country and key reference.
static Task< ContentResponse?> TryCachedGet(string Uri)
Tries to GET content from an URI. If content is cached, it is returned directly. Otherwise,...
static async Task< CertificateList?> TryLoadCrl(string Url, ICommunicationLayer? Client)
Tries to load an ICAO-compliant CRL, provided its URL.
static Task< CertificateList?> TryLoadCrl(string Url)
Tries to load an ICAO-compliant CRL, provided its URL.
static async Task< Certificate?> TryLoadCertificate(string IdDomain, string Country, byte[] KeyReference, ICommunicationLayer? Client)
Tries to load an ICAO certificate, provided its country and key reference.
static async Task< ContentResponse?> TryCachedGet(string Url, ICommunicationLayer? Client)
Tries to GET content from an URI. If content is cached, it is returned directly. Otherwise,...
Certificate List, as defined in RFC 5280, §5.1
Contains information about a response to a content request.
byte[] Encoded
Encoded object.
string ContentType
Internet Content-Type of encoded object.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
Static class managing encoding and decoding of internet content.
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
static Task< ContentResponse > GetAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static class managing persistent settings.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
static async Task< bool > SetAsync(string Key, string Value)
Sets a string-valued setting.
Contains methods for simple hash calculations.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
void Information(string Comment)
Called to inform the viewer of something.
void Error(string Error)
Called to inform the viewer of an error state.
Interface for observable classes implementing communication protocols.