Beispiel #1
0
        public object Get(string id)
        {
            CertificateId certId = new CertificateId(id);

            using (X509Certificate2 cert = CertificateHelper.GetCert(certId.Thumbprint, certId.StoreName, certId.StoreLocation)) {
                if (cert == null)
                {
                    return(NotFound());
                }

                return(CertificateHelper.ToJsonModel(cert, certId.StoreName, certId.StoreLocation, Context.Request.GetFields()));
            }
        }
Beispiel #2
0
        public object Get(string id)
        {
            StoreId storeId = StoreId.FromUuid(id);

            ICertificateStore store = _provider.Stores.FirstOrDefault(s => s.Name.Equals(storeId.Name, StringComparison.OrdinalIgnoreCase));

            if (store == null)
            {
                return(NotFound());
            }

            return(CertificateHelper.StoreToJsonModel(store, Context.Request.GetFields()));
        }
Beispiel #3
0
        public async Task <object> Get(string id)
        {
            CertificateId     certId = new CertificateId(id);
            ICertificate      cert   = null;
            ICertificateStore store  = _storeProvider.Stores.FirstOrDefault(s => s.Name.Equals(certId.StoreName, StringComparison.OrdinalIgnoreCase));

            if (store != null)
            {
                cert = await store.GetCertificate(certId.Id);
            }

            if (cert == null)
            {
                return(NotFound());
            }

            return(CertificateHelper.ToJsonModel(cert, Context.Request.GetFields()));
        }
Beispiel #4
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
            });
        }