Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cChocoInstaller - Use SSLv3 only for powershell 5 or lower versions #183

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions DSCResources/cChocoInstaller/cChocoInstaller.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,20 @@ function Get-FileDownload {
[ValidateNotNullOrEmpty()]
[string]$file
)

# Set security protocol preference to avoid the download error if the machine has disabled TLS 1.0 and SSLv3
# See: https://chocolatey.org/install (Installing With Restricted TLS section)
# Since cChoco requires at least PowerShell 4.0, we have .NET 4.5 available, so we can use [System.Net.SecurityProtocolType] enum values by name.
# Since cChoco requires at least PowerShell 4.0, we have .NET 4.5 available, so we can use
# [System.Net.SecurityProtocolType] enum values by name.
$securityProtocolSettingsOriginal = [System.Net.ServicePointManager]::SecurityProtocol
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls -bor [System.Net.SecurityProtocolType]::Ssl3

$tlsVersions = [enum]::GetValues('Net.SecurityProtocolType') | Where-Object { $_ -ge 'Tls' } # Include TLS versions by default
$tlsVersions.ForEach({[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor $_})

# SSLv3 is deprecated in version 6+ so only enable it for earlier versions
if ($PSVersionTable.PSVersion.Major -lt 6) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Ssl3
}

Write-Verbose "Downloading $url to $file"
$downloader = new-object -TypeName System.Net.WebClient
Expand Down