Automatic process for AMS Certificate rebinding #261
Unanswered
antoine-dentan
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Lithnet Community.
In case it can help, I wrote a script that configures AMS so that the certificate used is the most recent one from the "Computer" store that matches the appropriate subject name.
The script lists the certificates in the store, selects the most recent one, binds to http.sys, and restarts the AMS service.
Added to a scheduled task, this script allows you to use Let's Encrypt certificates without having to reconfigure AMS every 3 months.
Hope this can help :)
Here is the code:
<#
.SYNOPSIS
Updates SSL certificate bindings in HTTP.SYS and restarts the LithnetAMS service.
.DESCRIPTION
This script retrieves SSL binding information from the Windows registry, compares the thumbprint of the current SSL certificate with the most recent certificate for a given subject, updates the SSL certificate binding if they differ, and restarts the LithnetAMS service.
.PARAMETER IPPort
The IP address and port of the SSL binding to update. Default is '0.0.0.0:443'.
.PARAMETER Subject
The subject name of the certificate to search for and update. Default is 'laps.adviseit.org'.
.EXAMPLE
.\Update-SSLCertificate.ps1
Updates the SSL certificate binding for the default IP port '0.0.0.0:443' and subject 'laps.adviseit.org'.
.EXAMPLE
.\Update-SSLCertificate.ps1 -IPPort '192.168.1.1:443' -Subject 'example.org'
Updates the SSL certificate binding for the specified IP port '192.168.1.1:443' and subject 'example.org'.
#>
[CmdletBinding()]
param (
[string]$IPPort = '0.0.0.0:443',
[string]$Subject = 'laps.adviseit.org'
)
function Get-SslBindingInfo {
<#
.SYNOPSIS
Retrieves SSL binding information from the Windows registry.
}
function Get-UpdatedCertificate {
<#
.SYNOPSIS
Queries the "computer" certificate store and retrieves the most recent certificate with the subject name matching the one passed as an argument.
}
try {
$CurrentCert = Get-SslBindingInfo | Where-Object {$_.IPPort -eq $IPPort}
$UpdatedCert = Get-UpdatedCertificate -Subject $Subject
} catch {
Write-Error "An error occurred while comparing or updating certificates: $_"
}
try {
Restart-Service LithnetAMS -ErrorAction Stop
} catch {
Write-Error "An error occurred while restarting the LithnetAMS service: $_"
}
Beta Was this translation helpful? Give feedback.
All reactions