Free ACME scripts / Windows

Dynamics NAV

Deploys a simple-acme certificate to Microsoft Dynamics NAV / Business Central (on-premises) servers. Updates CustomSettings.config for every running BC instance (optionally filtered by name) and optionally restarts the affected instances.

Version
1.1
Language
PowerShell
SHA-256
9e7fae69353883948d2d3d2d82fda0a1347cc2147251a4566069400518a99249
Licence
Apache-2.0, copyright FairSSL A/S
Download dynamics-nav-1.1.ps1

Download it on the server, check the SHA-256 and keep it as C:\simple-acme\Scripts\ImportDynamicsNAV.ps1, so a newer version later replaces it without a change to your renewal:

PowerShell
# Windows PowerShell 5.1 needs TLS 1.2 switched on for this session
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -UseBasicParsing -Uri 'https://sslbrain.com/scripts/files/dynamics-nav-1.1.ps1' -OutFile 'C:\simple-acme\Scripts\ImportDynamicsNAV.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\ImportDynamicsNAV.ps1' -Algorithm SHA256).Hash -eq '9E7FAE69353883948D2D3D2D82FDA0A1347CC2147251A4566069400518A99249'
Unblock-File 'C:\simple-acme\Scripts\ImportDynamicsNAV.ps1'

What it does

simple-acme runs this script as its installation step, after it has put the certificate in Cert:\LocalMachine\My. The script finds every service named MicrosoftDynamicsNavServer$<instance>, and for each running instance (or only those named in -ServiceNames) writes the certificate's thumbprint to ServicesCertificateThumbprint in the instance's CustomSettings.config, reads the file back, and restarts the instance so it uses the new certificate.

An instance that already has the thumbprint is left alone and not restarted. An instance with an empty thumbprint and no *SSLEnabled key set to true runs without TLS and is left alone too. Before its first change the script copies each CustomSettings.config once to C:\simple-acme\fairssl-nav-backup.

The IIS binding of the Web Client is simple-acme's own step (--installation iis), not this script's. When an instance could not be updated the script ends with an error, so simple-acme reports the renewal as failed.

The settings at the top of the script choose whether instances are restarted, whether an instance without TLS gets the thumbprint anyway, and whether HTTP.sys bindings on the Business Central ports are refreshed.

Requires Windows PowerShell 3.0 or newer.

Requirements

  • Windows Server with Windows PowerShell 5.1, run as Administrator
  • simple-acme, which runs the script after each issuance and renewal

Parameters

-CertThumbprint SHA1 thumbprint of the certificate in Cert:\LocalMachine\My. simple-acme passes this in via --scriptparameters "'{CertThumbprint}'".
-ServiceNames Optional comma-separated list of BC instance names (the suffix after MicrosoftDynamicsNavServer$). When set, only the listed instances are touched - the same script can be reused across multiple wacs.exe runs on a host where each instance has its own hostname / certificate. Pass via --scriptparameters "'{CertThumbprint}' 'BC-PROD,BC-TEST'".

Get a certificate and run the script

Run simple-acme's wacs.exe from its folder (here C:\simple-acme) as Administrator. It orders the certificate, saves it in the Windows certificate store and as PEM files, runs the script, and creates the scheduled task that renews the certificate and runs the script again. Replace www.example.com, the e-mail address and the script's parameters (see Parameters; simple-acme fills in tokens such as {CertThumbprint}, {StorePath} and {RenewalId}). --validation selfhosting answers the CA's HTTP challenge on port 80; on a web server use --validation filesystem --webroot <site folder> instead.

Let's Encrypt

Directory: https://acme-v02.api.letsencrypt.org/directory. No account to create: the client registers one with your e-mail address. Let's Encrypt documentation

simple-acme
.\wacs.exe `
  --baseuri "https://acme-v02.api.letsencrypt.org/directory" `
  --accepttos --emailaddress "you@example.com" `
  --source manual --host "www.example.com" `
  --validation selfhosting `
  --store certificatestore,pemfiles --pemfilespath "C:\simple-acme\Certificates" `
  --installation script `
  --script ".\Scripts\ImportDynamicsNAV.ps1" `
  --scriptparameters "<parameters>"
Google Trust Services

Directory: https://dv.acme-v02.api.pki.goog/directory. Create an EAB key in a Google Cloud project (gcloud publicca external-account-keys create). Put the key's id and HMAC in place of EAB_KID and EAB_HMAC. Google Public CA tutorial

simple-acme
.\wacs.exe `
  --baseuri "https://dv.acme-v02.api.pki.goog/directory" `
  --eab-key-identifier "EAB_KID" --eab-key "EAB_HMAC" `
  --accepttos --emailaddress "you@example.com" `
  --source manual --host "www.example.com" `
  --validation selfhosting `
  --store certificatestore,pemfiles --pemfilespath "C:\simple-acme\Certificates" `
  --installation script `
  --script ".\Scripts\ImportDynamicsNAV.ps1" `
  --scriptparameters "<parameters>"
ZeroSSL

Directory: https://acme.zerossl.com/v2/DV90. Copy the EAB credentials from the Developer section of your ZeroSSL account. Put the key's id and HMAC in place of EAB_KID and EAB_HMAC. ZeroSSL ACME documentation

simple-acme
.\wacs.exe `
  --baseuri "https://acme.zerossl.com/v2/DV90" `
  --eab-key-identifier "EAB_KID" --eab-key "EAB_HMAC" `
  --accepttos --emailaddress "you@example.com" `
  --source manual --host "www.example.com" `
  --validation selfhosting `
  --store certificatestore,pemfiles --pemfilespath "C:\simple-acme\Certificates" `
  --installation script `
  --script ".\Scripts\ImportDynamicsNAV.ps1" `
  --scriptparameters "<parameters>"
acme.sslbrain.com

Directory: https://acme.sslbrain.com/acme/directory. Create an EAB key in sslbrain Cloud (Basic or higher) under ACME clients, Connect a client. sslbrain Cloud validates the domain through a CNAME redirect, a DNS API or pre-validation, not your ACME client. Put the key's id and HMAC in place of EAB_KID and EAB_HMAC. sslbrain plans

simple-acme
.\wacs.exe `
  --baseuri "https://acme.sslbrain.com/acme/directory" `
  --eab-key-identifier "EAB_KID" --eab-key "EAB_HMAC" `
  --accepttos --emailaddress "you@example.com" `
  --source manual --host "www.example.com" `
  --validation none `
  --store certificatestore,pemfiles --pemfilespath "C:\simple-acme\Certificates" `
  --installation script `
  --script ".\Scripts\ImportDynamicsNAV.ps1" `
  --scriptparameters "<parameters>"

Licence and credits

Copyright FairSSL A/S, licensed under the Apache License 2.0: use it, change it and share it, also commercially.

Runs in simple-acme (formerly win-acme), Apache-2.0.

One script per server, or sslbrain does it for all your servers without scripts.

See how sslbrain works

Feedback and improvements are welcome: info@fairssl.dk