3using System.Globalization;
4using System.Threading.Tasks;
51 Dictionary<string, bool> CertificateRevocationLists,
string CertificateHost,
56 foreach (
string CrlUrl
in TravelDocumentsClient.GetRevocationListUrls(
Certificate))
57 CertificateRevocationLists[CrlUrl] =
true;
59 KeyValuePair<string?, byte[]?> P = TravelDocumentsClient.GetAuthorityKeyIdentifier(
Certificate);
60 KeyValuePair<string?, byte[]?> P2 = TravelDocumentsClient.GetSubjectKeyIdentifier(
Certificate);
62 if (P.Value is
null || (AreEquals(P.Value, P2.Value) && P.Key == P2.Key))
63 return [.. Certificates];
65 Dictionary<string, bool> Processed = [];
66 string? CountryCode = P.Key;
67 byte[]? IssuerKeyReference = P.Value;
69 while (!
string.IsNullOrEmpty(CountryCode) && IssuerKeyReference is not
null)
71 string Key = Convert.ToBase64String(IssuerKeyReference);
72 if (Processed.ContainsKey(Key))
75 Processed[Key] =
true;
78 CertificateHost, CountryCode, IssuerKeyReference, Client);
80 if (IssuerCertificate is
null)
82 Client?.Error(
"Issuer certificate not found: " + CountryCode +
", " +
87 Certificates.Insert(0, IssuerCertificate);
89 foreach (
string CrlUrl
in TravelDocumentsClient.GetRevocationListUrls(IssuerCertificate))
90 CertificateRevocationLists[CrlUrl] =
true;
92 P = TravelDocumentsClient.GetAuthorityKeyIdentifier(IssuerCertificate);
94 IssuerKeyReference = P.Value;
97 return [.. Certificates];
100 private static bool AreEquals(
byte[]? A1,
byte[]? A2)
102 if ((A1 is
null) ^ (A2 is
null))
112 for (
int i = 0; i < c; i++)
141 if (Certificates.Length == 0)
149 Client?.Information(
"Validating certificate " + (++Index) +
" signature, serial number: " + Cert.
SerialNumber.ToString(CultureInfo.InvariantCulture));
151 if (Issuer.PublicKey is
null)
153 Client?.Error(
"Unable to decode issuer signature algorithm and public key.\r\n\r\n" +
154 Convert.ToBase64String(Cert.
Binary, Base64FormattingOptions.InsertLineBreaks));
162 Client?.Error(
"Issuer public key not configured properly.\r\n\r\n" +
163 Convert.ToBase64String(Cert.
Binary, Base64FormattingOptions.InsertLineBreaks));
169 Cert.
Signature, Issuer.PublicKey, Client))
171 Client?.Error(
"Certificate signature not valid.\r\n\r\n" +
172 Convert.ToBase64String(Cert.
Binary, Base64FormattingOptions.InsertLineBreaks));
Static class for validation of ICAO certificate chains
static Task< Certificate[]> GetChain(Certificate Certificate, string CertificateHost)
Gets the certificate chain for a given certificate.
static async Task< Certificate[]> GetChain(Certificate Certificate, Dictionary< string, bool > CertificateRevocationLists, string CertificateHost, ICommunicationLayer? Client)
Gets the certificate chain for a given certificate, as well as the URLs for associated Certificate Re...
static bool VerifySignatures(params Certificate[] Certificates)
Verifies the signatures of a chain of ICAO certificates.
static bool VerifySignatures(ICommunicationLayer? Client, params Certificate[] Certificates)
Verifies the signatures of a chain of ICAO certificates.
static Task< Certificate[]> GetChain(Certificate Certificate, string CertificateHost, ICommunicationLayer? Client)
Gets the certificate chain for a given certificate.
Certificate, as defined in RFC 5280, §4.1.
ToBeSignedCertificate ToBeSignedCertificate
Certificate that is signed.
byte[] Signature
Digital signature.
ISignatureAlgorithm IssuerSignatureAlgorithm
Signature algorithm used by issuer to sign the certificate.
System.Numerics.BigInteger SerialNumber
Serial Number
byte[] Binary
ASN.1 DER encoded certificate.
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.
byte[] Binary
Binary representation of certificate to be signed.
A chunked list is a linked list of chunks of objects of type T .
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).
Interface for security objects.
bool IsConfigured
If the object has been configured.
Interface for observable classes implementing communication protocols.