Ejemplo n.º 1
0
        /// <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>
        /// <param name="configureOptions">An Action to configure the <see cref="ProtosConnectionAdapterOptions"/>.</param>
        /// <returns>The <see cref="ListenOptions"/>.</returns>
        public static ListenOptions UseProtos(this ListenOptions listenOptions, string fileName, string password,
                                              Action <ProtosConnectionAdapterOptions> configureOptions)
        {
            var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService <IHostEnvironment>();

            return(listenOptions.UseProtos(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName), password), configureOptions));
        }
Ejemplo n.º 2
0
        /// <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 UseProtos(this ListenOptions listenOptions, X509Certificate2 serverCertificate)
        {
            if (serverCertificate == null)
            {
                throw new ArgumentNullException(nameof(serverCertificate));
            }

            return(listenOptions.UseProtos(options =>
            {
                options.ServerCertificate = serverCertificate;
            }));
        }
Ejemplo n.º 3
0
        // Use Protos if a default cert is available
        internal static bool TryUseProtos(this ListenOptions listenOptions)
        {
            var options = new ProtosConnectionAdapterOptions();

            listenOptions.KestrelServerOptions.ApplyProtosDefaults(options);
            listenOptions.KestrelServerOptions.ApplyDefaultCert(options);

            if (options.ServerCertificate == null && options.ServerCertificateSelector == null)
            {
                return(false);
            }
            listenOptions.UseProtos(options);
            return(true);
        }
Ejemplo n.º 4
0
        /// <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 ListenOptions UseProtos(this ListenOptions listenOptions, Action <ProtosConnectionAdapterOptions> configureOptions)
        {
            if (configureOptions == null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            var options = new ProtosConnectionAdapterOptions();

            listenOptions.KestrelServerOptions.ApplyProtosDefaults(options);
            configureOptions(options);
            listenOptions.KestrelServerOptions.ApplyDefaultCert(options);

            if (options.ServerCertificate == null && options.ServerCertificateSelector == null)
            {
                throw new InvalidOperationException(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound);
            }
            return(listenOptions.UseProtos(options));
        }
Ejemplo n.º 5
0
        /// <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>
        /// <param name="configureOptions">An Action to configure the <see cref="ProtosConnectionAdapterOptions"/>.</param>
        /// <returns>The <see cref="ListenOptions"/>.</returns>
        public static ListenOptions UseProtos(this ListenOptions listenOptions, X509Certificate2 serverCertificate,
                                              Action <ProtosConnectionAdapterOptions> configureOptions)
        {
            if (serverCertificate == null)
            {
                throw new ArgumentNullException(nameof(serverCertificate));
            }

            if (configureOptions == null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            return(listenOptions.UseProtos(options =>
            {
                options.ServerCertificate = serverCertificate;
                configureOptions(options);
            }));
        }
Ejemplo n.º 6
0
 /// <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 UseProtos(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid)
 => listenOptions.UseProtos(storeName, subject, allowInvalid, StoreLocation.CurrentUser);
Ejemplo n.º 7
0
 /// <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 UseProtos(this ListenOptions listenOptions, StoreName storeName, string subject)
 => listenOptions.UseProtos(storeName, subject, allowInvalid: false);
Ejemplo n.º 8
0
        /// <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>
        /// <returns>The <see cref="ListenOptions"/>.</returns>
        public static ListenOptions UseProtos(this ListenOptions listenOptions, string fileName)
        {
            var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService <IHostEnvironment>();

            return(listenOptions.UseProtos(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName))));
        }
Ejemplo n.º 9
0
 /// <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 UseProtos(this ListenOptions listenOptions) => listenOptions.UseProtos(_ => { });
Ejemplo n.º 10
0
 /// <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="ProtosConnectionAdapterOptions"/>.</param>
 /// <returns>The <see cref="ListenOptions"/>.</returns>
 public static ListenOptions UseProtos(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid, StoreLocation location,
                                       Action <ProtosConnectionAdapterOptions> configureOptions)
 {
     return(listenOptions.UseProtos(CertificateLoader.LoadFromStoreCert(subject, storeName.ToString(), location, allowInvalid), configureOptions));
 }
Ejemplo n.º 11
0
 /// <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 UseProtos(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid, StoreLocation location)
 => listenOptions.UseProtos(storeName, subject, allowInvalid, location, configureOptions: _ => { });