public List <I2dChartData> GetCertificateHistory() { List <I2dChartData> history = new List <I2dChartData>(); int fromDay = -7; DateTime issuedFrom = DateTime.Now.AddDays(fromDay); Expression <Func <CertificateIssuanceModel, bool> > query = x => x.IssuedOn > issuedFrom; IEnumerable <CertificateIssuanceModel> certs = certificateRepository.Get <CertificateIssuanceModel>(query); while (fromDay <= 0) { DateTime day = DateTime.Now.AddDays(fromDay); DateTime dayMin = new DateTime(day.Year, day.Month, day.Day, 0, 0, 0); DateTime dayMax = new DateTime(day.Year, day.Month, day.Day, 23, 59, 59); IEnumerable <CertificateIssuanceModel> dayQuery = certs.Where(x => x.IssuedOn >= dayMin && x.IssuedOn <= dayMax); if (dayQuery.Any()) { history.Add(new CertificateHistoryModel(day, dayQuery.Count())); } else { history.Add(new CertificateHistoryModel(day, 0)); } fromDay++; } return(history); }
public CreatePrivateCertificateResult IssuePendingCertificate(Guid id, ClaimsPrincipal user) { PendingCertificate pendingCertificate = certificateRepository.Get <PendingCertificate>(id); KeyUsage keyUsage = dataTransformation.ParseKeyUsage(pendingCertificate.KeyUsage); AdcsTemplate template = templateLogic.DiscoverTemplate(pendingCertificate.CipherAlgorithm, pendingCertificate.Provider, keyUsage); if (authorizationLogic.IsAuthorized(template, user)) { CertificateRequest csr = certificateProvider.CreateCsrKeyPair(dataTransformation.NewCertificateSubjectFromModel(pendingCertificate), pendingCertificate.CipherAlgorithm, pendingCertificate.KeySize, pendingCertificate.Provider, SigningRequestProtocol.Pkcs10); MicrosoftCertificateAuthority ca = configurationRepository.GetPrivateCertificateAuthority(pendingCertificate.HashAlgorithm); CertificateAuthorityRequestResponse response = ca.Sign(csr, template.Name, template.KeyUsage); CreatePrivateCertificateResult result = ProcessCertificateAuthorityResponse(pendingCertificate, response, csr.Subject, user); certificateRepository.Delete <PendingCertificate>(id); return(result); } else { throw new UnauthorizedAccessException("Current user is not authorized to issue pending certificates"); } }
public ActionResult InsertTrustedCertificates(AuthApiCertificate entity) { Certificate cert = certificateRepository.Get <Certificate>(entity.Id); entity.HasPrivateKey = cert.HasPrivateKey; entity.Thumbprint = cert.Thumbprint; entity.DisplayName = cert.DisplayName; configurationRepository.Insert <AuthApiCertificate>(entity); return(http.RespondSuccess(entity)); }
public FileContentResult DownloadPfxWithoutChain(Guid id) { DownloadPfxCertificateEntity cert = certificateRepository.Get <DownloadPfxCertificateEntity>(id); if (!cert.HasPrivateKey || cert.CertificateStorageFormat != CertificateStorageFormat.Pfx) { throw new Exception("No private key"); } return(new FileContentResult(cert.Content, pfxMimeType) { FileDownloadName = String.Format("{0}.pfx", cert.Thumbprint) }); }
public GetCertificateEntity GetCertificate(Guid id, ClaimsPrincipal user) { GetCertificateEntity cert = certificateRepository.Get <GetCertificateEntity>(id); audit.LogSecurityAuditSuccess(user, cert, EventCategory.CertificateViewed); if (cert.Acl != null && cert.Acl.Count >= 0) { List <AccessControlEntry> acl = new List <AccessControlEntry>(); foreach (AccessControlEntry ace in cert.Acl) { AccessControlEntry newAce = new AccessControlEntry(ace, securityPrincipalLogic.ResolveSecurityPrincipalDisplayName(ace.Identity)); acl.Add(newAce); } cert.Acl = acl; } return(cert); }