Esempio n. 1
0
        public void UpdateCertificates(string sslSubjectName, string signingSubjectName)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var certs = entities.Certificates;

                if (!string.IsNullOrWhiteSpace(sslSubjectName))
                {
                    var ssl = new Certificates
                    {
                        Name = SslCertificateName,
                        SubjectDistinguishedName = sslSubjectName
                    };

                    certs.Attach(ssl);
                    entities.Entry(ssl).State = EntityState.Modified;
                }

                if (!string.IsNullOrWhiteSpace(signingSubjectName))
                {
                    var signing = new Certificates
                    {
                        Name = SigningCertificateName,
                        SubjectDistinguishedName = signingSubjectName
                    };

                    certs.Attach(signing);
                    entities.Entry(signing).State = EntityState.Modified;
                }

                entities.SaveChanges();

                CacheRepository.Invalidate(SigningCertificateCacheKey);
                CacheRepository.Invalidate(SslCertificateCachekey);
                CacheRepository.Invalidate(Constants.CacheKeys.WSFedMetadata);
            }
        }
        public void UpdateCertificates(string sslSubjectName, string signingSubjectName)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var certs = entities.Certificates;

                if (!string.IsNullOrWhiteSpace(sslSubjectName))
                {
                    var ssl = new Certificates
                    {
                        Name = SslCertificateName,
                        SubjectDistinguishedName = sslSubjectName
                    };

                    certs.Attach(ssl);
                    entities.Entry(ssl).State = EntityState.Modified;
                }

                if (!string.IsNullOrWhiteSpace(signingSubjectName))
                {
                    var signing = new Certificates
                    {
                        Name = SigningCertificateName,
                        SubjectDistinguishedName = signingSubjectName
                    };

                    certs.Attach(signing);
                    entities.Entry(signing).State = EntityState.Modified;
                }

                entities.SaveChanges();

                CacheRepository.Invalidate(SigningCertificateCacheKey);
                CacheRepository.Invalidate(SslCertificateCachekey);
                CacheRepository.Invalidate(Constants.CacheKeys.WSFedMetadata);
            }
        }
        protected virtual CertificateConfiguration LoadCertificateConfiguration(Certificates cert)
        {
            object findValue;
            X509FindType findType;

            var certConfig = new CertificateConfiguration
            {
                SubjectDistinguishedName = cert.SubjectDistinguishedName,
            };

            if (!string.IsNullOrWhiteSpace(cert.SubjectDistinguishedName))
            {
                findValue = cert.SubjectDistinguishedName;
                findType = X509FindType.FindBySubjectDistinguishedName;
            }
            else
            {
                Tracing.Error("No distinguished name or thumbprint for certificate: " + cert.Name);
                return certConfig;
            }

            try
            {
                var certFileName = cert.SubjectDistinguishedName.Split('|')[0];
                var certPassw0rd = cert.SubjectDistinguishedName.Split('|')[1];
                var signignCert = new X509Certificate2(
                                                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, certFileName),
                                                        certPassw0rd,
                                                        X509KeyStorageFlags.PersistKeySet);

                certConfig.Certificate = signignCert;
                //certConfig.Certificate = X509Certificates.GetCertificateFromStore(StoreLocation.LocalMachine, StoreName.My, findType, findValue);
            }
            catch
            {
                Tracing.Error("No certificate found for: " + findValue);
                throw new ConfigurationErrorsException("No certificate found for: " + findValue);
            }

            return certConfig;
        }
        protected virtual CertificateConfiguration LoadCertificateConfiguration(Certificates cert)
        {
            object findValue;
            X509FindType findType;

            var certConfig = new CertificateConfiguration
            {
                SubjectDistinguishedName = cert.SubjectDistinguishedName,
            };

            if (!string.IsNullOrWhiteSpace(cert.SubjectDistinguishedName))
            {
                findValue = cert.SubjectDistinguishedName;
                findType = X509FindType.FindBySubjectDistinguishedName;
            }
            else
            {
                Tracing.Error("No distinguished name or thumbprint for certificate: " + cert.Name);
                return certConfig;
            }

            try
            {
                certConfig.Certificate = X509Certificates.GetCertificateFromStore(StoreLocation.LocalMachine, StoreName.My, findType, findValue);
            }
            catch
            {
                Tracing.Error("No certificate found for: " + findValue);
                throw new ConfigurationErrorsException("No certificate found for: " + findValue);
            }

            return certConfig;
        }