-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #725 from Icinga:fix/rework_certificate_handling_t…
…o_fix_systemside_compatibility Fix: Certificate handling to provide systemwide compatibility Fixes Icinga for Windows certificate handling by keeping the .pfx file on the system as created, without using the certificate store. Also fixes handling for providing thumbprints for certificates, which are now loaded directly from the certificate store by also providing a new filter mechanic to fetch the proper certificates from the store
- Loading branch information
Showing
15 changed files
with
178 additions
and
59 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+124 KB
doc/images/04_knowledgebase/IWKB000018/04_set_permission_and_apply.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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 |
---|---|---|
@@ -1,11 +1,65 @@ | ||
function Get-IcingaForWindowsCertificate() | ||
{ | ||
[string]$CertificateFolder = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'certificate'; | ||
[string]$CertificateFile = Join-Path -Path $CertificateFolder -ChildPath 'icingaforwindows.pfx'; | ||
[string]$CertThumbprint = $null; | ||
[PSCustomObject]$CertFilter = $null; | ||
[Security.Cryptography.X509Certificates.X509Certificate2]$Certificate = $null; | ||
|
||
if (-Not (Test-Path $CertificateFile)) { | ||
return $null; | ||
if ($Global:Icinga.Public.ContainsKey('SSL')) { | ||
$CertThumbprint = $Global:Icinga.Public.SSL.CertThumbprint; | ||
$CertFilter = $Global:Icinga.Public.SSL.CertFilter; | ||
} | ||
|
||
return ([Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile($CertificateFile)); | ||
if ([string]::IsNullOrEmpty($CertThumbprint) -eq $FALSE -Or $null -ne $CertFilter) { | ||
[hashtable]$FilterArgs = @{ | ||
'-Recurse' = $TRUE; | ||
'-Path' = 'cert:\LocalMachine\*'; | ||
} | ||
|
||
if ([string]::IsNullOrEmpty($CertThumbprint) -eq $FALSE) { | ||
$FilterArgs.Add('-Include', $CertThumbprint); | ||
} | ||
|
||
[array]$Certificates = Get-ChildItem @FilterArgs; | ||
[DateTime]$CurrentTime = [DateTime]::Now; | ||
|
||
foreach ($cert in $Certificates) { | ||
if ((Test-PSCustomObjectMember -PSObject $CertFilter -Name 'Subject') -And [string]::IsNullOrEmpty($CertFilter.Subject) -eq $FALSE) { | ||
if ($cert.Subject.ToLower() -NotLike $CertFilter.Subject.ToLower()) { | ||
continue; | ||
} | ||
} | ||
|
||
if ((Test-PSCustomObjectMember -PSObject $CertFilter -Name 'Issuer') -And [string]::IsNullOrEmpty($CertFilter.Issuer) -eq $FALSE) { | ||
if ($cert.Issuer.ToLower() -NotLike $CertFilter.Issuer.ToLower()) { | ||
continue; | ||
} | ||
} | ||
|
||
# Certificate expiration date | ||
if ($cert.NotAfter -lt $CurrentTime) { | ||
continue; | ||
} | ||
|
||
# Certificate start date | ||
if ($cert.NotBefore -gt $CurrentTime) { | ||
continue; | ||
} | ||
|
||
$Certificate = $cert; | ||
break; | ||
} | ||
} else { | ||
[string]$CertificateFolder = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'certificate'; | ||
[string]$CertificateFile = Join-Path -Path $CertificateFolder -ChildPath 'icingaforwindows.pfx'; | ||
|
||
if (-Not (Test-Path $CertificateFile)) { | ||
return $null; | ||
} | ||
|
||
$Certificate = ( | ||
New-Object Security.Cryptography.X509Certificates.X509Certificate2 $CertificateFile, '', ([System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet) | ||
); | ||
} | ||
|
||
return $Certificate; | ||
} |
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