// Use Https if a default cert is available internal static bool TryUseHttps(this ReplicaListenOptions listenOptions) { var options = new ReplicaHttpsConnectionAdapterOptions(); listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); listenOptions.KestrelServerOptions.ApplyDefaultCert(options); if (options.ServerCertificate == null && options.ServerCertificateSelector == null) { return(false); } listenOptions.UseHttps(options); return(true); }
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="configureOptions">An action to configure options for HTTPS.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ReplicaListenOptions UseHttps(this ReplicaListenOptions listenOptions, Action <HttpsConnectionAdapterOptions> configureOptions) { if (configureOptions == null) { throw new ArgumentNullException(nameof(configureOptions)); } var options = new ReplicaHttpsConnectionAdapterOptions(); listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); configureOptions(options); listenOptions.KestrelServerOptions.ApplyDefaultCert(options); if (options.ServerCertificate == null && options.ServerCertificateSelector == null) { throw new InvalidOperationException(ReplicaCoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound); } return(listenOptions.UseHttps(options)); }
public void Load() { if (_loaded) { // The loader has already been run. return; } _loaded = true; LoadDefaultCert(ConfigurationReader); foreach (var endpoint in ConfigurationReader.Endpoints) { var listenOptions = ReplicaAddressBinder.ParseAddress(endpoint.Url, out var https); //ZX //Options.ApplyEndpointDefaults(listenOptions); if (endpoint.Protocols.HasValue) { listenOptions.Protocols = endpoint.Protocols.Value; } // Compare to UseHttps(httpsOptions => { }) var httpsOptions = new ReplicaHttpsConnectionAdapterOptions(); if (https) { // Defaults //ZX //Options.ApplyHttpsDefaults(httpsOptions); // Specified httpsOptions.ServerCertificate = LoadCertificate(endpoint.Certificate, endpoint.Name) ?? httpsOptions.ServerCertificate; // Fallback //ZX //Options.ApplyDefaultCert(httpsOptions); } if (EndpointConfigurations.TryGetValue(endpoint.Name, out var configureEndpoint)) { var endpointConfig = new ReplicaEndpointConfiguration(https, listenOptions, httpsOptions, endpoint.ConfigSection); configureEndpoint(endpointConfig); } // EndpointDefaults or configureEndpoint may have added an https adapter. if (https && !listenOptions.ConnectionAdapters.Any(f => f.IsHttps)) { if (httpsOptions.ServerCertificate == null && httpsOptions.ServerCertificateSelector == null) { throw new InvalidOperationException(ReplicaCoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound); } listenOptions.UseHttps(httpsOptions); } // ZX: //Options.ListenOptions.Add(listenOptions); } foreach (var action in EndpointsToAdd) { action(); } }
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="httpsOptions">Options to configure HTTPS.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ReplicaListenOptions UseHttps(this ReplicaListenOptions listenOptions, ReplicaHttpsConnectionAdapterOptions httpsOptions) { var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService <ILoggerFactory>(); // Set the list of protocols from listen options httpsOptions.HttpProtocols = listenOptions.Protocols; listenOptions.ConnectionAdapters.Add(new HttpsConnectionAdapter(httpsOptions, loggerFactory)); return(listenOptions); }