/// <summary> /// Adds CA certificate to AIA entry as CA certificate or cross-certificate. The type is determined by <strong>type</strong> /// parameter. /// <para> /// <strong>Note:</strong> 'userCertificate' type is not supported by this method. /// </para> /// </summary> /// <param name="cert">CA certificate to add.</param> /// <param name="type">Certificate type. Can be either 'CACertificate' or 'CrossCertificate'.</param> /// <exception cref="ArgumentException"> /// specified certificate type is not valid. /// </exception> /// <exception cref="UninitializedObjectException"> /// <strong>cert</strong> parameter is not valid X.509 certificate object. /// </exception> /// <exception cref="ArgumentNullException"> /// <strong>cert</strong> parameter is null. /// </exception> /// <inheritdoc cref="DsPkiCertContainer.AddCertificateEntry" section="returns|remarks/*"/> public Boolean AddCertificate(X509Certificate2 cert, DsCertificateType type) { if (cert == null) { throw new ArgumentNullException(nameof(cert)); } if (cert.RawData == null) { throw new UninitializedObjectException(); } if (type == DsCertificateType.UserCertificate) { throw new ArgumentException("Specified type is not supported."); } String containerName = GetContainerName(cert); var entry = new DsCertificateEntry(containerName, cert, type); return(AddCertificateEntry(entry)); }
// reads certificates of specified type from specified DS object. List <DsCertificateEntry> readCertsFromDsAttribute(DirectoryEntry entry, String key, DsCertificateType type) { String attribute; switch (type) { case DsCertificateType.CACertificate: attribute = "cACertificate"; break; case DsCertificateType.CrossCertificate: attribute = "crossCertificatePair"; break; case DsCertificateType.UserCertificate: attribute = "userCertificate"; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } Byte[][] rawData = GetEntryProperty <Byte[]>(entry, attribute); // x.Length > 1 is necessary, because empty mandatory value contains a 1 byte element. return(rawData.Where(x => x.Length > 1) .Select(bytes => new DsCertificateEntry(key, new X509Certificate2(bytes), type)) .ToList()); }
internal DsCertificateEntry(String name, X509Certificate2 certificate, DsCertificateType type) { Name = name; Certificate = certificate; CertificateType = type; }