Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072"
  • Loading branch information
aaronparker committed Mar 20, 2024
1 parent 46ee734 commit 0174e37
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
# shell: pwsh
# working-directory: "${{ github.workspace }}"
# run: |
# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# Install-PackageProvider -Name "NuGet" -MinimumVersion "2.8.5.208" -Force -ErrorAction "SilentlyContinue"
# Install-PackageProvider -Name "PowerShellGet" -MinimumVersion "2.2.5" -Force -ErrorAction "SilentlyContinue"
# Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted" -ErrorAction "SilentlyContinue"
Expand All @@ -105,7 +105,7 @@ jobs:
# shell: pwsh
# working-directory: "${{ github.workspace }}"
# run: |
# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# Install-PackageProvider -Name "NuGet" -MinimumVersion "2.8.5.208" -Force -ErrorAction "SilentlyContinue"
# Install-PackageProvider -Name "PowerShellGet" -MinimumVersion "2.2.5" -Force -ErrorAction "SilentlyContinue"
# Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted" -ErrorAction "SilentlyContinue"
Expand Down
10 changes: 2 additions & 8 deletions Evergreen/Private/Invoke-EvergreenRestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,12 @@ public class TrustAllCertsPolicy : ICertificatePolicy {
}
}
"@
Write-Verbose -Message "$($MyInvocation.MyCommand): Settings Net.SecurityProtocolType to $SslProtocol."
Write-Verbose -Message "$($MyInvocation.MyCommand): Trust all certificates."
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName "TrustAllCertsPolicy"
}

# Use TLS for connections
if (($SslProtocol.IsPresent) -and -not(Test-PSCore)) {
if ($SslProtocol -eq "Tls13") {
$SslProtocol = "Tls12"
Write-Warning -Message "$($MyInvocation.MyCommand): Defaulting back to TLS1.2."
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::$SslProtocol
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072

#region Build the Invoke-RestMethod parameters
$params = @{
Expand Down
10 changes: 2 additions & 8 deletions Evergreen/Private/Invoke-EvergreenWebRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,12 @@ public class TrustAllCertsPolicy : ICertificatePolicy {
}
}
"@
Write-Verbose -Message "$($MyInvocation.MyCommand): Trust all certificates."
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName "TrustAllCertsPolicy"
}

# Use TLS for connections
if ($PSBoundParameters.ContainsKey("SslProtocol") -and -not(Test-PSCore)) {
if ($SslProtocol -eq "Tls13") {
$SslProtocol = "Tls12"
Write-Warning -Message "$($MyInvocation.MyCommand): Defaulting back to TLS1.2."
}
Write-Verbose -Message "$($MyInvocation.MyCommand): Settings Net.SecurityProtocolType to $SslProtocol."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::$SslProtocol
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072

# Build the Invoke-WebRequest parameters
$params = @{
Expand Down
3 changes: 1 addition & 2 deletions Evergreen/Private/Save-File.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
$params.SslProtocol = "Tls12"
}
else {
$SslProtocol = "Tls12"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::$SslProtocol
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
}
Invoke-WebRequest @params
}
Expand Down
2 changes: 1 addition & 1 deletion Evergreen/Public/Save-EvergreenApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Function Save-EvergreenApp {
#endregion

# Enable TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
}

process {
Expand Down
5 changes: 2 additions & 3 deletions Evergreen/Shared/Get-GitHubRepoRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ function Get-GitHubRepoRelease {
try {
# Retrieve the releases from the GitHub API
# Use TLS for connections
$SslProtocol = "Tls12"
Write-Verbose -Message "$($MyInvocation.MyCommand): Set TLS to $SslProtocol."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::$SslProtocol
Write-Verbose -Message "$($MyInvocation.MyCommand): Set TLS to 1.2."
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072

# Invoke the GitHub releases REST API
# Note that the API performs rate limiting.
Expand Down
3 changes: 1 addition & 2 deletions ci/GitHub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
param ()

try {
$SslProtocol = "Tls12"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::$SslProtocol
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
$params = @{
ContentType = "application/vnd.github.v3+json"
ErrorAction = "SilentlyContinue"
Expand Down
31 changes: 11 additions & 20 deletions scripts/Test-RestMethod.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
$Uri = "https://api.github.com/repos/git-for-windows/git1/releases/latest"
$tempFile = New-TemporaryFile

try {
$params = @{
Uri = $Uri
Method = "Get"
ContentType = "application/vnd.github.v3+json"
UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
UseBasicParsing = $true
PassThru = $true
OutFile = $tempFile
}
$response = Invoke-RestMethod @params
}
catch {
Write-Warning -Message "$($MyInvocation.MyCommand): REST API call to [$Uri] failed with: $($_.Exception.Response.StatusCode)."
Throw $_
Break
$params = @{
Uri = $Uri
Method = "Get"
ContentType = "application/vnd.github.v3+json"
UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
UseBasicParsing = $true
PassThru = $true
OutFile = $tempFile
ErrorAction = "Stop"
}

$response
Invoke-RestMethod @params

0 comments on commit 0174e37

Please sign in to comment.