Skip to content

Commit

Permalink
throw PNSE for unsupported SSL options in Quic. (#55877)
Browse files Browse the repository at this point in the history
* throw PNSP for unsupported SSL options

* add missing resource file change

* fix spacing
  • Loading branch information
wfurt authored Jul 21, 2021
1 parent 577136c commit b2107c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/libraries/System.Net.Quic/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@
<data name="net_quic_writing_notallowed" xml:space="preserve">
<value>Writing is not allowed on stream.</value>
</data>
<data name="net_quic_ssl_option" xml:space="preserve">
<value>The '{0}' is not supported by System.Net.Quic.</value>
</data>
</root>

Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,39 @@ protected override bool ReleaseHandle()
public static unsafe SafeMsQuicConfigurationHandle Create(QuicClientConnectionOptions options)
{
X509Certificate? certificate = null;
if (options.ClientAuthenticationOptions?.ClientCertificates != null)

if (options.ClientAuthenticationOptions != null)
{
foreach (var cert in options.ClientAuthenticationOptions.ClientCertificates)
if (options.ClientAuthenticationOptions.CipherSuitesPolicy != null)
{
throw new PlatformNotSupportedException(SR.Format(SR.net_quic_ssl_option, nameof(options.ClientAuthenticationOptions.CipherSuitesPolicy)));
}

if (options.ClientAuthenticationOptions.EncryptionPolicy == EncryptionPolicy.NoEncryption)
{
try
throw new PlatformNotSupportedException(SR.Format(SR.net_quic_ssl_option, nameof(options.ClientAuthenticationOptions.EncryptionPolicy)));
}

if (options.ClientAuthenticationOptions.LocalCertificateSelectionCallback != null)
{
throw new PlatformNotSupportedException(SR.Format(SR.net_quic_ssl_option, nameof(options.ClientAuthenticationOptions.LocalCertificateSelectionCallback)));
}

if (options.ClientAuthenticationOptions.ClientCertificates != null)
{
foreach (var cert in options.ClientAuthenticationOptions.ClientCertificates)
{
if (((X509Certificate2)cert).HasPrivateKey)
try
{
// Pick first certificate with private key.
certificate = cert;
break;
if (((X509Certificate2)cert).HasPrivateKey)
{
// Pick first certificate with private key.
certificate = cert;
break;
}
}
catch { }
}
catch { }
}
}

Expand All @@ -59,9 +78,23 @@ public static unsafe SafeMsQuicConfigurationHandle Create(QuicClientConnectionOp
public static unsafe SafeMsQuicConfigurationHandle Create(QuicListenerOptions options)
{
QUIC_CREDENTIAL_FLAGS flags = QUIC_CREDENTIAL_FLAGS.NONE;
if (options.ServerAuthenticationOptions != null && options.ServerAuthenticationOptions.ClientCertificateRequired)

if (options.ServerAuthenticationOptions != null)
{
flags |= QUIC_CREDENTIAL_FLAGS.REQUIRE_CLIENT_AUTHENTICATION | QUIC_CREDENTIAL_FLAGS.INDICATE_CERTIFICATE_RECEIVED | QUIC_CREDENTIAL_FLAGS.NO_CERTIFICATE_VALIDATION;
if (options.ServerAuthenticationOptions.CipherSuitesPolicy != null)
{
throw new PlatformNotSupportedException(SR.Format(SR.net_quic_ssl_option, nameof(options.ServerAuthenticationOptions.CipherSuitesPolicy)));
}

if (options.ServerAuthenticationOptions.EncryptionPolicy == EncryptionPolicy.NoEncryption)
{
throw new PlatformNotSupportedException(SR.Format(SR.net_quic_ssl_option, nameof(options.ServerAuthenticationOptions.EncryptionPolicy)));
}

if (options.ServerAuthenticationOptions.ClientCertificateRequired)
{
flags |= QUIC_CREDENTIAL_FLAGS.REQUIRE_CLIENT_AUTHENTICATION | QUIC_CREDENTIAL_FLAGS.INDICATE_CERTIFICATE_RECEIVED | QUIC_CREDENTIAL_FLAGS.NO_CERTIFICATE_VALIDATION;
}
}

return Create(options, flags, options.ServerAuthenticationOptions?.ServerCertificate, options.ServerAuthenticationOptions?.ServerCertificateContext, options.ServerAuthenticationOptions?.ApplicationProtocols);
Expand Down

0 comments on commit b2107c5

Please sign in to comment.