示例#1
0
        public async Task <bool> PerformDailyTasks()
        {
            Debug.WriteLine("Checking for daily tasks..");

            // clear old cache of challenge responses
            _currentChallenges = new ConcurrentDictionary <string, SimpleAuthorizationChallengeItem>();

            // use latest settings
            SettingsManager.LoadAppSettings();

            if (_tc != null)
            {
                _tc.TrackEvent("ServiceDailyTaskCheck");
            }

            // perform expired cert cleanup (if enabled)
            if (CoreAppSettings.Current.EnableCertificateCleanup)
            {
                try
                {
                    CertificateManager.PerformCertificateStoreCleanup(DateTime.Now);
                }
                catch (Exception exp)
                {
                    // log exception
                    _serviceLog.Error("Failed to perform certificate cleanup: " + exp.ToString());
                }
            }

            return(await Task.FromResult(true));
        }
示例#2
0
        public async Task PerformCertificateCleanup()
        {
            try
            {
                var mode = CoreAppSettings.Current.CertificateCleanupMode;
                if (mode == null)
                {
                    mode = CertificateCleanupMode.AfterExpiry;
                }

                if (mode != CertificateCleanupMode.None)
                {
                    List <string> excludedCertThumprints = new List <string>();

                    if (mode == CertificateCleanupMode.FullCleanup)
                    {
                        // excluded thumbprints are all certs currently tracked as managed certs
                        var managedCerts = await GetManagedCertificates();

                        foreach (var c in managedCerts)
                        {
                            if (!string.IsNullOrEmpty(c.CertificateThumbprintHash))
                            {
                                excludedCertThumprints.Add(c.CertificateThumbprintHash.ToLower());
                            }
                        }
                    }

                    // this will only perform expiry cleanup, as no specific thumbprint provided
                    var certsRemoved = CertificateManager.PerformCertificateStoreCleanup(
                        (CertificateCleanupMode)mode,
                        DateTime.Now,
                        matchingName: null,
                        excludedThumbprints: excludedCertThumprints
                        );

                    if (certsRemoved.Any())
                    {
                        foreach (var c in certsRemoved)
                        {
                            _serviceLog.Information($"Cleanup removed cert: {c}");
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                // log exception
                _serviceLog.Error("Failed to perform certificate cleanup: " + exp.ToString());
            }
        }
示例#3
0
        public async Task PerformCertificateCleanup()
        {
            try
            {
                var mode = CoreAppSettings.Current.CertificateCleanupMode;
                if (mode == null)
                {
                    mode = CertificateCleanupMode.AfterExpiry;
                }

                if (mode != CertificateCleanupMode.None)
                {
                    var excludedCertThumprints = new List <string>();

                    // excluded thumbprints are all certs currently tracked as managed certs
                    var managedCerts = await GetManagedCertificates();

                    foreach (var c in managedCerts)
                    {
                        if (!string.IsNullOrEmpty(c.CertificateThumbprintHash))
                        {
                            excludedCertThumprints.Add(c.CertificateThumbprintHash.ToLower());
                        }
                    }

                    if (mode == CertificateCleanupMode.FullCleanup)
                    {
                        // cleanup old pfx files in asset store(s), if any
                        var assetPath = Path.Combine(Util.GetAppDataFolder(), "certes", "assets");
                        if (Directory.Exists(assetPath))
                        {
                            var ext = new List <string> {
                                ".pfx"
                            };
                            DeleteOldCertificateFiles(assetPath, ext);
                        }

                        assetPath = Path.Combine(Util.GetAppDataFolder(), "assets");
                        if (Directory.Exists(assetPath))
                        {
                            var ext = new List <string> {
                                ".pfx", ".key", ".crt", ".pem"
                            };
                            DeleteOldCertificateFiles(assetPath, ext);
                        }
                    }

                    // this will only perform expiry cleanup, as no specific thumbprint provided
                    var certsRemoved = CertificateManager.PerformCertificateStoreCleanup(
                        (CertificateCleanupMode)mode,
                        DateTime.Now,
                        matchingName: null,
                        excludedThumbprints: excludedCertThumprints,
                        log: _serviceLog
                        );
                }
            }
            catch (Exception exp)
            {
                // log exception
                _serviceLog?.Error("Failed to perform certificate cleanup: " + exp.ToString());
            }
        }