Skip to content

Commit 772a681

Browse files
authored
Fixed issue where multiple AzureStackCertificationAuthority certs reside on host (#506)
# Description This pull request makes a targeted improvement to the `New-SdnServerCertificate` function by ensuring that, when multiple matching certificates are found in the root store, only the most recent one is selected. This change improves the reliability and correctness of certificate selection. - Certificate selection logic: * In `New-SdnServerCertificate` (`src/modules/SdnDiag.Server.psm1`), after retrieving certificates that match the issuer, the code now sorts them by the `NotBefore` property in descending order and selects the most recent certificate. # Change type - [x] Bug fix (non-breaking change) - [ ] Code style update (formatting, local variables) - [ ] New Feature (non-breaking change that adds new functionality without impacting existing) - [ ] Breaking change (fix or feature that may cause functionality impact) - [ ] Other # Checklist: - [x] My code follows the style and contribution guidelines of this project. - [x] I have tested and validated my code changes.
1 parent 32bf9ef commit 772a681

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/modules/SdnDiag.Server.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,9 @@ function New-SdnServerCertificate {
27062706

27072707
# locate the AzureStackCertificationAuthority certificate within the root store
27082708
$certificate = Get-SdnCertificate -Path "Cert:\LocalMachine\Root" -Subject $newestCertificate.Issuer
2709+
if ($certificate) {
2710+
$certificate = $certificate | Sort-Object -Property NotBefore -Descending | Select-Object -First 1
2711+
}
27092712
}
27102713
}
27112714
}

0 commit comments

Comments
 (0)