From 3ea7632af6ac3331d84475c57234f0276ab5b10b Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Tue, 4 Sep 2018 08:41:09 -0500 Subject: [PATCH] Revert "Only run the cert validation on 45 or netstandard 2.0" This reverts commit 6dcf54399c5cfb8db45a70becf232197f5689a50. --- build/sourcelink.props | 2 +- .../Configuration/CertificateData.cs | 7 ++++--- .../Configuration/ExceptionlessConfiguration.cs | 2 +- .../ExceptionlessConfigurationExtensions.cs | 15 ++++----------- .../Submission/DefaultSubmissionClient.cs | 10 +++++----- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/build/sourcelink.props b/build/sourcelink.props index 7a526507..ec7ca577 100644 --- a/build/sourcelink.props +++ b/build/sourcelink.props @@ -4,6 +4,6 @@ - + \ No newline at end of file diff --git a/src/Exceptionless/Configuration/CertificateData.cs b/src/Exceptionless/Configuration/CertificateData.cs index 7c8dd5cb..0b15333f 100644 --- a/src/Exceptionless/Configuration/CertificateData.cs +++ b/src/Exceptionless/Configuration/CertificateData.cs @@ -1,5 +1,4 @@ -#if NET45 || NETSTANDARD2_0 -using System; +#if !PORTABLE && !NETSTANDARD1_2 using System.Net.Http; using System.Net.Security; using System.Security.Cryptography.X509Certificates; @@ -44,7 +43,9 @@ private CertificateData(X509Chain chain, SslPolicyErrors sslPolicyErrors) { /// An object that contains state information for this validation. /// public object Sender { get; } -#else +#endif + +#if !NET45 && !PORTABLE && !NETSTANDARD1_2 /// /// The request which was sent to the remore party /// diff --git a/src/Exceptionless/Configuration/ExceptionlessConfiguration.cs b/src/Exceptionless/Configuration/ExceptionlessConfiguration.cs index 52a5216b..11e1746b 100644 --- a/src/Exceptionless/Configuration/ExceptionlessConfiguration.cs +++ b/src/Exceptionless/Configuration/ExceptionlessConfiguration.cs @@ -277,7 +277,7 @@ public int SubmissionBatchSize { } } -#if NET45 || NETSTANDARD2_0 +#if !PORTABLE && !NETSTANDARD1_2 /// /// Callback which is invoked to validate the exceptionless server certificate. /// diff --git a/src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs b/src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs index 47cb53cb..63b940e0 100644 --- a/src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs +++ b/src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs @@ -436,7 +436,7 @@ private static string GetEnvironmentalVariable(string name) { } #endif -#if NET45 || NETSTANDARD2_0 +#if !PORTABLE && !NETSTANDARD1_2 /// /// Add a custom server certificate validation against the thumbprint of the server certificate. /// @@ -444,9 +444,7 @@ private static string GetEnvironmentalVariable(string name) { /// Thumbprint of the server certificate. e.g. "86481791CDAF6D7A02BEE9A649EA9F84DE84D22C" public static void TrustCertificateThumbprint(this ExceptionlessConfiguration config, string thumbprint) { config.ServerCertificateValidationCallback = x => { - if (x.SslPolicyErrors == SslPolicyErrors.None) - return true; - + if (x.SslPolicyErrors == SslPolicyErrors.None) return true; return x.Certificate != null && thumbprint != null && thumbprint.Equals(x.Certificate.Thumbprint, StringComparison.OrdinalIgnoreCase); }; } @@ -458,17 +456,12 @@ public static void TrustCertificateThumbprint(this ExceptionlessConfiguration co /// Thumbprint of the ca certificate. e.g. "afe5d244a8d1194230ff479fe2f897bbcd7a8cb4" public static void TrustCAThumbprint(this ExceptionlessConfiguration config, string thumbprint) { config.ServerCertificateValidationCallback = x => { - if (x.SslPolicyErrors == SslPolicyErrors.None) - return true; - - if (x.Chain == null || thumbprint == null) - return false; - + if (x.SslPolicyErrors == SslPolicyErrors.None) return true; + if (x.Chain == null || thumbprint == null) return false; foreach (var ca in x.Chain.ChainElements) { if (thumbprint.Equals(ca.Certificate.Thumbprint, StringComparison.OrdinalIgnoreCase)) return true; } - return false; }; } diff --git a/src/Exceptionless/Submission/DefaultSubmissionClient.cs b/src/Exceptionless/Submission/DefaultSubmissionClient.cs index 60b4013c..e1c23a67 100644 --- a/src/Exceptionless/Submission/DefaultSubmissionClient.cs +++ b/src/Exceptionless/Submission/DefaultSubmissionClient.cs @@ -4,7 +4,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; -#if NET45 || NETSTANDARD2_0 +#if NET45 || (!PORTABLE && !NETSTANDARD1_2) using System.Net.Security; using System.Security.Cryptography.X509Certificates; #endif @@ -130,13 +130,13 @@ protected virtual HttpClient CreateHttpClient(ExceptionlessConfiguration config) #else var handler = new HttpClientHandler { UseDefaultCredentials = true }; #endif -#if NET45 || NETSTANDARD2_0 +#if !PORTABLE && !NETSTANDARD1_2 var callback = config.ServerCertificateValidationCallback; if (callback != null) { #if NET45 - handler.ServerCertificateValidationCallback = (s,c,ch,p) => Validate(s,c,ch,p,callback); + handler.ServerCertificateValidationCallback = (s,c,ch,p)=>Validate(s,c,ch,p,callback); #else - handler.ServerCertificateCustomValidationCallback = (m,c,ch,p) => Validate(m,c,ch,p,callback); + handler.ServerCertificateCustomValidationCallback = (m,c,ch,p)=>Validate(m,c,ch,p,callback); #endif } #endif @@ -157,7 +157,7 @@ protected virtual HttpClient CreateHttpClient(ExceptionlessConfiguration config) return client; } -#if NET45 || NETSTANDARD2_0 +#if !PORTABLE && !NETSTANDARD1_2 #if NET45 private bool Validate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors, Func callback) { var certData = new CertificateData(sender, certificate, chain, sslPolicyErrors);