Free ACME scripts / Windows

Result notification

Reports the result of each simple-acme run (the certificate order and its installation) to a report address: in FairSSL's download your FairSSL control panel, so you can see status, installation errors and expiry for every server in one place and be alerted when a renewal or an installation fails.

Version
3.9
Language
PowerShell
SHA-256
3fb28b63d7b8521d658c0900716cbe20704729da029b2cba82f7b6fd8a7fb8b8
Licence
Apache-2.0, copyright FairSSL A/S
Download result-notification-3.9.ps1

Download it on the server, check the SHA-256 and keep it as C:\simple-acme\Scripts\FairSSLResultNotification.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/result-notification-3.9.ps1' -OutFile 'C:\simple-acme\Scripts\FairSSLResultNotification.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\FairSSLResultNotification.ps1' -Algorithm SHA256).Hash -eq '3FB28B63D7B8521D658C0900716CBE20704729DA029B2CBA82F7B6FD8A7FB8B8'
Unblock-File 'C:\simple-acme\Scripts\FairSSLResultNotification.ps1'

What it does

simple-acme runs this script as its notification script (Notification.Script in settings_default.json) after it has saved the result of the run: after the first issuance, after every renewal and after a failed renewal. It reads the renewal's own result from the renewal file and the account's ACME URL from the account registration file, then POSTs a short JSON summary to the report address (-ReportUrl; FairSSL's control panel in FairSSL's download).

An installation step that fails (for example an installation script that ends with exit 1) is reported as an installation failure with simple-acme's first error message, even though simple-acme itself keeps the certificate. For a renewal installed by Deploy-FortiGate.ps1, Deploy-FortiMail.ps1, Deploy-PaloAlto.ps1, Deploy-FortiADC.ps1, Deploy-FortiManager.ps1, Deploy-FortiNAC.ps1 or Deploy-FortiWeb.ps1 (except its older path, which has none of the current parameters such as -Username) a successful run is reported without an installation result: that script's background worker reports the installation on the appliance itself.

The script never fails or holds up a renewal: it makes one attempt, always ends with exit code 0 and writes one line to the simple-acme log saying whether the receiver confirmed the report. A report the receiver has not confirmed (answer ok=true) waits as a file in the FairSSL-pending folder beside the renewal files, and a background copy of this script sends it again after 1, 5 and 15 minutes and then every hour, for as long as it takes. After a restart of the server the next run of this script (the next renewal simple-acme processes) picks the folder up again. Only one copy sends from the folder at a time, and a report is deleted only after the receiver has confirmed it. Compatible with Windows PowerShell 4/5.1 and PowerShell 7+.

Requirements

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

Parameters

-RenewalId The renewal's identifier, from simple-acme's {RenewalId} token.
-EventType simple-acme's {EventType} token: created, success, success-with-errors, failure, cancel or test.
-ReportUrl Where each result is reported: an https address. Leave it out: the address in $DefaultReportUrl below is used. FairSSL's download has FairSSL's address there; in the script library it is empty, and then nothing is sent. -CallbackUrl is the earlier name of this parameter and still works.
-Deliver Used by the script itself: send the reports waiting in -SpoolFolder until the receiver has confirmed each of them.
-SpoolFolder Used by the script itself with -Deliver: the folder with the waiting reports.

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.

simple-acme runs this script after every run, not as an installation step. Name it under Notification in settings.json in the simple-acme folder:

settings.json
{
  "Notification": {
    "Script": {
      "Path": "Scripts\\FairSSLResultNotification.ps1",
      "Parameters": "-RenewalId '{RenewalId}' -EventType '{EventType}'",
      "NotifyOnSuccess": true
    }
  }
}
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
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
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
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

Report each result to your own receiver

The script can send the result of every installation to an HTTPS address of yours, so one place shows the status, errors and expiry of all your servers. It sends nothing until you give it the address: pass -ReportUrl 'https://reports.example.com/acme' or set the report address in the variable at the top of the script.

Each report is a JSON POST; your receiver answers {"ok": true}, and a report without that answer is kept and sent again. The fields are in the report format.

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