/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="storeName">The certificate store to load the certificate from.</param> /// <param name="subject">The subject name for the certificate to load.</param> /// <param name="allowInvalid">Indicates if invalid certificates should be considered, such as self-signed certificates.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid) => listenOptions.UseHttps(storeName, subject, allowInvalid, StoreLocation.CurrentUser);
public static void ServerListenOptions(this ListenOptions listenOptions, string pathCetificate, string password) { listenOptions.UseHttps(pathCetificate, password); listenOptions.Protocols = HttpProtocols.Http1AndHttp2; }
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="fileName">The name of a certificate file, relative to the directory that contains the application /// content files.</param> /// <param name="password">The password required to access the X.509 certificate data.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, string fileName, string password) { var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService <IHostEnvironment>(); return(listenOptions.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName), password))); }
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="storeName">The certificate store to load the certificate from.</param> /// <param name="subject">The subject name for the certificate to load.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject) => listenOptions.UseHttps(storeName, subject, allowInvalid: false);
/// <summary> /// Configure Kestrel to use HTTPS with the default certificate if available. /// This will throw if no default certificate is configured. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions) => listenOptions.UseHttps(_ => { });
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="storeName">The certificate store to load the certificate from.</param> /// <param name="subject">The subject name for the certificate to load.</param> /// <param name="allowInvalid">Indicates if invalid certificates should be considered, such as self-signed certificates.</param> /// <param name="location">The store location to load the certificate from.</param> /// <param name="configureOptions">An Action to configure the <see cref="HttpsConnectionAdapterOptions"/>.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid, StoreLocation location, Action <HttpsConnectionAdapterOptions> configureOptions) { return(listenOptions.UseHttps(CertificateLoader.LoadFromStoreCert(subject, storeName.ToString(), location, allowInvalid), configureOptions)); }
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="storeName">The certificate store to load the certificate from.</param> /// <param name="subject">The subject name for the certificate to load.</param> /// <param name="allowInvalid">Indicates if invalid certificates should be considered, such as self-signed certificates.</param> /// <param name="location">The store location to load the certificate from.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid, StoreLocation location) => listenOptions.UseHttps(storeName, subject, allowInvalid, location, configureOptions: _ => { });
/// <summary> /// Configure Kestrel to use HTTPS. /// </summary> /// <param name="listenOptions"> /// The <see cref="ListenOptions"/> to configure. /// </param> /// <param name="serverCertificate"> /// The X.509 certificate. /// </param> /// <returns> /// The <see cref="ListenOptions"/>. /// </returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, X509Certificate2 serverCertificate) { return(listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = serverCertificate })); }
/// <summary> /// Configure Kestrel to use HTTPS. This does not use default certificates or other defaults specified via config or /// <see cref="KestrelServerOptions.ConfigureHttpsDefaults(Action{HttpsConnectionAdapterOptions})"/>. /// </summary> /// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param> /// <param name="serverOptionsSelectionCallback">Callback to configure HTTPS options.</param> /// <param name="state">State for the <paramref name="serverOptionsSelectionCallback"/>.</param> /// <returns>The <see cref="ListenOptions"/>.</returns> public static ListenOptions UseHttps(this ListenOptions listenOptions, ServerOptionsSelectionCallback serverOptionsSelectionCallback, object state) { return(listenOptions.UseHttps(serverOptionsSelectionCallback, state, HttpsConnectionAdapterOptions.DefaultHandshakeTimeout)); }