Mono Frustrations: “The authentication or decryption has failed.”

Often calling the AuthenticateAsClient method of an SslStream results in the “The authentication or decryption has failed.” error, because Mono cannot verify the certificate. As a last resort, the error can be circumvented by disabling the certificate validation by adding the following line to the code:

ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;

If you are creating the SslStream in a using block, you can do this instead:

using (SslStream s = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback((o, certificate, chain, errors) => true)))
s.AuthenticateAsClient(uri.Host, null, SslProtocols.Tls, false);

Leave a Reply