From 6ee42d278768348d5ea2267d2c640e5735ecfffc Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 27 Dec 2014 21:06:02 +0100 Subject: [PATCH] Mono has no root certs! Uglyhacking. --- Logic/Financial/ExchangeRateSnapshot.cs | 3 +++ Logic/Logic.csproj | 1 + Logic/Support/General.cs | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 Logic/Support/General.cs diff --git a/Logic/Financial/ExchangeRateSnapshot.cs b/Logic/Financial/ExchangeRateSnapshot.cs index b4d3f154..f1c623c9 100644 --- a/Logic/Financial/ExchangeRateSnapshot.cs +++ b/Logic/Financial/ExchangeRateSnapshot.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Web.Script.Serialization; using System.Xml.Serialization; using Swarmops.Basic.Types.Financial; +using Swarmops.Logic.Support; namespace Swarmops.Logic.Financial { @@ -39,6 +40,8 @@ namespace Swarmops.Logic.Financial { using(WebClient client = new WebClient()) { + SupportFunctions.DisableSslCertificateChecks(); // MONO BUG/MISFEATURE: Mono has no root certificates, so can't verify cert + client.Encoding = Encoding.UTF8; string rateDataRaw = client.DownloadString("https://bitpay.com/api/rates"); diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index c22c8963..038a2df7 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -252,6 +252,7 @@ + diff --git a/Logic/Support/General.cs b/Logic/Support/General.cs new file mode 100644 index 00000000..4be36ddd --- /dev/null +++ b/Logic/Support/General.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace Swarmops.Logic.Support +{ + public class SupportFunctions + { + public static void DisableSslCertificateChecks() + { + // X.509 is SO SO SO broken. The reason we do this, btw, is that mono doesn't come with root certs. At all. + + // This disables certificate checking completely and accepts ALL certificates. + + System.Net.ServicePointManager.ServerCertificateValidationCallback += + (sender, certificate, chain, sslPolicyErrors) => true; + } + } +}