certify icon indicating copy to clipboard operation
certify copied to clipboard

IIS loses cert binding on renewal

Open dgbillotte opened this issue 8 years ago • 5 comments

I want to give some props first. I've been playing with letsencrypt since pretty early on and I really love the Certify interface for Windows. I've always been able to get letsencrypt to work, but it always took some effort. With Certify, it just works.

I have a Windows server (server 2016 with IIS 10.0) that has one IP with two subdomains mapped to the same IP. There are certs created for both subdomains and the setup on both was easy. HTTPS works great for both subdomains. The problem comes when a cert renewal happens. I'll get a report (from a user) that the "website is down", go into the bindings setting in IIS and see that the SSL cert selection dropdown is empty. If I select the new (renewed) cert and hit "OK", everything works. I'm currently working on a PS script to hook into the the Post-request hook that will re-associate the renewed cert with the binding, but I'm guessing that the intention was for that to happen automagically.

The site in question has these config options in the Certify UI: Options:

  • Enable Auto Renewal (checked) Advanced:
  • Challenge-Type: http-01
  • Perform challenge response config checks (checked)
  • perform web application auto-config (checked)
  • Auto create/update IIS bindings (uses SNI) checked

One thing that might be causing a problem is: I have two IIS servers running on this given subdomain. One uses the default port (443) while the other one uses an alternate port for SSL.

dgbillotte avatar Mar 06 '18 17:03 dgbillotte

Hi, thanks for the great feedback!

You mentioned that you have two IIS servers, do you mean you have one IIS server running two websites?

So you are running two sites with the same domain name but different ports (like www.example.com:443 and www.example.com:8443 ?) - interestingly I don't think you can do this currently with the app as we just update the first matching https binding (https://github.com/webprofusion/certify/blob/507b0256a2e014bd0aec5b02a04de84cc28b939c/src/Certify.Core/Management/Servers/ServerProviderIIS.cs#L753) , but as you say Post-Request script will do what you need (use the certificate thumbprint hash), let me know if you need help with that. I think it would be cool for us to support this behaviour with the next release (update all https bindings, not just the first match).

webprofusion-chrisc avatar Mar 07 '18 02:03 webprofusion-chrisc

Hi Chris,

Thank you for the reply. I can knock out the power-shell script, but if you know of one that is ready to go, I've love to start with that. Otherwise I'll be happy to share the one I come up with you.

cheers, Daniel

On Tue, Mar 6, 2018 at 7:52 PM, Christopher Cook [email protected] wrote:

Hi, thanks for the great feedback!

You mentioned that you have two IIS servers, do you mean you have one IIS server running two websites?

So you are running two sites with the same domain name but different ports (like www.example.com:443 and www.example.com:8443 ?) - interestingly I don't think you can do this currently with the app as we just update the first matching https binding (https://github.com/ webprofusion/certify/blob/507b0256a2e014bd0aec5b02a04de8 4cc28b939c/src/Certify.Core/Management/Servers/ServerProviderIIS.cs#L753) , but as you say Post-Request script will do what you need (use the certificate thumbprint hash), let me know if you need help with that. I think it would be cool for us to support this behaviour with the next release (update all https bindings, not just the first match).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/webprofusion/certify/issues/266#issuecomment-371004987, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeDhDSvYrJMRSPkD3eb4f6_g3yj15Zrks5tb0tUgaJpZM4SfGaC .

dgbillotte avatar Mar 07 '18 16:03 dgbillotte

I was going to write this so that it grabbed all https sites for the given domain and updated all of them, but our use case didn't require that level of completeness for now, so I just hardcoded the site name and port-num at the top.

param($result)

$website_name = 'site-name'
$website_port = 4433

If($result.IsSuccess) {

    # this is the path to the 64 bit version of powershell
    $ps = "$env:windir\sysnative\WindowsPowerShell\v1.0\powershell.exe"
    set-alias ps64 $ps


    # the commands must be run in this subshell because it seems that 
    # CertifyTheWeb uses the 32-bit version of powershell which throws
    # errors on the call to Get-WebBinding (and presumably AddSslCertificate as well)
    ps64 -args $result, $website_name, $website_port -command {
        $result = $args[0]
        $name = $args[1]
        $port = $args[2]

        # Write-Output 'second arg: ' $args[1]

        Import-Module WebAdministration

        $certHash = $result.ManagedItem.CertificateThumbprintHash
        Write-Output 'certHash is' $certHash

        Write-Output 'getting the binding'
        $binding = Get-WebBinding -Name $name -Port $port

        Write-Output $binding
        $binding.AddSslCertificate($certHash, 'my')

    }
}

dgbillotte avatar Mar 07 '18 22:03 dgbillotte

Nice work! Thanks for sharing.

webprofusion-chrisc avatar Mar 07 '18 23:03 webprofusion-chrisc

Closing. Multiple https bindings on the same site is fixed in the upcoming v4.x version.

webprofusion-chrisc avatar Mar 14 '18 00:03 webprofusion-chrisc