Skip to content

Commit

Permalink
(GH-719) Reset ServerCertificateValidationCallback
Browse files Browse the repository at this point in the history
If the server certificate validation callback is set in
ServicePointManager, reset it to null with a warning.
  • Loading branch information
ferventcoder committed Sep 10, 2016
1 parent 2f44f93 commit be29013
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace chocolatey.infrastructure.app.services
using cryptography;
using domain;
using infrastructure.commands;
using infrastructure.registration;
using logging;
using NuGet;
using powershell;
Expand Down Expand Up @@ -468,6 +469,8 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura
Environment.SetEnvironmentVariable("CacheChecksumType_{0}".format_with(urlKey), "sha512");
}
}

SecurityProtocol.set_protocol();
}

private ResolveEventHandler _handler = null;
Expand Down
14 changes: 14 additions & 0 deletions src/chocolatey/infrastructure/registration/SecurityProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ Chaining. Upgrade to at least .NET 4.5 at your earliest convenience.
For more information you should visit https://www.howsmyssl.com/");

}

try
{
if (ServicePointManager.ServerCertificateValidationCallback != null)
{
"chocolatey".Log().Warn("ServerCertificateValidationCallback was set to '{0}' Removing.".format_with(System.Net.ServicePointManager.ServerCertificateValidationCallback));
ServicePointManager.ServerCertificateValidationCallback = null;
}
}
catch (Exception ex)
{
"chocolatey".Log().Warn("Error resetting ServerCertificateValidationCallback: {0}".format_with(ex.Message));
}

}
}
}

0 comments on commit be29013

Please sign in to comment.