Free ACME scripts / Windows
FortiADC
Installs a simple-acme certificate on a FortiADC virtual server through its client SSL profile over REST.
- Version
- 1.9
- Language
- PowerShell
- SHA-256
- f9296a552e8aa53998177b67fc4eaf8f77decfaed82e1b7c02d36fb120517fa0
- 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-FortiADC.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/fortiadc-1.9.ps1' -OutFile 'C:\simple-acme\Scripts\Deploy-FortiADC.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\Deploy-FortiADC.ps1' -Algorithm SHA256).Hash -eq 'F9296A552E8AA53998177B67FC4EAF8F77DECFAED82E1B7C02D36FB120517FA0'
Unblock-File 'C:\simple-acme\Scripts\Deploy-FortiADC.ps1' What it does
simple-acme runs the script after each issuance. The script hands the job to a scheduled task named "FairSSL FortiADC <id>", which runs as SYSTEM with no time limit. The job folder under C:\ProgramData\FairSSL\FortiADC 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 wait limit only notices a hung operation; it does not stop the retries. 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 label>-<12 hex of the leaf SHA-256>; an object that already holds the same certificate is reused. Each missing intermediate is imported to the intermediate CA store. An existing CA under any name, or a duplicate answer, is settled by reading back; a hidden duplicate the API cannot identify is reported with guidance. Roots and repeats are left out. The virtual server must have a client SSL profile and a local certificate group. An own fssl-cag- intermediate CA group and a copy of the local certificate group carry the new chain and leaf. The worker renews the member that holds the previous certificate with this label, else the default member or the only member; ReplaceCertificate names the member when that is ambiguous. All other members and extra RSA or EC certificates stay. The client SSL profile points at the copy, so other virtual servers that use the same profile change too. When the delivered chain has no intermediates, the renewed member gets no intermediate group. The current and the previous local certificate group stay. Cleanup deletes only unused fssl- certificates and groups in this job's history, never a CA object. Service TLS is advisory: the API decides success. After the API confirms, the worker looks at the certificate served on the virtual server's address, or on ServiceHost and ServicePort, with ServiceSni as the name asked for. An unreachable service or another served leaf is a warning only. An expired certificate, one that becomes valid more than a day ahead, and keys other than RSA or EC wait for a replacement. The API key is sent only in the APITOKEN header. Management SHA-256 is pinned before APITOKEN or PEM material is sent. Unexpected changes refuse MGMT_CERT_CHANGED. Pins are in C:\ProgramData\FairSSL\FortiADC\<host hash>.pins.json. After an intended change of the management certificate that you have checked yourself, delete that host's pin file. The stored list is read correctly by Windows PowerShell 5.1 after a restart. Each attempt and its 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, FortiADC'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. No API key, secret, private key or PEM is reported. The REST calls follow the fortiadc-api 2.0.5 contract: /api/<resource>, ?vdom= when VDOM is on, and payload 0 for a completed write. Measured on FortiADC-VM 8.0.4. 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
| -FortiADCHost | FortiADC's management host name or IP address. In an HA cluster: the Configuration Source. |
|---|---|
| -SecretName | Name of the REST API administrator key in simple-acme's vault (wacs.exe: O, S, A); default fortiadc. 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. |
| -VirtualServerName | The virtual server that gets the certificate. |
| -Vdom | The virtual server's VDOM; root when VDOM is off. |
| -ReplaceCertificate | The certificate held by the group member to renew, when the worker cannot decide the member itself. |
| -ServiceHost | Address where the served certificate is looked at afterwards; default the virtual server's address. |
| -ServicePort | Port for ServiceHost; default the virtual server's port. |
| -ServiceSni | Server name asked for in that check; default the certificate's common name. |
| -ManagementCertSha256 | Optional SHA-256 of the management leaf to pin before the first connection. |
| -Port | 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-FortiADC.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-FortiADC.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-FortiADC.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-FortiADC.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