From fce9698a55798c39fd52a22b4277d0c876bfb6f9 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Tue, 16 Jan 2024 15:57:04 -0600 Subject: [PATCH 1/2] Http Proxy logic to correctly pull out the right string values --- .../Get-HttpProxySetting.ps1 | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-HttpProxySetting.ps1 b/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-HttpProxySetting.ps1 index a6be0ee705..02cabbae95 100644 --- a/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-HttpProxySetting.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-HttpProxySetting.ps1 @@ -15,25 +15,28 @@ function Get-HttpProxySetting { [Parameter(Mandatory = $true)][string]$RegistryLocation ) $connections = Get-ItemProperty -Path $RegistryLocation + $byteLength = 4 + $proxyStartLocation = 16 + $proxyLength = 0 $proxyAddress = [string]::Empty $byPassList = [string]::Empty if (($null -ne $connections) -and ($Connections | Get-Member).Name -contains "WinHttpSettings") { - $onProxy = $true + try { + $bytes = $Connections.WinHttpSettings + $proxyLength = [System.BitConverter]::ToInt32($bytes, $proxyStartLocation - $byteLength) - foreach ($Byte in $Connections.WinHttpSettings) { - if ($onProxy -and - $Byte -ge 42) { - $proxyAddress += [CHAR]$Byte - } elseif (-not $onProxy -and - $Byte -ge 42) { - $byPassList += [CHAR]$Byte - } elseif (-not ([string]::IsNullOrEmpty($proxyAddress)) -and - $onProxy -and - $Byte -eq 0) { - $onProxy = $false + if ($proxyLength -gt 0) { + $proxyAddress = [System.Text.Encoding]::UTF8.GetString($bytes, $proxyStartLocation, $proxyLength) + $byPassListLength = [System.BitConverter]::ToInt32($bytes, $proxyStartLocation + $proxyLength) + + if ($byPassListLength -gt 0) { + $byPassList = [System.Text.Encoding]::UTF8.GetString($bytes, $byteLength + $proxyStartLocation + $proxyLength, $byPassListLength) + } } + } catch { + Write-Verbose "Failed to properly get HTTP Proxy information. Inner Exception: $_" } } From ddbbb6da14aef60c084c12f5f5cdd56748c3596c Mon Sep 17 00:00:00 2001 From: David Paulson Date: Tue, 16 Jan 2024 16:18:48 -0600 Subject: [PATCH 2/2] Don't show mismatch if port 80 is used on proxy --- .../HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 b/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 index e49fd53613..2b9f3680d0 100644 --- a/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 +++ b/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 @@ -332,7 +332,9 @@ function Invoke-AnalyzerOsInformation { if (($osInformation.NetworkInformation.HttpProxy.ProxyAddress -ne "None") -and ($exchangeInformation.GetExchangeServer.IsEdgeServer -eq $false) -and - ($osInformation.NetworkInformation.HttpProxy.ProxyAddress -ne $exchangeInformation.GetExchangeServer.InternetWebProxy.Authority)) { + ($null -ne $exchangeInformation.GetExchangeServer.InternetWebProxy) -and + ($osInformation.NetworkInformation.HttpProxy.ProxyAddress -ne + "$($exchangeInformation.GetExchangeServer.InternetWebProxy.Host):$($exchangeInformation.GetExchangeServer.InternetWebProxy.Port)")) { $params = $baseParams + @{ Details = "Error: Exchange Internet Web Proxy doesn't match OS Web Proxy." DisplayWriteType = "Red"