Esempio n. 1
0
        public async Task <object> Get()
        {
            Fields fields    = Context.Request.GetFields();
            string storeUuid = Context.Request.Query[Defines.StoreIdentifier];
            IEnumerable <ICertificate> certs = null;

            if (storeUuid != null)
            {
                StoreId id = StoreId.FromUuid(storeUuid);
                certs = await GetFromStore(id.Name);
            }

            if (certs == null)
            {
                certs = await SafeGetAllCertificates();
            }

            certs = Filter(certs);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(certs.Count());
            this.Context.Response.Headers[HeaderNames.AcceptRanges] = _units;

            // Invoke json models immediately to prevent errors during serialization
            var models = new List <object>();

            foreach (var cert in certs)
            {
                models.Add(CertificateHelper.ToJsonModelRef(cert, fields));
            }

            return(new {
                certificates = models
            });
        }
Esempio n. 2
0
        public object Get()
        {
            List <object>       refs   = new List <object>();
            Fields              fields = Context.Request.GetFields();
            const StoreName     sn     = CertificateHelper.STORE_NAME;
            const StoreLocation sl     = CertificateHelper.STORE_LOCATION;

            // Filter for selecting certificates with specific purpose.
            string intended_purpose = Context.Request.Query["intended_purpose"];

            var certs = CertificateHelper.GetCertificates(sn, sl);

            if (intended_purpose != null)
            {
                // Filter based on intended purpose, select only the certificates that contain a matching usage
                certs = certs.Where(cert => {
                    return(CertificateHelper.GetEnhancedUsages(cert).Any(s => s.Equals(intended_purpose, StringComparison.OrdinalIgnoreCase)));
                }).ToList();
            }

            // Build references in the scope of the store because references have dependence on store name and location
            foreach (X509Certificate2 cert in certs)
            {
                refs.Add(CertificateHelper.ToJsonModelRef(cert, sn, sl, fields));
                cert.Dispose();
            }

            // All certs disposed.
            certs = null;

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(refs.Count());

            return(new {
                certificates = refs
            });
        }