====== TrustStoreExtensions & PqTrustStore ====== Custom Trust Store Management für PQ-kompatible PKI-Infrastrukturen. ---- ===== Übersicht ===== ^ Klasse ^ Beschreibung ^ | ''PqTrustStore'' | Vollwertiger Trust Store mit PQ-Unterstützung | | ''TrustStoreExtensions'' | Extension Methods für ''X509Certificate2Collection'' | | ''TrustEntry'' | Metadaten für Trust Store Einträge | | ''TrustType'' | Enum: TrustAnchor, IntermediateCA, etc. | ---- ===== PqTrustStore Klasse ===== using WvdS.System.Security.Cryptography.X509Certificates; // Trust Store erstellen using var trustStore = new PqTrustStore(); // Root CA hinzufügen var rootCa = new X509Certificate2("root-ca.cer"); trustStore.AddTrustAnchor(rootCa, alias: "Company Root CA"); // Intermediate CA hinzufügen var intermediateCa = new X509Certificate2("intermediate-ca.cer"); trustStore.AddIntermediate(intermediateCa, alias: "Issuing CA"); // Trust Store verwenden Console.WriteLine($"Trust Store enthält {trustStore.Count} Einträge"); ---- ===== Integration mit X509Chain ===== **Mit Custom Trust Store validieren:** using System.Security.Cryptography.X509Certificates; using WvdS.System.Security.Cryptography; using WvdS.System.Security.Cryptography.X509Certificates; // Trust Store laden using var trustStore = PqTrustStore.LoadFromPem("company-trust-store.pem"); // Zertifikat validieren var userCert = new X509Certificate2("user.cer"); using var chain = new X509Chain(); bool isValid = chain.Build(userCert, trustStore, CryptoMode.Hybrid); if (isValid) { Console.WriteLine("Zertifikat ist gültig"); } else { foreach (var status in chain.ChainStatus) { Console.WriteLine($"Fehler: {status.StatusInformation}"); } } **Mit X509Certificate2Collection:** // Einfacher: Direkt mit Collection var trustAnchors = TrustStoreExtensions.LoadFromPem("trust-anchors.pem"); using var chain = new X509Chain(); bool isValid = chain.Build(userCert, trustAnchors, CryptoMode.Hybrid); ---- ===== Trust Store Import/Export ===== **PEM-Bundle:** // Speichern trustStore.SaveToPem("trust-store.pem"); // Laden var loadedStore = PqTrustStore.LoadFromPem("trust-store.pem"); **PKCS#7 (DER):** // Speichern als PKCS#7 trustStore.SaveToPkcs7("trust-store.p7b"); // Laden var loadedStore = PqTrustStore.LoadFromPkcs7("trust-store.p7b"); ---- ===== System Store Import ===== // Trust Store mit System-Zertifikaten befüllen using var trustStore = new PqTrustStore(); // Windows Root CAs importieren trustStore.ImportFromSystemRootStore(); // Windows Intermediate CAs importieren trustStore.ImportFromSystemIntermediateStore(); // Als PEM exportieren für Air-Gapped Systeme trustStore.SaveToPem("system-trust-store.pem"); ---- ===== TrustType Enum ===== ^ Wert ^ Beschreibung ^ | ''TrustAnchor'' | Vertrauensanker (Root CA) | | ''IntermediateCA'' | Zwischenzertifizierungsstelle | | ''CrossCertifiedCA'' | Cross-zertifizierte CA | | ''EndEntity'' | End-Entity (kein CA) | ---- ===== Trust Store Abfragen ===== // Nur Trust Anchors var roots = trustStore.TrustAnchors; // Nur Intermediate CAs var intermediates = trustStore.IntermediateCAs; // Suche nach Subject var found = trustStore.FindBySubjectName("Company"); // Suche nach Thumbprint var entry = trustStore.FindByThumbprint("A1B2C3..."); // Prüfen ob enthalten bool exists = trustStore.Contains(certificate); ---- ===== Validierungsbericht ===== using var chain = new X509Chain(); chain.Build(cert, trustStore, CryptoMode.Hybrid); // Detaillierten Bericht erstellen var report = chain.GetValidationReport(); Console.WriteLine($"Gültig: {report.IsValid}"); Console.WriteLine($"Kettenlänge: {report.ChainLength}"); Console.WriteLine($"Vollständig PQ-geschützt: {report.IsFullyPqProtected}"); // Einzelne Elemente foreach (var element in report.Elements) { Console.WriteLine($" {element.Subject}"); Console.WriteLine($" Mode: {element.CryptoMode}"); Console.WriteLine($" PQ-Keys: {element.HasPqKeys}"); } **Beispiel-Ausgabe:** Chain Validation: VALID Chain Length: 3 Fully PQ Protected: True Elements: [0] CN=User Certificate Mode: Hybrid, PQ Keys: True [1] CN=Issuing CA Mode: Hybrid, PQ Keys: True [2] CN=Root CA Mode: Hybrid, PQ Keys: True ---- ===== Offline CRL-Prüfung ===== Für Air-Gapped Systeme mit vorgeladenen CRLs: // CRLs laden var crls = new List { File.ReadAllBytes("root-ca.crl"), File.ReadAllBytes("issuing-ca.crl") }; using var chain = new X509Chain(); bool isValid = chain.BuildWithOfflineCrl( certificate, trustStore.ToCollection(), crls, CryptoMode.Hybrid); ---- ===== Collection Extensions ===== // Collection filtern var collection = new X509Certificate2Collection(); collection.Import("certificates.p7b"); // Nur CAs var cas = collection.FilterCertificateAuthorities(); // Nur Root CAs (self-signed) var roots = collection.FilterRootCertificates(); // Nach Subject suchen var found = collection.FindBySubjectName("Company"); // PQ-Status prüfen bool hasPq = collection.HasPqProtectedCertificates(); // Als PEM speichern collection.SaveToPem("output.pem"); ---- ===== Best Practices ===== **Trust Store Hierarchie:** PqTrustStore ├── TrustAnchors (Root CAs) │ └── → chain.ChainPolicy.CustomTrustStore └── IntermediateCAs └── → chain.ChainPolicy.ExtraStore **Empfehlungen:** * **Minimalprinzip:** Nur benötigte CAs aufnehmen * **PQ-Migration:** Schrittweise PQ-Keys zu bestehenden CAs hinzufügen * **Backup:** Trust Store regelmäßig sichern * **Validierung:** Neue CAs vor Aufnahme prüfen ---- ===== Siehe auch ===== * [[.:x509chainextensions|X509ChainExtensions]] - Kettenvalidierung * [[.:revocationextensions|RevocationExtensions]] - Widerrufsprüfung * [[de:int:pqcrypt:konzepte:pki|PKI-Konzepte]] ---- //Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional// {{tag>truststore pki ca chain}}