Skip to content

Commit

Permalink
(GH-458) Support TLS v1.2
Browse files Browse the repository at this point in the history
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. If someone compiles choco with .NET 4.0, post
a warning about the encryption not being good enough.
  • Loading branch information
ferventcoder committed Oct 11, 2015
1 parent fd09a01 commit 91e492c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
<Compile Include="infrastructure.app\domain\CommandNameType.cs" />
<Compile Include="infrastructure\events\EventManager.cs" />
<Compile Include="infrastructure\events\IEvent.cs" />
<Compile Include="infrastructure\registration\SecurityProtocol.cs" />
<Compile Include="infrastructure\registration\SimpleInjectorContainer.cs" />
<Compile Include="infrastructure\results\IResult.cs" />
<Compile Include="infrastructure\results\PackageResult.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure/registration/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void initialize()
{
Log.InitializeWith<Log4NetLog>();
_logger.Debug("XmlConfiguration is now operational");
SecurityProtocol.set_protocol();
}

/// <summary>
Expand Down
41 changes: 41 additions & 0 deletions src/chocolatey/infrastructure/registration/SecurityProtocol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.Net;
using logging;

public sealed class SecurityProtocol
{
public static void set_protocol()
{
#if NETFX_45
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
#else
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
built 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.
For more information you should visit https://www.howsmyssl.com/");
#endif
}
}
}

0 comments on commit 91e492c

Please sign in to comment.