Use INF CNs as primary hosts and SANs separately
This commit is contained in:
33
certy.ps1
33
certy.ps1
@@ -269,19 +269,10 @@ function Get-InfRequestFromLines {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hosts = New-Object System.Collections.Generic.List[string]
|
|
||||||
if ($commonName) {
|
|
||||||
$hosts.Add($commonName)
|
|
||||||
}
|
|
||||||
foreach ($san in $sans) {
|
|
||||||
if ($commonName -and $san.Equals($commonName, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
|
|
||||||
$hosts.Add($san)
|
|
||||||
}
|
|
||||||
|
|
||||||
return [pscustomobject]@{
|
return [pscustomobject]@{
|
||||||
CommonName = $commonName
|
CommonName = $commonName
|
||||||
Sans = $sans
|
Sans = $sans
|
||||||
Hosts = $hosts
|
Hosts = @($commonName) | Where-Object { $_ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1514,10 +1505,11 @@ $infImportBtn.Add_Click({
|
|||||||
Hosts = $hosts
|
Hosts = $hosts
|
||||||
CommonName = $reqData.CommonName
|
CommonName = $reqData.CommonName
|
||||||
Sans = @($reqData.Sans)
|
Sans = @($reqData.Sans)
|
||||||
|
CertHosts = @(@($reqData.CommonName) + @($reqData.Sans) | Where-Object { $_ } | Sort-Object -Unique)
|
||||||
Sanitized = $sanitizedPath
|
Sanitized = $sanitizedPath
|
||||||
CsrInf = $csrInfPath
|
CsrInf = $csrInfPath
|
||||||
}
|
}
|
||||||
$infHosts += $hosts
|
if ($reqData.CommonName) { $infHosts += $reqData.CommonName }
|
||||||
$script:infSans += @($reqData.Sans)
|
$script:infSans += @($reqData.Sans)
|
||||||
if ($reqData.CommonName) {
|
if ($reqData.CommonName) {
|
||||||
$sanList = if (@($reqData.Sans).Count -gt 0) { (@($reqData.Sans) -join ", ") } else { "none" }
|
$sanList = if (@($reqData.Sans).Count -gt 0) { (@($reqData.Sans) -join ", ") } else { "none" }
|
||||||
@@ -1532,6 +1524,9 @@ $infImportBtn.Add_Click({
|
|||||||
$merged = Merge-Hostnames -Existing $currentHosts -NewItems $infHosts
|
$merged = Merge-Hostnames -Existing $currentHosts -NewItems $infHosts
|
||||||
$hostsBox.Text = ($merged -join [Environment]::NewLine)
|
$hostsBox.Text = ($merged -join [Environment]::NewLine)
|
||||||
}
|
}
|
||||||
|
if ($infHosts.Count -gt 0) {
|
||||||
|
& $logAction "INF CNs loaded into Hostnames. SANs listed separately."
|
||||||
|
}
|
||||||
if ($script:infSans.Count -gt 0) {
|
if ($script:infSans.Count -gt 0) {
|
||||||
$infSanBox.Text = ($script:infSans -join [Environment]::NewLine)
|
$infSanBox.Text = ($script:infSans -join [Environment]::NewLine)
|
||||||
} else {
|
} else {
|
||||||
@@ -1681,7 +1676,15 @@ $runBtn.Add_Click({
|
|||||||
$hosts += $fileHosts
|
$hosts += $fileHosts
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($hosts.Count -eq 0) { throw "No hostnames provided." }
|
$infDnsHosts = @()
|
||||||
|
if ($script:infRequests -and $script:infRequests.Count -gt 0) {
|
||||||
|
foreach ($req in $script:infRequests) {
|
||||||
|
$infDnsHosts += @($req.CertHosts)
|
||||||
|
}
|
||||||
|
$infDnsHosts = @($infDnsHosts | Where-Object { $_ } | Sort-Object -Unique)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hosts.Count -eq 0 -and $infDnsHosts.Count -eq 0) { throw "No hostnames provided." }
|
||||||
$zone = $zoneBox.Text.Trim()
|
$zone = $zoneBox.Text.Trim()
|
||||||
if (-not $zone) { throw "Default DNS zone is required." }
|
if (-not $zone) { throw "Default DNS zone is required." }
|
||||||
|
|
||||||
@@ -1703,7 +1706,8 @@ $runBtn.Add_Click({
|
|||||||
throw "PFX password is required."
|
throw "PFX password is required."
|
||||||
}
|
}
|
||||||
|
|
||||||
$hostEntries = @($hosts | ForEach-Object { Resolve-HostEntry -Name $_ -Zone $zone -UseProvidedFqdn $useFqdnBox.Checked } | Where-Object { $_ })
|
$dnsHostInputs = if ($infDnsHosts.Count -gt 0) { $infDnsHosts } else { $hosts }
|
||||||
|
$hostEntries = @($dnsHostInputs | ForEach-Object { Resolve-HostEntry -Name $_ -Zone $zone -UseProvidedFqdn $useFqdnBox.Checked } | Where-Object { $_ })
|
||||||
|
|
||||||
& $logAction "Processing $($hostEntries.Count) hostname(s)."
|
& $logAction "Processing $($hostEntries.Count) hostname(s)."
|
||||||
|
|
||||||
@@ -1788,7 +1792,8 @@ $runBtn.Add_Click({
|
|||||||
if ($script:infRequests -and $script:infRequests.Count -gt 0) {
|
if ($script:infRequests -and $script:infRequests.Count -gt 0) {
|
||||||
& $logAction "INF requests detected; issuing one certificate per INF file."
|
& $logAction "INF requests detected; issuing one certificate per INF file."
|
||||||
foreach ($req in $script:infRequests) {
|
foreach ($req in $script:infRequests) {
|
||||||
$reqEntries = @($req.Hosts | ForEach-Object { Resolve-HostEntry -Name $_ -Zone $zone -UseProvidedFqdn $useFqdnBox.Checked } | Where-Object { $_ })
|
$reqHostInputs = @($req.CertHosts)
|
||||||
|
$reqEntries = @($reqHostInputs | ForEach-Object { Resolve-HostEntry -Name $_ -Zone $zone -UseProvidedFqdn $useFqdnBox.Checked } | Where-Object { $_ })
|
||||||
$reqFqdns = @($reqEntries | ForEach-Object { $_.Fqdn } | Where-Object { $_ })
|
$reqFqdns = @($reqEntries | ForEach-Object { $_.Fqdn } | Where-Object { $_ })
|
||||||
if ($reqFqdns.Count -eq 0) {
|
if ($reqFqdns.Count -eq 0) {
|
||||||
& $logAction "INF $([System.IO.Path]::GetFileName($req.File)) skipped (no hosts)."
|
& $logAction "INF $([System.IO.Path]::GetFileName($req.File)) skipped (no hosts)."
|
||||||
|
|||||||
Reference in New Issue
Block a user