// 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;
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.
///
///
/// 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; }
///
/// 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; }
///
/// 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), HttpsStrings.PositiveTimeSpanRequired);
}
_handshakeTimeout = value != Timeout.InfiniteTimeSpan ? value : TimeSpan.MaxValue;
}
}
}
}