Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD `SkipCertificateCheck` parameter. Enables SSL Validation to be skipped for the session. `Invoke-PASRestMethod` updated with separate flows for PWSH + PowerShell. PWSH uses the `SkipCertificateCheck` parameter present in `Invoke-WebRequest`. PowerShell uses code contained in `Skip-CertificateCheck.ps1`. Using SkipCertificateCheck parameter is not secure and is not recommended. Use at your own risk. Closes #196
- Loading branch information
Showing
3 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Function Skip-CertificateCheck { | ||
<# | ||
.SYNOPSIS | ||
Bypass SSL Validation | ||
.DESCRIPTION | ||
Enables skipping of ssl certificate validation for current PowerShell session. | ||
.EXAMPLE | ||
Skip-CertificateCheck | ||
#> | ||
|
||
#Only required to be executed once per ps session | ||
$Provider = New-Object Microsoft.CSharp.CSharpCodeProvider | ||
$Compiler = $Provider.CreateCompiler() | ||
$Params = New-Object System.CodeDom.Compiler.CompilerParameters | ||
$Params.GenerateExecutable = $false | ||
$Params.GenerateInMemory = $true | ||
$Params.IncludeDebugInformation = $false | ||
$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null | ||
$TASource = @' | ||
namespace Local.ToolkitExtensions.Net.CertificatePolicy | ||
{ | ||
public class TrustAll : System.Net.ICertificatePolicy | ||
{ | ||
public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
'@ | ||
|
||
$TAResults = $Provider.CompileAssemblyFromSource($Params, $TASource) | ||
$TAAssembly = $TAResults.CompiledAssembly | ||
## Create an instance of TrustAll and attach it to the ServicePointManager | ||
$TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll") | ||
[System.Net.ServicePointManager]::CertificatePolicy = $TrustAll | ||
} |