public async Task <ActionResult> GetIssuerCertAsync(string serial, string cert)
        {
            try
            {
                serial = serial.ToLower();
                cert   = cert.ToLower();
                if (cert.EndsWith(".cer"))
                {
                    string groupId = cert.Substring(0, cert.Length - 4);
                    // find isser cert with serial no.

                    X509Certificate2Collection certVersions;
                    string nextPageLink;
                    (certVersions, nextPageLink) = await _certificateGroups.GetIssuerCACertificateVersionsAsync(groupId, false);

                    while (certVersions != null && certVersions.Count > 0)
                    {
                        foreach (var certVersion in certVersions)
                        {
                            if (serial.Equals(certVersion.SerialNumber, StringComparison.OrdinalIgnoreCase))
                            {
                                var byteArray = certVersion.RawData;
                                return(new FileContentResult(byteArray, ContentType.Cert)
                                {
                                    FileDownloadName = Utils.DownloadName(certVersion, groupId) + ".cer"
                                });
                            }
                        }
                        if (nextPageLink != null)
                        {
                            (certVersions, nextPageLink) = await _certificateGroups.GetIssuerCACertificateVersionsAsync(groupId, false, nextPageLink);
                        }
                        else
                        {
                            certVersions = null;
                        }
                    }
                }
            }
            catch
            {
                await Task.Delay(1000);
            }
            return(new NotFoundResult());
        }
Exemplo n.º 2
0
        public async Task <X509Certificate2CollectionApiModel> GetCertificateGroupIssuerCAVersionsAsync(
            string group,
            bool?withCertificates,
            [FromQuery] string nextPageLink,
            [FromQuery] int?pageSize)
        {
            X509Certificate2Collection collection;

            (collection, nextPageLink) = await _certificateGroups.GetIssuerCACertificateVersionsAsync(group, withCertificates, nextPageLink, pageSize);

            return(new X509Certificate2CollectionApiModel(collection, nextPageLink));
        }