/// <summary> /// Adds certificate template to issue by a specified Certification Authority server. The method do not writes newly assigned /// templates to Certification Authority. /// </summary> /// <param name="template">An <see cref="CertificateTemplate"/> object to add.</param> /// <exception cref="ArgumentNullException">The <strong>template</strong> parameter is null reference.</exception> /// <exception cref="UninitializedObjectException">The object in the <strong>template</strong> parameter is not initialized.</exception> /// <returns><strong>True</strong> if certificate template is added; otherwise <strong>False</strong>.</returns> /// <remarks> /// This method returns <strong>False</strong> in the following circumstances: /// <list type="bullet"> /// <item>Current CA server already contains specified certificate template in the issuance list.</item> /// <item>Specified certificate template is not supported by this CA version.</item> /// </list> /// If the method returns <strong>True</strong>, a <see cref="IsModified"/> property is set to <strong>True</strong>. /// </remarks> public Boolean Add(CertificateTemplate template) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (String.IsNullOrEmpty(template.Name)) { throw new UninitializedObjectException(); } List <CertificateTemplate> extemplates = new List <CertificateTemplate>(Templates); if (extemplates.Contains(template)) { return(false); } if (!IsSupported(template.SchemaVersion)) { return(false); } extemplates.Add(template); IsModified = true; Templates = extemplates.ToArray(); return(true); }
public IEnumerable <string> GetTemplateParameters(CertificateTemplate template) { EnsureCertificateTemplateIsUnpacked(template); var templateDirectory = GetTemplateDirectory(template); var indexFile = templateDirectory.GetFile(TemplateIndexFile); if (!indexFile.Exists) { log.Error($"Не нашёл файла {TemplateIndexFile} в шаблоне \"{template.Name}\" (Id = {template.Id}, {template.ArchiveName})"); yield break; } var foundParameters = new HashSet <string>(); var matches = templateParameterRegex.Matches(File.ReadAllText(indexFile.FullName)); foreach (Match match in matches) { var parameter = match.Groups[1].Value; if (!foundParameters.Contains(parameter)) { yield return(parameter); foundParameters.Add(parameter); } } }
internal CertTemplateSecurityDescriptor(CertificateTemplate template) : base(false) { DisplayName = template.DisplayName; _schemaVersion = template.SchemaVersion; _x500Name = template.DistinguishedName; fromActiveDirectorySecurity(); }
public string GetTemplateBuiltinParameterForUser(CertificateTemplate template, Course course, ApplicationUser user, ApplicationUser instructor, string parameterName) { var mockCertificate = new Certificate { Id = Guid.Empty, User = user, UserId = user.Id, Instructor = instructor, InstructorId = instructor.Id, Template = template, TemplateId = template.Id, Timestamp = DateTime.Now, }; return(SubstituteBuiltinParameters($"%{parameterName}|raw%", mockCertificate, course, "<адрес сертификата>")); }
public async Task <CertificateTemplate> AddTemplate(string courseId, string name, string archiveName) { var template = new CertificateTemplate { Id = Guid.NewGuid(), CourseId = courseId, Name = name, Timestamp = DateTime.Now, ArchiveName = archiveName, }; db.CertificateTemplates.Add(template); await db.SaveChangesAsync(); return(template); }
/// <summary> /// Adds certificate template to issue by a specified Certification Authority server. The method do not writes newly assigned /// templates to Certification Authority. /// </summary> /// <param name="template">An <see cref="CertificateTemplate"/> object to add.</param> /// <exception cref="ArgumentNullException">The <strong>template</strong> parameter is null reference.</exception> /// <exception cref="UninitializedObjectException">The object in the <strong>template</strong> parameter is not initialized.</exception> /// <returns><strong>True</strong> if certificate template is added; otherwise <strong>False</strong>.</returns> /// <remarks> /// This method returns <strong>False</strong> in the following circumstances: /// <list type="bullet"> /// <item>Current CA server already contains specified certificate template in the issuance list.</item> /// <item>Specified certificate template is not supported by this CA version.</item> /// </list> /// If the method returns <strong>True</strong>, a <see cref="IsModified"/> property is set to <strong>True</strong>. /// </remarks> public Boolean Add(CertificateTemplate template) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (String.IsNullOrEmpty(template.Name)) { throw new UninitializedObjectException(); } if (_templates.Contains(template) || !IsSupported(template.SchemaVersion)) { return(false); } _templates.Add(template); return(IsModified = true); }
/// <summary> /// Removes specified certificate template from CA server. This method do not remove certificate template itself. /// </summary> /// <param name="template">The template to remove.</param> /// <exception cref="ArgumentNullException">The <strong>template</strong> parameter is null reference.</exception> /// <exception cref="UninitializedObjectException">An object in the <strong>template</strong> parameter is not initialized.</exception> /// <returns><strong>True</strong> if the specified template was found and successfully removed, otherwise <strong>False</strong>.</returns> public Boolean Remove(CertificateTemplate template) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (String.IsNullOrEmpty(template.Name)) { throw new UninitializedObjectException(); } if (!_templates.Contains(template)) { return(false); } _templates.Remove(template); IsModified = true; return(true); }
/// <summary> /// Removes specified certificate template from CA server. This method do not remove certificate template itself. /// </summary> /// <param name="template">The template to remove.</param> /// <exception cref="ArgumentNullException">The <strong>template</strong> parameter is null reference.</exception> /// <exception cref="UninitializedObjectException">An object in the <strong>template</strong> parameter is not initialized.</exception> /// <returns><strong>True</strong> if the specified template was found and successfully removed, otherwise <strong>False</strong>.</returns> public Boolean Remove(CertificateTemplate template) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (String.IsNullOrEmpty(template.Name)) { throw new UninitializedObjectException(); } var existingTemplates = new List <CertificateTemplate>(Templates); if (!existingTemplates.Contains(template)) { return(false); } existingTemplates.Remove(template); IsModified = true; Templates = existingTemplates.ToArray(); return(true); }
static void listAllADCertificateTemplates() { ILog log = LogManager.GetLogger("GK.CACleaner.Console.CertificateTemplates"); log.Info("Starting to list certificate templates available in AD (this feature has preview status)"); CertificateTemplate[] userTemplates = CertificateTemplate.RetrieveAllUserCertificateTemplates(); foreach (CertificateTemplate ct in userTemplates) { log.Info("Certificate Template \"" + ct.TemplateName + "\" found with OID \"" + ct.TemplateOID + "\" (type " + ct.TemplateType + ")"); } CertificateTemplate[] machineTemplates = CertificateTemplate.RetrieveAllMachineCertificateTemplates(); foreach (CertificateTemplate ct in machineTemplates) { log.Info("Certificate Template \"" + ct.TemplateName + "\" found with OID \"" + ct.TemplateOID + "\" (type " + ct.TemplateType + ")"); } log.Info("Finished listing certificate templates available in AD"); }
void m_initialize(CertificateAuthority certificateAuthority) { if (!certificateAuthority.IsEnterprise) { throw new PlatformNotSupportedException(); } version = certificateAuthority.Version; sku = certificateAuthority.Sku; configString = certificateAuthority.ConfigString; ICertPropReaderD propReader; if (certificateAuthority.PingRequest()) { propReader = new CertPropReaderD(configString, false); } else if (certificateAuthority.PingAdmin()) { propReader = new CertPropReaderD(configString, true); } else { var e = new ServerUnavailableException(certificateAuthority.DisplayName); e.Data.Add(nameof(e.Source), OfflineSource.DCOM); throw e; } Name = certificateAuthority.Name; DisplayName = certificateAuthority.DisplayName; ComputerName = certificateAuthority.ComputerName; String[,] templates = propReader.GetCaTemplates(); for (Int32 i = 0; i <= templates.GetUpperBound(0); i++) { _templates.Add(CertificateTemplate.FromCommonName(templates[i, 0])); } }
void m_initialize(CertificateAuthority certificateAuthority) { if (!certificateAuthority.IsEnterprise) { throw new PlatformNotSupportedException(); } if (!certificateAuthority.Ping()) { var e = new ServerUnavailableException(certificateAuthority.DisplayName); e.Data.Add(nameof(e.Source), OfflineSource.DCOM); throw e; } Name = certificateAuthority.Name; DisplayName = certificateAuthority.DisplayName; ComputerName = certificateAuthority.ComputerName; version = certificateAuthority.Version; sku = certificateAuthority.Sku; configString = certificateAuthority.ConfigString; var CertAdmin = new CCertRequest(); String templates = (String)CertAdmin.GetCAProperty(certificateAuthority.ConfigString, CertAdmConstants.CrPropTemplates, 0, CertAdmConstants.ProptypeString, 0); var toBeAdded = new List <CertificateTemplate>(); if (templates != String.Empty) { String[] SplitString = { "\n" }; String[] TempArray = templates.Split(SplitString, StringSplitOptions.RemoveEmptyEntries); for (Int32 index = 0; index < TempArray.Length; index += 2) { toBeAdded.Add(new CertificateTemplate("Name", TempArray[index])); } Templates = toBeAdded.ToArray(); } else { Templates = new CertificateTemplate[0]; } }
public void EnsureCertificateTemplateIsUnpacked(CertificateTemplate template) { var certificateDirectory = GetTemplateDirectory(template); if (!certificateDirectory.Exists) { log.Info($"Нет директории с распакованным шаблоном сертификата, Id = {template.Id}"); var certificateArchive = GetTemplateArchivePath(template); if (!certificateArchive.Exists) { throw new Exception("Can\'t find certificate template"); } log.Info($"Распаковываю шаблон сертификата {template.Id}: \"{certificateArchive.FullName}\" в \"{certificateDirectory.FullName}\""); using (var zip = ZipFile.Read(certificateArchive.FullName, new ReadOptions { Encoding = Encoding.UTF8 })) { zip.ExtractAll(certificateDirectory.FullName, ExtractExistingFileAction.OverwriteSilently); } } }
/// <summary> /// Removes all certificate templates from issuance on current CA server. /// </summary> public void Clear() { Templates = new CertificateTemplate[0]; IsModified = true; }
public async Task RemoveTemplate(CertificateTemplate template) { template.IsDeleted = true; await db.SaveChangesAsync(); }
public DirectoryInfo GetTemplateDirectory(CertificateTemplate template) { return(GetTemplateDirectory(template.ArchiveName)); }
public FileInfo GetTemplateArchivePath(CertificateTemplate template) { return(GetTemplateArchivePath(template.ArchiveName)); }
public IEnumerable <string> GetBuiltinTemplateParameters(CertificateTemplate template) { return(GetTemplateParameters(template).Where(p => builtInParameters.Contains(p)).Distinct()); }