コード例 #1
0
        private void RotateCert(CertificateOptions newCert)
        {
            if (newCert.Certificate == null)
            {
                return;
            }

            var personalCertStore  = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            var authorityCertStore = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser);

            personalCertStore.Open(OpenFlags.ReadWrite);
            authorityCertStore.Open(OpenFlags.ReadWrite);
            if (_lastValue != null)
            {
                personalCertStore.Certificates.Remove(_lastValue.Certificate);
                foreach (var cert in _lastValue.IssuerChain)
                {
                    personalCertStore.Certificates.Remove(cert);
                }
            }

            personalCertStore.Certificates.Add(newCert.Certificate);
            foreach (var cert in newCert.IssuerChain)
            {
                personalCertStore.Certificates.Add(cert);
            }

            personalCertStore.Close();
            authorityCertStore.Close();
        }
コード例 #2
0
        public void Start()
        {
            if (_isStarted)
            {
                return;
            }

            RotateCert(_optionsMonitor.CurrentValue);
            _lastValue = _optionsMonitor.CurrentValue;
        }