Free ACME scripts / Windows

Windows Custom

Template deployment script for custom Windows services.

Version
1.2
Language
PowerShell
SHA-256
bfb1e397e3b90e905578ef239b3555384c42e247e95e765b7bac5b92326a0cde
Licence
Apache-2.0, copyright FairSSL A/S
Download windows-custom-1.2.ps1

Download it on the server, check the SHA-256 and keep it as C:\simple-acme\Scripts\ImportCustomWindows.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/windows-custom-1.2.ps1' -OutFile 'C:\simple-acme\Scripts\ImportCustomWindows.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\ImportCustomWindows.ps1' -Algorithm SHA256).Hash -eq 'BFB1E397E3B90E905578EF239B3555384C42E247E95E765B7BAC5B92326A0CDE'
Unblock-File 'C:\simple-acme\Scripts\ImportCustomWindows.ps1'

What it does

Use this as a Simple-ACME installation script after storing the issued certificate in the Windows certificate store, as a PFX file, and as PEM files. Edit the configuration block before first use.

The script intentionally contains examples instead of product-specific logic. Keep the actions your service needs and remove the rest.

What it does, in order:

1. Prints a command that runs the script again with the same certificate. After editing the script, run that command from the simple-acme folder: it uses the files simple-acme has already stored and requests no new certificate. 2. Copies the PEM files (certificate, private key, chain) and the PFX file from the simple-acme output folder to $DestinationFolder, under the file names set in the configuration block. $CopyPemFiles and $CopyPfxFile turn each copy off. 3. With $ConvertToJks = $true, builds a Java keystore from the exported PFX (see below). 4. Restarts the service $ServiceName when $RestartService is $true.

Near the end of the script is a commented-out example that writes the copied file paths into an application's JSON configuration file. Uncomment and adapt it when your application needs that.

Java keystore (JKS). For an application that reads a Java keystore, for example Cryptshare or another Java service. keytool reads the exported PFX with $PfxPassword, so it must be the --pfxpassword value of the wacs.exe command. The Java application that reads the keystore already has keytool.exe in its JDK or JRE bin folder (for example F:\Java\jdk-25\bin\keytool.exe): set $KeytoolPath to it, or leave it empty to find keytool through JAVA_HOME or PATH. Only a server without Java needs a JDK, for example the Microsoft Build of OpenJDK (about 200 MB, https://learn.microsoft.com/en-us/java/openjdk/download). With $RecreateJks = $true (the default) the file at $JksFilePath is deleted and built again from the PFX at every renewal, so it must be a keystore that holds only this certificate. Cryptshare example: $JksAlias 'com.cryptshare.server', $JksFilePath ending in \lib\security\keystore, the same value in $JksStorePassword and $JksKeyPassword, and $RestartService = $true with the Cryptshare service in $ServiceName.

The wacs.exe command in the ACME Easy guide stores the certificate as PEM files, as a PFX file and in Cert:\LocalMachine\My before this script runs, and simple-acme replaces {CertThumbprint} with the thumbprint. A PFX password of letters and digits only needs no quoting on the command line. --acl-read on that command gives a service account access to the private key in the certificate store only; an application that reads the copied files needs permission to $DestinationFolder as well.

Requirements

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

Parameters

-CertThumbprint Thumbprint of the newly issued certificate.
-StorePath PEM and PFX output base folder from Simple-ACME.
-FilePrefix PEM/PFX filename prefix used when the renewal was created.

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\ImportCustomWindows.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\ImportCustomWindows.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\ImportCustomWindows.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\ImportCustomWindows.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