Example #1
0
        private async Task LoadCerts(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var errors = new List <Exception>();

            var factory = new CertificateFactory(_options, _challengeStore, _logger, _hostEnvironment);

            try
            {
                var cert = await GetOrCreateCertificate(factory, cancellationToken);

                foreach (var domainName in _options.Value.DomainNames)
                {
                    _selector.Use(domainName, cert);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex);
            }

            if (errors.Count > 0)
            {
                throw new AggregateException(errors);
            }
        }
        private void FindDeveloperCert()
        {
            using var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly);
            var certs = store.Certificates.Find(X509FindType.FindByExtension, AspNetHttpsOid, validOnly: false);

            if (certs.Count == 0)
            {
                _logger.LogDebug("Could not find the " + AspNetHttpsOidFriendlyName);
            }
            else
            {
                _logger.LogDebug("Using the " + AspNetHttpsOidFriendlyName + " for 'localhost' requests");
                _certSelector.Use("localhost", certs[0]);
            }
        }