mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Adds Cmdlets to enable/disable untrusted certificates for rest endpoints
This commit is contained in:
parent
d30970b3a9
commit
d62e566fea
2 changed files with 41 additions and 0 deletions
14
lib/web/Disable-IcingaUntrustedCertificateValidation.psm1
Normal file
14
lib/web/Disable-IcingaUntrustedCertificateValidation.psm1
Normal 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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
27
lib/web/Enable-IcingaUntrustedCertificateValidation.psm1
Normal file
27
lib/web/Enable-IcingaUntrustedCertificateValidation.psm1
Normal 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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue