// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core;
namespace Microsoft.AspNetCore.Server.Kestrel.Https
{
///
/// Settings for how Kestrel should handle HTTPS connections.
///
public class HttpsConnectionAdapterOptions
{
private TimeSpan _handshakeTimeout;
///
/// Initializes a new instance of .
///
public HttpsConnectionAdapterOptions()
{
ClientCertificateMode = ClientCertificateMode.NoCertificate;
SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11;
HandshakeTimeout = TimeSpan.FromSeconds(10);
}
///
///
/// Specifies the server certificate used to authenticate HTTPS connections. This is ignored if ServerCertificateSelector is set.
///
///
/// If the server certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1).
///
///
public X509Certificate2 ServerCertificate { get; set; }
///
///
/// A callback that will be invoked to dynamically select a server certificate. This is higher priority than ServerCertificate.
/// If SNI is not avialable then the name parameter will be null.
///
///
/// If the server certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1).
///
///
public Func ServerCertificateSelector { get; set; }
///
/// Specifies the client certificate requirements for a HTTPS connection. Defaults to .
///
public ClientCertificateMode ClientCertificateMode { get; set; }
///
/// Specifies a callback for additional client certificate validation that will be invoked during authentication.
///
public Func ClientCertificateValidation { get; set; }
///
/// Specifies allowable SSL protocols. Defaults to and .
///
public SslProtocols SslProtocols { get; set; }
///
/// The protocols enabled on this endpoint.
///
/// Defaults to HTTP/1.x only.
internal HttpProtocols HttpProtocols { get; set; }
///
/// Specifies whether the certificate revocation list is checked during authentication.
///
public bool CheckCertificateRevocation { get; set; }
///
/// Specifies the maximum amount of time allowed for the TLS/SSL handshake. This must be positive and finite.
///
public TimeSpan HandshakeTimeout
{
get => _handshakeTimeout;
set
{
if (value <= TimeSpan.Zero && value != Timeout.InfiniteTimeSpan)
{
throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveTimeSpanRequired);
}
_handshakeTimeout = value != Timeout.InfiniteTimeSpan ? value : TimeSpan.MaxValue;
}
}
// For testing
internal Action OnHandshakeStarted;
}
}