Skip to content

Commit

Permalink
Enable TLS 1.2 for Invoke-WebRequest (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
arsing authored Nov 1, 2018
1 parent 645545a commit e93e707
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scripts/windows/setup/IotEdgeSecurityDaemon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ function Install-SecurityDaemon {
return
}

if (-not (Test-IotCore)) {
# `Invoke-WebRequest` may not use TLS 1.2 by default, depending on the specific release of Windows 10.
# This will be a problem if the release is downloaded from github.com since it only provides TLS 1.2.
# So enable TLS 1.2 in `[System.Net.ServicePointManager]::SecurityProtocol`, which enables it (in the current PS session)
# for `Invoke-WebRequest` and everything else that uses `System.Net.HttpWebRequest`
#
# This is not needed on IoT Core since its `Invoke-WebRequest` supports TLS 1.2 by default. It *can't* be done
# for IoT Core anyway because the `System.Net.ServicePointManager` type doesn't exist in its version of dotnet.
[System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12
}

$usesSeparateDllForEventLogMessages = Get-SecurityDaemon
Set-SystemPath
Get-VcRuntime
Expand Down Expand Up @@ -146,7 +158,7 @@ function Test-IsDockerRunning {
}
} else {
Write-Host "Docker is not running." -ForegroundColor "Red"
if ((Get-Item "HKLM:\Software\Microsoft\Windows NT\CurrentVersion").GetValue("EditionID") -eq "IoTUAP") {
if (Test-IotCore) {
Write-Host ("Please visit https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-core " +
"for assistance with installing Docker on IoT Core.") `
-ForegroundColor "Red"
Expand Down Expand Up @@ -364,7 +376,7 @@ function Reset-SystemPath {
}

function Get-VcRuntime {
if ((Get-Item "HKLM:\Software\Microsoft\Windows NT\CurrentVersion").GetValue("EditionID") -eq "IoTUAP") {
if (Test-IotCore) {
Write-Host "Skipped vcruntime download on IoT Core." -ForegroundColor "Green"
return
}
Expand Down Expand Up @@ -647,5 +659,9 @@ function Invoke-Native {
}
}

function Test-IotCore {
(Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').'EditionID' -eq 'IoTUAP'
}

Export-ModuleMember -Function Install-SecurityDaemon, Uninstall-SecurityDaemon
}

0 comments on commit e93e707

Please sign in to comment.