Skip to content

Commit

Permalink
Revert "Only run the cert validation on 45 or netstandard 2.0"
Browse files Browse the repository at this point in the history
This reverts commit 6dcf543.
  • Loading branch information
niemyjski committed Sep 4, 2018
1 parent 6dcf543 commit 3ea7632
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build/sourcelink.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.8.3" PrivateAssets="all" />
<PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.8.1" PrivateAssets="all" />
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions src/Exceptionless/Configuration/CertificateData.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,7 +43,9 @@ private CertificateData(X509Chain chain, SslPolicyErrors sslPolicyErrors) {
/// An object that contains state information for this validation.
/// </summary>
public object Sender { get; }
#else
#endif

#if !NET45 && !PORTABLE && !NETSTANDARD1_2
/// <summary>
/// The request which was sent to the remore party
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public int SubmissionBatchSize {
}
}

#if NET45 || NETSTANDARD2_0
#if !PORTABLE && !NETSTANDARD1_2
/// <summary>
/// Callback which is invoked to validate the exceptionless server certificate.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,15 @@ private static string GetEnvironmentalVariable(string name) {
}
#endif

#if NET45 || NETSTANDARD2_0
#if !PORTABLE && !NETSTANDARD1_2
/// <summary>
/// Add a custom server certificate validation against the thumbprint of the server certificate.
/// </summary>
/// <param name="config">The configuration object you want to apply the attribute settings to.</param>
/// <param name="thumbprint">Thumbprint of the server certificate. <example>e.g. "86481791CDAF6D7A02BEE9A649EA9F84DE84D22C"</example></param>
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);
};
}
Expand All @@ -458,17 +456,12 @@ public static void TrustCertificateThumbprint(this ExceptionlessConfiguration co
/// <param name="thumbprint">Thumbprint of the ca certificate. <example>e.g. "afe5d244a8d1194230ff479fe2f897bbcd7a8cb4"</example></param>
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;
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/Exceptionless/Submission/DefaultSubmissionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<CertificateData, bool> callback) {
var certData = new CertificateData(sender, certificate, chain, sslPolicyErrors);
Expand Down

0 comments on commit 3ea7632

Please sign in to comment.