Skip to content

Commit

Permalink
Merge pull request #3067 from warlof/disclose-sslissue
Browse files Browse the repository at this point in the history
fix: enhance ps7 compatibility with ssl selfsigned
  • Loading branch information
freddydk committed May 27, 2023
2 parents 411b165 + 89f7648 commit 2d16653
Show file tree
Hide file tree
Showing 5 changed files with 1,197 additions and 1,204 deletions.
26 changes: 2 additions & 24 deletions AppHandling/Compile-AppInNavContainer.ps1
Expand Up @@ -391,25 +391,8 @@ try {
$devServerUrl = "$($protocol)$($containerName):$($customConfig.DeveloperServicesPort)/$ServerInstance"
}

$sslVerificationDisabled = ($protocol -eq "https://")
if ($sslVerificationDisabled) {
if (-not ([System.Management.Automation.PSTypeName]"SslVerification").Type)
{
Add-Type -TypeDefinition "
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class SslVerification
{
private static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
public static void Disable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidationCallback; }
public static void Enable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = null; }
}"
}
Write-Host "Disabling SSL Verification"
[SslVerification]::Disable()
}

$timeout = 300000
$sslVerificationDisabled = ($protocol -eq "https://")
if ($customConfig.ClientServicesCredentialType -eq "Windows") {
$useDefaultCredentials = $true
}
Expand Down Expand Up @@ -467,7 +450,7 @@ try {
}
Write-Host "Url : $Url"
try {
DownloadFileLow -sourceUrl $url -destinationFile $symbolsFile -timeout $timeout -useDefaultCredentials:$useDefaultCredentials -Headers $headers
DownloadFileLow -sourceUrl $url -destinationFile $symbolsFile -timeout $timeout -useDefaultCredentials:$useDefaultCredentials -Headers $headers -skipCertificateCheck:$sslVerificationDisabled
}
catch {
$throw = $true
Expand Down Expand Up @@ -560,11 +543,6 @@ try {
}
$depidx++
}

if ($sslverificationdisabled) {
Write-Host "Re-enabling SSL Verification"
[SslVerification]::Enable()
}

$result = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($appProjectFolder, $appSymbolsFolder, $appOutputFile, $EnableCodeCop, $EnableAppSourceCop, $EnablePerTenantExtensionCop, $EnableUICop, $CustomCodeCops, $rulesetFile, $assemblyProbingPaths, $nowarn, $GenerateCrossReferences, $ReportSuppressedDiagnostics, $generateReportLayoutParam, $features, $preProcessorSymbols, $platformversion, $updateDependencies )

Expand Down
24 changes: 1 addition & 23 deletions AppHandling/Get-NavContainerApp.ps1
Expand Up @@ -64,23 +64,6 @@ try {
}

$sslVerificationDisabled = ($protocol -eq "https://")
if ($sslVerificationDisabled) {
if (-not ([System.Management.Automation.PSTypeName]"SslVerification").Type)
{
Add-Type -TypeDefinition "
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class SslVerification
{
private static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
public static void Disable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidationCallback; }
public static void Enable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = null; }
}"
}
Write-Host "Disabling SSL Verification"
[SslVerification]::Disable()
}

$timeout = 300000
$useDefaultCredentials = $false
$headers = @{}
Expand All @@ -104,18 +87,13 @@ try {
$url = "$devServerUrl/dev/packages?publisher=$([uri]::EscapeDataString($publisher))&appName=$([uri]::EscapeDataString($appName))&versionText=$($appVersion)&tenant=$tenant"
Write-Host "Url : $Url"
try {
DownloadFileLow -sourceUrl $url -destinationFile $appFile -timeout $timeout -useDefaultCredentials:$useDefaultCredentials -Headers $headers
DownloadFileLow -sourceUrl $url -destinationFile $appFile -timeout $timeout -useDefaultCredentials:$useDefaultCredentials -Headers $headers -skipCertificateCheck:$sslVerificationDisabled
}
catch [System.Net.WebException] {
Write-Host "ERROR $($_.Exception.Message)"
throw (GetExtendedErrorMessage $_)
}

if ($sslverificationdisabled) {
Write-Host "Re-enabling SSL Verification"
[SslVerification]::Enable()
}

$appFile
}
catch {
Expand Down
20 changes: 11 additions & 9 deletions AppHandling/PsTestFunctions.ps1
Expand Up @@ -1243,16 +1243,18 @@ function Disable-SslVerification
{
if (-not ([System.Management.Automation.PSTypeName]"SslVerification").Type)
{
Add-Type -TypeDefinition @"
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class SslVerification
{
private static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
public static void Disable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidationCallback; }
public static void Enable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = null; }
}
$sslCallbackCode = @"
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class SslVerification
{
public static bool DisabledServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
public static void Disable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = DisabledServerCertificateValidationCallback; }
public static void Enable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = null; }
}
"@
Add-Type -TypeDefinition $sslCallbackCode
}
[SslVerification]::Disable()
}
Expand Down
39 changes: 12 additions & 27 deletions AppHandling/Publish-NavContainerApp.ps1
Expand Up @@ -189,6 +189,17 @@ try {
}
else {
$handler = New-Object System.Net.Http.HttpClientHandler
if ($customConfig.DeveloperServicesSSLEnabled -eq "true") {
$protocol = "https://"
}
else {
$protocol = "http://"
}
$sslVerificationDisabled = ($protocol -eq "https://")
if ($sslVerificationDisabled) {
Write-Host "Disabling SSL Verification"
$handler.ServerCertificateCustomValidationCallback = [SslVerification]::DisabledServerCertificateValidationCallback
}
if ($customConfig.ClientServicesCredentialType -eq "Windows") {
$handler.UseDefaultCredentials = $true
}
Expand All @@ -204,13 +215,6 @@ try {
}
$HttpClient.Timeout = [System.Threading.Timeout]::InfiniteTimeSpan
$HttpClient.DefaultRequestHeaders.ExpectContinue = $false

if ($customConfig.DeveloperServicesSSLEnabled -eq "true") {
$protocol = "https://"
}
else {
$protocol = "http://"
}

$ip = Get-BcContainerIpAddress -containerName $containerName
if ($ip) {
Expand All @@ -219,24 +223,6 @@ try {
else {
$devServerUrl = "$($protocol)$($containerName):$($customConfig.DeveloperServicesPort)/$($customConfig.ServerInstance)"
}

$sslVerificationDisabled = ($protocol -eq "https://")
if ($sslVerificationDisabled) {
if (-not ([System.Management.Automation.PSTypeName]"SslVerification").Type)
{
Add-Type -TypeDefinition "
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class SslVerification
{
private static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
public static void Disable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidationCallback; }
public static void Enable() { System.Net.ServicePointManager.ServerCertificateValidationCallback = null; }
}"
}
Write-Host "Disabling SSL Verification"
[SslVerification]::Disable()
}
}

$schemaUpdateMode = "synchronize"
Expand Down Expand Up @@ -289,8 +275,7 @@ try {
}

if ($sslverificationdisabled) {
Write-Host "Re-enablssing SSL Verification"
[SslVerification]::Enable()
Write-Host "Restoring SSL Verification" # no action required - only to enforce blocks consistency
}
if ($bcContainerHelperConfig.NoOfSecondsToSleepAfterPublishBcContainerApp -gt 0) {
# Avoid race condition
Expand Down

0 comments on commit 2d16653

Please sign in to comment.