Allow cert file and private key file to be passed in (#19477)

This commit is contained in:
Justin Kotalik 2020-03-03 20:42:46 -08:00 committed by GitHub
parent 7e139c9b5f
commit cda762685a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 6 deletions

View File

@ -29,10 +29,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
_log = log;
_context = new QuicTransportContext(_log, options);
EndPoint = endpoint;
var quicListenerOptions = new QuicListenerOptions();
var sslConfig = new SslServerAuthenticationOptions();
sslConfig.ServerCertificate = options.Certificate;
sslConfig.ApplicationProtocols = new List<SslApplicationProtocol>() { new SslApplicationProtocol(options.Alpn) };
_listener = new QuicListener(QuicImplementationProviders.MsQuic, endpoint as IPEndPoint, sslConfig);
quicListenerOptions.ServerAuthenticationOptions = sslConfig;
quicListenerOptions.CertificateFilePath = options.CertificateFilePath;
quicListenerOptions.PrivateKeyFilePath = options.PrivateKeyFilePath;
quicListenerOptions.ListenEndPoint = endpoint as IPEndPoint;
_listener = new QuicListener(QuicImplementationProviders.MsQuic, quicListenerOptions);
_listener.Start();
}

View File

@ -29,6 +29,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic
/// </summary>
public X509Certificate2 Certificate { get; set; }
/// <summary>
/// Optional path to certificate file to configure the security configuration.
/// </summary>
public string CertificateFilePath { get; set; }
/// <summary>
/// Optional path to private key file to configure the security configuration.
/// </summary>
public string PrivateKeyFilePath { get; set; }
/// <summary>
/// Sets the idle timeout for connections and streams.
/// </summary>

View File

@ -236,8 +236,8 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
{
fileParams = new MsQuicNativeMethods.CertFileParams
{
CertificateFilePath = Marshal.StringToCoTaskMemUTF8(certFilePath),
PrivateKeyFilePath = Marshal.StringToCoTaskMemUTF8(privateKeyFilePath)
PrivateKeyFilePath = Marshal.StringToCoTaskMemUTF8(privateKeyFilePath),
CertificateFilePath = Marshal.StringToCoTaskMemUTF8(certFilePath)
};
unmanagedAddr = Marshal.AllocHGlobal(Marshal.SizeOf(fileParams));
@ -246,7 +246,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
createConfigStatus = SecConfigCreateDelegate(
_registrationContext,
(uint)QUIC_SEC_CONFIG_FLAG.CERT_FILE,
certificate.Handle,
unmanagedAddr,
null,
IntPtr.Zero,
SecCfgCreateCallbackHandler);

View File

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -481,8 +481,8 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
[StructLayout(LayoutKind.Sequential)]
internal struct CertFileParams
{
internal IntPtr CertificateFilePath;
internal IntPtr PrivateKeyFilePath;
internal IntPtr CertificateFilePath;
}
}
}