@@ -17,7 +17,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
17
17
internal sealed class SafeMsQuicConfigurationHandle : SafeHandle
18
18
{
19
19
private static readonly FieldInfo _contextCertificate = typeof ( SslStreamCertificateContext ) . GetField ( "Certificate" , BindingFlags . NonPublic | BindingFlags . Instance ) ! ;
20
- private static readonly FieldInfo _contextChain = typeof ( SslStreamCertificateContext ) . GetField ( "IntermediateCertificates" , BindingFlags . NonPublic | BindingFlags . Instance ) ! ;
20
+ private static readonly FieldInfo _contextChain = typeof ( SslStreamCertificateContext ) . GetField ( "IntermediateCertificates" , BindingFlags . NonPublic | BindingFlags . Instance ) ! ;
21
21
22
22
public override bool IsInvalid => handle == IntPtr . Zero ;
23
23
@@ -33,7 +33,7 @@ protected override bool ReleaseHandle()
33
33
}
34
34
35
35
// TODO: consider moving the static code from here to keep all the handle classes small and simple.
36
- public static unsafe SafeMsQuicConfigurationHandle Create ( QuicClientConnectionOptions options )
36
+ public static SafeMsQuicConfigurationHandle Create ( QuicClientConnectionOptions options )
37
37
{
38
38
X509Certificate ? certificate = null ;
39
39
if ( options . ClientAuthenticationOptions ? . ClientCertificates != null )
@@ -56,15 +56,35 @@ public static unsafe SafeMsQuicConfigurationHandle Create(QuicClientConnectionOp
56
56
return Create ( options , QUIC_CREDENTIAL_FLAGS . CLIENT , certificate : certificate , certificateContext : null , options . ClientAuthenticationOptions ? . ApplicationProtocols ) ;
57
57
}
58
58
59
- public static unsafe SafeMsQuicConfigurationHandle Create ( QuicListenerOptions options )
59
+ public static SafeMsQuicConfigurationHandle Create ( QuicOptions options , SslServerAuthenticationOptions ? serverAuthenticationOptions , string ? targetHost = null )
60
60
{
61
61
QUIC_CREDENTIAL_FLAGS flags = QUIC_CREDENTIAL_FLAGS . NONE ;
62
- if ( options . ServerAuthenticationOptions != null && options . ServerAuthenticationOptions . ClientCertificateRequired )
62
+ X509Certificate ? certificate = serverAuthenticationOptions ? . ServerCertificate ;
63
+
64
+ if ( serverAuthenticationOptions != null )
63
65
{
64
- flags |= QUIC_CREDENTIAL_FLAGS . REQUIRE_CLIENT_AUTHENTICATION | QUIC_CREDENTIAL_FLAGS . INDICATE_CERTIFICATE_RECEIVED | QUIC_CREDENTIAL_FLAGS . NO_CERTIFICATE_VALIDATION ;
66
+ if ( serverAuthenticationOptions . CipherSuitesPolicy != null )
67
+ {
68
+ throw new PlatformNotSupportedException ( SR . Format ( SR . net_quic_ssl_option , nameof ( serverAuthenticationOptions . CipherSuitesPolicy ) ) ) ;
69
+ }
70
+
71
+ if ( serverAuthenticationOptions . EncryptionPolicy == EncryptionPolicy . NoEncryption )
72
+ {
73
+ throw new PlatformNotSupportedException ( SR . Format ( SR . net_quic_ssl_option , nameof ( serverAuthenticationOptions . EncryptionPolicy ) ) ) ;
74
+ }
75
+
76
+ if ( serverAuthenticationOptions . ClientCertificateRequired )
77
+ {
78
+ flags |= QUIC_CREDENTIAL_FLAGS . REQUIRE_CLIENT_AUTHENTICATION | QUIC_CREDENTIAL_FLAGS . INDICATE_CERTIFICATE_RECEIVED | QUIC_CREDENTIAL_FLAGS . NO_CERTIFICATE_VALIDATION ;
79
+ }
80
+
81
+ if ( certificate == null && serverAuthenticationOptions ? . ServerCertificateSelectionCallback != null && targetHost != null )
82
+ {
83
+ certificate = serverAuthenticationOptions . ServerCertificateSelectionCallback ( options , targetHost ) ;
84
+ }
65
85
}
66
86
67
- return Create ( options , flags , options . ServerAuthenticationOptions ? . ServerCertificate , options . ServerAuthenticationOptions ? . ServerCertificateContext , options . ServerAuthenticationOptions ? . ApplicationProtocols ) ;
87
+ return Create ( options , flags , certificate , serverAuthenticationOptions ? . ServerCertificateContext , serverAuthenticationOptions ? . ApplicationProtocols ) ;
68
88
}
69
89
70
90
// TODO: this is called from MsQuicListener and when it fails it wreaks havoc in MsQuicListener finalizer.
0 commit comments