/// <summary> /// Create a new AnchorBundle by parsing raw bundle data /// </summary> /// <param name="bundleData">Raw bundle data</param> /// <param name="checkSignatureOnly">If bundle is signed, check signature but don't verify signature cert chain</param> public AnchorBundle(byte[] bundleData, bool checkSignatureOnly) { SignedCms cms = ParseCms(bundleData, checkSignatureOnly); if (cms != null) { this.Certificates = cms.Certificates; if (cms.HasContent()) { this.Metadata = ParseMetadata(cms.ContentInfo.Content); } } else { this.Certificates = new X509Certificate2Collection(); } }
/// <summary> /// Parse raw bundle data into a CMS structure /// </summary> /// <param name="bundleData">Array of bytes</param> /// <param name="checkSignatureOnly">If bundle is signed, check signature but don't verify signature cert chain</param> /// <returns>The parsed Cms structure</returns> public static SignedCms ParseCms(byte[] bundleData, bool checkSignatureOnly) { if (bundleData.IsNullOrEmpty()) { throw new ArgumentNullException("bundleData"); } SignedCms cms = null; try { cms = DecodeDerBundle(bundleData); } catch { } if (cms == null) { cms = DecodePEMBundle(bundleData); } if (!cms.HasSignatures()) { // No signature. Must assume is already p7b return(cms); } cms.CheckSignature(checkSignatureOnly); if (!cms.HasContent()) { return(null); } SignedCms p7bCms = new SignedCms(); p7bCms.Decode(cms.ContentInfo.Content); return(p7bCms); }