Mono Https Webrequest Fails with "The Authentication or Decryption Has Failed"

Mono https webrequest fails with The authentication or decryption has failed

Mono does not trust any certificate by default, to import the Mozilla trusted root authorities you can run mozroots --import --quiet in the mono installation folder where mozroots.exe is located

Mono Service Exception - The authentication or decryption has failed

Try to replace this line:

 var ssl_stream = new SslStream(csGlobal.m_tcp_client.GetStream(), false, (sender, certificate, chain, ssl_policy_errors) => ssl_policy_errors == SslPolicyErrors.None);

with this:

 var ssl_stream = new SslStream(csGlobal.m_tcp_client.GetStream());

WebClient.DownloadString with HTTPS The authentication or decryption has failed

After some rigorous research it turns out that the version of Mono that Unity(2017.2.0f3) currently uses does not support TLS 1.2, as explained by a developer here. Also, a careful examination of the exception log shows that internally, the legacy backend is being used: Mono.Net.Security.Private.LegacySslStream as opposed to Mono.Net.Security.Private.SslStream. As of right now, the only solution would involve third-party libraries, or workarounds.

Thanks to @Evk for pointing me in the right direction.

The authentication or decryption has failed.

It was necessary to run it without sudo.

Some HTTPS domains fail in mono

The domains you list as failing all require Server Name Indication (SNI). My guess is that you unknown version of Mono has no support for SNI yet. If this is the case just adding some more CA certificates will not help because this problem is unrelated to certificate validation.

According to this bugreport Mono should have support for SNI at least starting with version 3.0.10 but not in 2.x so you might check what version you are running.

C# Mono - Error: SecureChannelFailure - HTTPS request fails for some domain

After days and days by searching solution, I understand that I had to use a trick because the error come from Mono.

This is not the proper way, but the most simple.

I used a free domain for hosting a php file which contain this in
domain.com/myfile.php :

<?php echo file_get_contents("url of the website"); ?>

And then, instead of using the url causing the issue, I replace with the link of PHP file in C#.

string url = "domain.com/myfile.php";
using (WebClient client = new WebClient())
{
string html = client.DownloadString(url);
lines = Regex.Split(html, @"\r?\n|\r");
client.Dispose();
}

C# WebRequest succed with .NET but failed using Mono

Adding

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

At the beginning of GetRequest(uri) solved the problem.



Related Topics



Leave a reply



Submit