-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The .NET Framework supports TLS v1.2 as of version 4.5 - http://msdn.microsoft.com/en-us/library/system.security.authentication.sslprotocols(v=vs.110).aspx but the security protocol is not set to use it out of the box. Set the SecurityProtocol to start with the highest encryption available and move down from there. Choco is compiled on .NET 4.0, but .NET 4.5 is an in place upgrade, which gives us access to set the proper security protocols by converting the enumeration values directly into `SecurityProtocolType`. This will fail when running on .NET 4.0, so fall back to using TLS, then SSLv3 with a warning recommending folks upgrade to .NET 4.5 at their earliest convenience.
- Loading branch information
1 parent
f4ae1c9
commit 2d39d97
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/chocolatey/infrastructure/registration/SecurityProtocol.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright © 2011 - Present RealDimensions Software, LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.registration | ||
{ | ||
using System; | ||
using System.Net; | ||
using logging; | ||
|
||
public sealed class SecurityProtocol | ||
{ | ||
private const int TLS_1_1 = 768; | ||
private const int TLS_1_2 = 3072; | ||
|
||
public static void set_protocol() | ||
{ | ||
try | ||
{ | ||
// We can't address the protocols directly when built with .NET | ||
// Framework 4.0. However if someone is running .NET 4.5 or | ||
// greater, they have in-place upgrades for System.dll, which | ||
// will allow us to set these protocols directly. | ||
const SecurityProtocolType tls11 = (SecurityProtocolType)TLS_1_1; | ||
const SecurityProtocolType tls12 = (SecurityProtocolType)TLS_1_2; | ||
ServicePointManager.SecurityProtocol = tls12 | tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3; | ||
} | ||
catch (Exception) | ||
{ | ||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3; | ||
"chocolatey".Log().Warn(ChocolateyLoggers.Important, | ||
@" !!WARNING!! | ||
Choco prefers to use TLS v1.2 if it is available, but this client is | ||
running on .NET 4.0, which uses an older SSL. It's using TLS 1.0 or | ||
earlier, which makes it susceptible to BEAST and also doesn't | ||
implement the 1/n-1 record splitting mitigation for Cipher-Block | ||
Chaining. Upgrade to at least .NET 4.5 at your earliest convenience. | ||
For more information you should visit https://www.howsmyssl.com/"); | ||
|
||
} | ||
} | ||
} | ||
} |
2d39d97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of this code was originally at #459