private SimpleStore GetStore(StoreName name, StoreLocation location, string sn)
 {
     try
     {
         using (var store = new X509Store(name, location))
         {
             var ss = new SimpleStore(GetCertsForStore(store), sn);
             return(ss);
         }
     }
     catch (System.Security.Cryptography.CryptographicException ce)
     {
         var ss = new SimpleStore(new List <SimpleCert>(), sn);
         ss.failure = true;
         return(ss);
     }
 }
        public JsonResult GetCertList()
        {
            var certs = new List <SimpleStore>();

            using (var store = new X509Store(StoreLocation.CurrentUser))
            {
                var ss = new SimpleStore(GetCertsForStore(store), "CU");
                certs.Add(ss);
            }

            certs.Add(GetStore(StoreName.My, StoreLocation.LocalMachine, "My LM"));
            certs.Add(GetStore(StoreName.My, StoreLocation.CurrentUser, "My CU"));
            certs.Add(GetStore(StoreName.CertificateAuthority, StoreLocation.LocalMachine, "CA LM"));
            certs.Add(GetStore(StoreName.CertificateAuthority, StoreLocation.CurrentUser, "CA CU"));
            certs.Add(GetStore(StoreName.TrustedPeople, StoreLocation.LocalMachine, "TP LM"));
            certs.Add(GetStore(StoreName.TrustedPeople, StoreLocation.CurrentUser, "TP CU"));
            certs.Add(GetStore(StoreName.TrustedPublisher, StoreLocation.LocalMachine, "TPub LM"));
            certs.Add(GetStore(StoreName.TrustedPublisher, StoreLocation.CurrentUser, "TPub CU"));

            try
            {
                X509Certificate2 cert = new X509Certificate2("/opt/app-root/certs/DP3.pfx", _settings.Value.CertPassword);

                var lc = new SimpleCert(cert.FriendlyName, cert.Subject);
                certs.Add(new SimpleStore(new List <SimpleCert>()
                {
                    lc
                }, "Local"));
            }
            catch (Exception e)
            {
                certs.Add(new SimpleStore(new List <SimpleCert>(), "Local: " + e.Message)
                {
                    failure = true
                });
            }
            return(new JsonResult(certs));
        }