Adds Cmdlets to enable/disable untrusted certificates for rest endpoints

This commit is contained in:
Christian Stein 2020-03-26 18:08:48 +01:00
parent d30970b3a9
commit d62e566fea
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,14 @@
function Disable-IcingaUntrustedCertificateValidation()
{
try {
[System.Net.ServicePointManager]::CertificatePolicy = $null;
Write-Host 'Successfully disabled untrusted certificate validation for this shell instance';
} catch {
Write-Host (
[string]::Format(
'Failed to disable untrusted certificate policy: {0}', $_.Exception.Message
)
);
}
}

View file

@ -0,0 +1,27 @@
function Enable-IcingaUntrustedCertificateValidation()
{
try {
# There is no other way as to use C# for this specific
# case to configure the certificate validation check
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class IcingaUntrustedCertificateValidation : ICertificatePolicy {
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object IcingaUntrustedCertificateValidation;
Write-Host 'Successfully enabled untrusted certificate validation for this shell instance';
} catch {
Write-Host (
[string]::Format(
'Failed to enable untrusted certificate policy: {0}', $_.Exception.Message
)
);
}
}