Free ACME scripts / Windows
FortiManager
Installs a simple-acme certificate as FortiManager's own admin HTTPS certificate over JSON-RPC.
- Version
- 1.8
- Language
- PowerShell
- SHA-256
- 6e37ccd85a1054e9b28fa6f2b37dc63f2ce84bdb311c7b7f358204d41668d9e1
- Licence
- Apache-2.0, copyright FairSSL A/S
Download it on the server, check the SHA-256 and keep it as C:\simple-acme\Scripts\Deploy-FortiManager.ps1, so a newer version later replaces it without a change to your renewal:
# 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/fortimanager-1.8.ps1' -OutFile 'C:\simple-acme\Scripts\Deploy-FortiManager.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\Deploy-FortiManager.ps1' -Algorithm SHA256).Hash -eq '6E37CCD85A1054E9B28FA6F2B37DC63F2CE84BDB311C7B7F358204D41668D9E1'
Unblock-File 'C:\simple-acme\Scripts\Deploy-FortiManager.ps1' What it does
simple-acme runs the script after each issuance. The script hands the job to a scheduled task named "FairSSL FortiManager <id>", which runs as SYSTEM with no time limit, and returns at once; a run in a console window shows the first attempt. The job folder under C:\ProgramData\FairSSL\FortiManager is open to SYSTEM and Administrators only. It holds worker.log and the API key, encrypted with DPAPI LocalMachine. A failed attempt is tried again after 1, 2, 5, 10 and 30 minutes and then every hour until it succeeds, also after Windows restarts. A rollback waits a day; a newer certificate starts at once. POST /jsonrpc uses a REST API administrator's Bearer API key (FortiManager 7.2.2+). Local objects are fssl-<id6>-<fp12>, uploaded with the intermediates in the CA's order. The worker reuses the same leaf, changes admin_server_cert and reads it back; the setting read back decides. HTTPS that still serves the previous leaf is noted, and both leaves stay pinned until it serves the new one. When HTTPS stops answering after the switch, the worker puts the previous admin_server_cert back; that needs the API to answer. Intermediates are reused or imported in the CA store, from which FortiManager serves the chain. Switching restarts HTTPS and can drop the API response: on FortiManager 8.0.2 the switch restarted HTTPS at once and cut the answer to the update, and the setting was confirmed by reading it again. Only older own objects in this job's history are deleted; new and previous stay. Refused: an expired certificate, one that becomes valid more than a day ahead, and keys other than RSA or EC. The first management certificate SHA-256 is kept machine-wide. A changed pin is refused as MGMT_CERT_CHANGED, before the API key is sent. An intentional switch accepts old and new pins until verified, then keeps the new one, including across worker restarts. Pins are in C:\ProgramData\FairSSL\FortiManager\<host hash>.pins.json. After a verified change of the management certificate made outside this script, delete that host's pin file. Each result and the worker's log of the attempt go to the report address (-ReportUrl; FairSSL's control panel in FairSSL's download); a report the receiver has not confirmed waits in the outbox. Reports contain certificate metadata, this worker's log, this script's file name, version and SHA-256, FortiManager's model and version and the server's Windows and PowerShell version, never key material or the API key. Requires PowerShell 3.0+ and .NET Framework 4.5+.
Requirements
- Windows Server with Windows PowerShell 5.1, run as Administrator
- simple-acme, which runs the script after each issuance and renewal
Parameters
| -FortiManagerHost | FortiManager's host name or IP address. |
|---|---|
| -SecretName | Name of the API key in simple-acme's vault (wacs.exe: O, S, A); default fortimanager. The script reads the vault itself, so the key never reaches a command line. |
| -VaultFile | simple-acme secrets.json to read, only when different ACME servers hold different secrets under that name. |
| -ApiKey | The API key itself, instead of SecretName. simple-acme then keeps the key in its renewal settings and its log on the server, and in PowerShell each $ and backtick in the key needs a backtick before it. |
| -ManagementCertSha256 | Optional SHA-256 of the management leaf to pin before the first connection. |
| -Port | FortiManager management HTTPS port, default 443. |
| -StorePath | Folder where simple-acme stores PEM files. |
| -FilePrefix | PEM filename prefix configured in simple-acme. |
| -CertName | Name of this certificate in the object names on the appliance. Defaults to FilePrefix. |
| -RenewalId | simple-acme's {RenewalId}, used in the reports. Left out, the script finds the renewal itself. |
| -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. |
| -Worker | Used by the script itself: runs the background worker for -JobFolder. |
| -JobFolder | Used by the script itself: the worker's job folder. |
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
.\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\Deploy-FortiManager.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
.\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\Deploy-FortiManager.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
.\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\Deploy-FortiManager.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
.\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\Deploy-FortiManager.ps1" `
--scriptparameters "<parameters>" 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.
Feedback and improvements are welcome: info@fairssl.dk