Fix loading certificate from .pfx file

If you tried this
 Use-Icinga; Get-IcingaSSLCertForSocket -CertFile "C:/my/cert.pfx"

the former code expanded like
 $FileType = Get-Item -Path "C:/my/cert.pfx";
 if ("cert.pfx" -eq '.pfx') { ... not reached ... }

and thus did not load the certificate file.

Now use GetExtension instead of Get-Item to make the .pfx check work.
This commit is contained in:
Tobias Deiminger 2021-05-10 09:17:46 +02:00
parent 5f3d08ba84
commit 91e37ea16c

View file

@ -10,8 +10,7 @@ function Get-IcingaSSLCertForSocket()
# to get a proper certificate # to get a proper certificate
if ([string]::IsNullOrEmpty($CertFile) -eq $FALSE) { if ([string]::IsNullOrEmpty($CertFile) -eq $FALSE) {
if ((Test-Path $CertFile)) { if ((Test-Path $CertFile)) {
$FileType = Get-Item -Path $CertFile; if ([IO.Path]::GetExtension($CertFile) -eq '.pfx') {
if ($FileType -eq '.pfx') {
return (New-Object Security.Cryptography.X509Certificates.X509Certificate2 $CertFile); return (New-Object Security.Cryptography.X509Certificates.X509Certificate2 $CertFile);
} else { } else {
return ConvertTo-IcingaX509Certificate -CertFile $CertFile; return ConvertTo-IcingaX509Certificate -CertFile $CertFile;