Free ACME scripts / Windows
FortiWeb
Installs a simple-acme certificate on a FortiWeb server policy over REST v2.0.
- Version
- 1.7
- Language
- PowerShell
- SHA-256
- 48aff2d83ba49b154df5134c34d7c8cd6d7280246c064ad5bc07224295acf48d
- 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-FortiWeb.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/fortiweb-1.7.ps1' -OutFile 'C:\simple-acme\Scripts\Deploy-FortiWeb.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\Deploy-FortiWeb.ps1' -Algorithm SHA256).Hash -eq '48AFF2D83BA49B154DF5134C34D7C8CD6D7280246C064AD5BC07224295ACF48D'
Unblock-File 'C:\simple-acme\Scripts\Deploy-FortiWeb.ps1' What it does
simple-acme runs the script after each issuance. The script hands the job to a scheduled task named "FairSSL FortiWeb <id>", which runs as SYSTEM with no time limit; a run in a console window shows the first attempt, and the worker continues in the background. The job folder under C:\ProgramData\FairSSL\FortiWeb is open to SYSTEM and Administrators only. It holds worker.log and the password, 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 new certificate starts at once. Measured on FortiWeb-VM 8.0.8. Uploads leaf/key and intermediates, reusing stored certificates under any name. Uses an own intermediate group and reads every write back. The leaf and key become fssl-<6 hex of the name>-<12 hex of the leaf SHA-256>, or a local certificate with the same leaf is reused. Each missing intermediate is imported on its own and gets the device's name, such as Inter_Cert_1. The worker collects the intermediates in its group fssl-cag-<12 hex>, reuses a group with exactly the same members, and points the policy's intermediate-certificate-group at it. Roots and repeats are left out. The new and the previous certificate stay; only older unused own objects in this job's history are deleted. By default the policy's certificate and intermediate group are changed. With SniDomain the worker copies the policy's SNI group, changes only that member and selects the copy for this policy; other policies keep the original group. A regex SNI member and a member with several certificates are refused. Service TLS is advisory: the API decides success. After the API confirms, the worker looks at the certificate served on ServiceHost and ServicePort, or on the policy's single VIP; without a VIP it warns and skips the check. An unreachable service or another served leaf is a warning only. Refused: an expired certificate, one that becomes valid more than a day ahead, and keys other than RSA or EC. The password is sent as base64 administrator JSON in the Authorization header. Management SHA-256 is pinned before Authorization or PEM material is sent. Unexpected changes refuse MGMT_CERT_CHANGED. Pins are in C:\ProgramData\FairSSL\FortiWeb\<host hash>.pins.json. After a verified, intended change of the management certificate, delete that host's pin file. Each result and the worker's log go to the report address (-ReportUrl; FairSSL's control panel in FairSSL's download), with this script's file name, version and SHA-256, FortiWeb's model and version, the server's Windows and PowerShell version and the certificate's key type and SHA-256 fingerprint; a report the receiver has not confirmed waits in the outbox. Passwords, private keys and certificate PEM are never reported. Calls with only the old parameters use CredentialManager and default port 8443 as before. They upload the leaf only, take an optional IntermediateGroupName that the customer maintains, and print one line that recommends the new setup. Requires PowerShell 3.0+ and .NET Framework 4.5+. ASCII source.
Requirements
- Windows Server with Windows PowerShell 5.1, run as Administrator
- simple-acme, which runs the script after each issuance and renewal
Parameters
| -FortiWebHost | FortiWeb's management host name or IP address. |
|---|---|
| -Username | The FortiWeb administrator the script logs in as. |
| -SecretName | Name of the FortiWeb password in simple-acme's vault (wacs.exe: O, S, A); default fortiweb. The script reads the vault itself, so the password never reaches a command line. |
| -VaultFile | simple-acme secrets.json to read, only when different ACME servers hold different secrets under that name. |
| -Password | The administrator's password itself, instead of SecretName. simple-acme then keeps the password in its renewal settings and its log on the server, and in PowerShell each $ and backtick in it needs a backtick before it. |
| -ServerPolicyName | The server policy that gets the certificate. |
| -SniDomain | A plain SNI domain of the policy that gets the certificate instead of the policy's own certificate. |
| -ServiceHost | Address where the served certificate is looked at afterwards; default the policy's single VIP. |
| -ServicePort | Port for ServiceHost; default the port of the policy's HTTPS service. |
| -Vdom | Administrative domain the administrator logs in to, default root. |
| -IntermediateGroupName | Legacy calls only: an intermediate group the customer maintains. |
| -ManagementCertSha256 | Optional SHA-256 of the management leaf to pin before the first connection. |
| -Port | Management HTTPS port; 443 for the new setup. Legacy calls keep 8443. |
| -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. |
| -CredentialTarget | Legacy calls only: the Windows Credential Manager target that holds the login. |
| -UseHttp | Legacy calls only: talks to the appliance over http. |
| -ValidateManagementCertificate | Legacy calls only: checks the management certificate against Windows' trust store. |
| -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-FortiWeb.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-FortiWeb.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-FortiWeb.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-FortiWeb.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