예제 #1
0
        public StartupCertificateLoader(string named, IServiceProvider sp)
        {
            _httpChallenge        = sp.GetRequiredService <HttpChallenge>();
            _certificateValidator = sp.GetRequiredService <ICertificateValidator>();

            _accountOptions     = sp.GetRequiredService <IOptionsMonitor <AcmeAccountOptions> >().Get(named);
            _certificateOptions = sp.GetRequiredService <IOptionsMonitor <CertificateOptions> >().Get(named);

            _developmentCertificate = sp.GetRequiredService <DevelopmentCertificate>();
            _stores = sp.GetRequiredService <IEnumerable <ICertificateStore> >();
            _certificateSelector = sp.GetRequiredService <KestrelCertificateSelector>();

            _server = sp.GetRequiredService <IServer>();
            _config = sp.GetRequiredService <IConfiguration>();

            _logger = sp.GetRequiredService <ILogger <StartupCertificateLoader> >();
        }
예제 #2
0
        private async Task <X509Certificate2?> CreateAcmeOrder(
            string domainName,
            HttpChallenge httpChallenge,
            CertificateOptions certificateOptions,
            ICertificateStore store,
            CancellationToken cancellationToken)
        {
            var certificateBytes = await httpChallenge.GetCertificateAsync(store.NamedOption, cancellationToken);

            if (certificateBytes == null)
            {
                return(await Task.FromResult <X509Certificate2?>(null));
            }

            await store.SaveAsync(certificateBytes, domainName, cancellationToken);

#pragma warning disable CA2000 // Dispose objects before losing scope
            return(await Task.FromResult(new X509Certificate2(certificateBytes, certificateOptions?.CertificatePassword ?? string.Empty)));

#pragma warning restore CA2000 // Dispose objects before losing scope
        }