-
Notifications
You must be signed in to change notification settings - Fork 378
Allow using custom Auth Certificate lifetime #2347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
61b2af2
202b3a8
eb0a22d
3b4b97f
7d13e5b
95318ed
3b16892
8e966c8
889a6f4
fa128d6
88de13b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||
| . $PSScriptRoot\..\DataCollection\Get-ExchangeServerCertificate.ps1 | ||||||||||||
| . $PSScriptRoot\..\..\..\Shared\ActiveDirectoryFunctions\Get-InternalTransportCertificateFromServer.ps1 | ||||||||||||
| . $PSScriptRoot\..\..\..\Shared\CertificateFunctions\Import-ExchangeCertificateFromRawData.ps1 | ||||||||||||
| . $PSScriptRoot\..\..\..\Shared\CertificateFunctions\New-ExchangeSelfSignedCertificate.ps1 | ||||||||||||
| . $PSScriptRoot\..\..\..\Shared\Invoke-CatchActionError.ps1 | ||||||||||||
|
|
||||||||||||
| function New-ExchangeAuthCertificate { | ||||||||||||
|
|
@@ -19,6 +20,11 @@ function New-ExchangeAuthCertificate { | |||||||||||
| [Parameter(Mandatory = $true, ParameterSetName = "NewNextAuthCert")] | ||||||||||||
| [int]$CurrentAuthCertificateLifetimeInDays, | ||||||||||||
|
|
||||||||||||
| [Parameter(Mandatory = $false, ParameterSetName = "NewPrimaryAuthCert")] | ||||||||||||
| [Parameter(Mandatory = $false, ParameterSetName = "NewNextAuthCert")] | ||||||||||||
| [ValidateScript({ $_ -ge 0 })] | ||||||||||||
| [int]$NewAuthCertificateLifetimeInDays, | ||||||||||||
|
|
||||||||||||
| [Parameter(Mandatory = $false, ParameterSetName = "NewPrimaryAuthCert")] | ||||||||||||
| [Parameter(Mandatory = $false, ParameterSetName = "NewNextAuthCert")] | ||||||||||||
| [ScriptBlock]$CatchActionFunction | ||||||||||||
|
|
@@ -100,6 +106,16 @@ function New-ExchangeAuthCertificate { | |||||||||||
| ErrorAction = "Stop" | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| $newCustomAuthCertificateParams = @{ | ||||||||||||
| AlgorithmType = "RSA" | ||||||||||||
| UseRSACryptoServiceProvider = $true # Make sure to set this to true as the certificate can't be used as Auth Certificate otherwise | ||||||||||||
| KeySize = 2048 | ||||||||||||
| LifetimeInDays = $NewAuthCertificateLifetimeInDays | ||||||||||||
| SubjectName = "Microsoft Exchange Server Auth Certificate" | ||||||||||||
| FriendlyName = $authCertificateFriendlyName | ||||||||||||
| DomainName = @() | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, $confirmationMessage, "Unattended Exchange certificate generation")) { | ||||||||||||
| Write-Verbose ("Internal transport certificate will be overwritten for a short time and then reset to the previous one") | ||||||||||||
| $internalTransportCertificate = Get-InternalTransportCertificateFromServer $env:COMPUTERNAME | ||||||||||||
|
|
@@ -187,7 +203,17 @@ function New-ExchangeAuthCertificate { | |||||||||||
| Write-Verbose ("Starting Auth Certificate creation process") | ||||||||||||
| try { | ||||||||||||
| if ($PSCmdlet.ShouldProcess("New-ExchangeCertificate", "Generate new Auth Certificate")) { | ||||||||||||
| $newAuthCertificate = New-ExchangeCertificate @newAuthCertificateParams | ||||||||||||
| if ($NewAuthCertificateLifetimeInDays -gt 0) { | ||||||||||||
| Write-Verbose "Creating a custom self-signed certificate with a lifetime of $NewAuthCertificateLifetimeInDays days" | ||||||||||||
| $newAuthCertificate = New-ExchangeSelfSignedCertificate @newCustomAuthCertificateParams | ||||||||||||
|
||||||||||||
| $newAuthCertificate = New-ExchangeSelfSignedCertificate @newCustomAuthCertificateParams | |
| $newAuthCertificate = New-ExchangeSelfSignedCertificate @newCustomAuthCertificateParams | |
| if ($null -eq $newAuthCertificate) { | |
| throw "Failed to create a new Auth Certificate. The certificate object is null." | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,11 @@ | |||||
| .PARAMETER ValidateAndRenewAuthCertificate | ||||||
| You can use this parameter to let the script perform the required Auth Certificate renewal actions. | ||||||
| If the script runs with this parameter set to $false, no action will be made to the current Auth Configuration. | ||||||
| .PARAMETER EnforceNewAuthCertificateCreation | ||||||
| You can use this switch parameter to let the script stage a new next Auth Certificate which will become automatically active within 24 hours. | ||||||
| .PARAMETER CustomCertificateLifetimeInDays | ||||||
| You can use this parameter to specify a custom lifetime for the newly created Auth certificate. | ||||||
| By default, the self-signed certificate is created with a lifetime of 5 years. | ||||||
|
||||||
| By default, the self-signed certificate is created with a lifetime of 5 years. | |
| By default (or when set to 0), the self-signed certificate is created with a lifetime of 5 years. |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation { $_ -ge 0 } allows 0 as a valid value for CustomCertificateLifetimeInDays. However, when this value is 0, the code at line 206 checks if ($NewAuthCertificateLifetimeInDays -gt 0), meaning a value of 0 will use the default certificate generation path. This creates ambiguity: should 0 mean "use default" or should it be rejected as invalid?
Consider either:
- Changing the validation to
{ $_ -gt 0 }if 0 is not a valid lifetime, or - Adding clearer documentation that
0means "use default 5-year lifetime".
| [ValidateScript({ $_ -ge 0 })] | |
| [ValidateScript({ $_ -gt 0 })] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
$NewAuthCertificateLifetimeInDaysparameter lacks a default value. When not explicitly provided by the caller, it will be$nullor0(depending on PowerShell's type coercion). This could lead to unexpected behavior. The parameter should have an explicit default value (e.g.,= 0) to make the API contract clear, especially since line 206 checksif ($NewAuthCertificateLifetimeInDays -gt 0)which suggests 0 or less means "use default".