From 91e492c262c085f914419279aeb787686231bede Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sat, 10 Oct 2015 19:52:45 -0500 Subject: [PATCH] (GH-458) Support TLS v1.2 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. --- src/chocolatey/chocolatey.csproj | 1 + .../infrastructure/registration/Bootstrap.cs | 1 + .../registration/SecurityProtocol.cs | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/chocolatey/infrastructure/registration/SecurityProtocol.cs diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index c828eeadd2..9893266e1a 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -213,6 +213,7 @@ + diff --git a/src/chocolatey/infrastructure/registration/Bootstrap.cs b/src/chocolatey/infrastructure/registration/Bootstrap.cs index db15a77d89..22bbeb80b2 100644 --- a/src/chocolatey/infrastructure/registration/Bootstrap.cs +++ b/src/chocolatey/infrastructure/registration/Bootstrap.cs @@ -35,6 +35,7 @@ public static void initialize() { Log.InitializeWith(); _logger.Debug("XmlConfiguration is now operational"); + SecurityProtocol.set_protocol(); } /// diff --git a/src/chocolatey/infrastructure/registration/SecurityProtocol.cs b/src/chocolatey/infrastructure/registration/SecurityProtocol.cs new file mode 100644 index 0000000000..8962f8bb5c --- /dev/null +++ b/src/chocolatey/infrastructure/registration/SecurityProtocol.cs @@ -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 + } + } +}