-
Notifications
You must be signed in to change notification settings - Fork 571
Description
Describe the bug
It's possible to disable (or provide custom) SSL validation by setting SslCertificateAuthentication
like in this example:
serviceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
{
CertificateValidationMode = X509CertificateValidationMode.None,
RevocationMode = X509RevocationMode.NoCheck,
};
However, this only works when using client certificate authentication.
Looking at:
Line 155 in f789e63
if (_channelFactory is HttpsChannelFactory<IDuplexSessionChannel> httpsChannelFactory && httpsChannelFactory.RequireClientCertificate) |
It seems like the WebSocket RemoteCertificateValidationCallback is only ever set if RequireClientCertificate is true, which will only be the case when using client certificates.
It should be possible to disable or customize server SSL certificate validation regardless of the auth type being used.
To Reproduce
- Create a binding where WebSockets are always enabled, without setting any client certificate auth.
var binding = new NetHttpBinding(BasicHttpSecurityMode.Transport)
{
MaxReceivedMessageSize = int.MaxValue,
WebSocketSettings = { TransportUsage = WebSocketTransportUsage.Always },
};
- Disable SSL validation with:
serviceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
serviceCertificate.Authentication.CustomCertificateValidator = new DisableCertificateValidation();
serviceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
{
CertificateValidationMode = X509CertificateValidationMode.None,
RevocationMode = X509RevocationMode.NoCheck
};
- Try to call a service that uses a self-signed SSL certificate, or one that doesn't match the domain.
Expected behavior
The call should succeed.
Actual behavior
Call fails with an error similar to this one:
Exception info dump:
System.ServiceModel.CommunicationException: Unable to connect to the remote server
---> System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.