Skip to content

Commit e25774b

Browse files
authored
Merge pull request #2515 from microsoft/lusassl-06032026-1
Improve certificate renewal workflow in deserialization failure scenario
2 parents 152baf6 + e1a1600 commit e25774b

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Admin/MonitorExchangeAuthCertificate/ConfigurationAction/New-ExchangeAuthCertificate.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,14 @@ function New-ExchangeAuthCertificate {
209209
} else {
210210
Write-Verbose "Creating a default self-signed certificate with a lifetime of 5 years"
211211
$certObject = New-ExchangeCertificate @newAuthCertificateParams
212+
212213
$newAuthCertificate = [PSCustomObject]@{
213214
Thumbprint = $certObject.Thumbprint
214215
Subject = $certObject.Subject
216+
RawData = $certObject.RawData # We need to include RawData in case the deserialization of the cert object fails
215217
}
216218
}
219+
Write-Verbose "Certificate with thumbprint: $($newAuthCertificate.Thumbprint) was generated"
217220
Start-Sleep -Seconds 5
218221
} else {
219222
$newAuthCertificateParams.GetEnumerator() | ForEach-Object {
@@ -240,7 +243,7 @@ function New-ExchangeAuthCertificate {
240243

241244
if ($null -ne $newAuthCertificate) {
242245
$operationSuccessful = $true
243-
if ($null -ne $newAuthCertificate.Thumbprint) {
246+
if (-not([System.String]::IsNullOrWhiteSpace($newAuthCertificate.Thumbprint))) {
244247
Write-Verbose ("Certificate object successfully deserialized")
245248
[string]$newAuthCertificateThumbprint = $newAuthCertificate.Thumbprint
246249
} else {

Shared/CertificateFunctions/Import-ExchangeCertificateFromRawData.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ function Import-ExchangeCertificateFromRawData {
2222
Write-Verbose ("Going to process '$($ExchangeCertificates.Count )' Exchange certificates")
2323

2424
foreach ($c in $ExchangeCertificates) {
25+
if ($null -eq $c.RawData) {
26+
Write-Verbose "Skipping certificate because RawData is null"
27+
continue
28+
}
29+
2530
# Initialize X509Certificate2 class
2631
$certObject = New-Object 'System.Security.Cryptography.X509Certificates.X509Certificate2'
2732
# Use the Import() method to import byte[] RawData

0 commit comments

Comments
 (0)