Free ACME scripts / Windows
FortiNAC
Installs a simple-acme certificate and chain on one FortiNAC REST v2 target.
- Version
- 1.9
- Language
- PowerShell
- SHA-256
- b4f7030ae0cdf1da5c845a25d126b5afc5491d72e7a46228c0de899341f19a82
- 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-FortiNAC.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/fortinac-1.9.ps1' -OutFile 'C:\simple-acme\Scripts\Deploy-FortiNAC.ps1'
(Get-FileHash 'C:\simple-acme\Scripts\Deploy-FortiNAC.ps1' -Algorithm SHA256).Hash -eq 'B4F7030AE0CDF1DA5C845A25D126B5AFC5491D72E7A46228C0DE899341F19A82'
Unblock-File 'C:\simple-acme\Scripts\Deploy-FortiNAC.ps1' What it does
The script follows the REST API v2 certificate calls of the sslbrain fortinac 2.0.5 contract for FortiNAC 9.x and FortiNAC-F 7.x, on port 8443 with a Bearer API token. simple-acme runs the script after each issuance. The script hands the job to a scheduled task named "FairSSL FortiNAC <id>", which runs as SYSTEM with no time limit. The job folder under C:\ProgramData\FairSSL\FortiNAC is open to SYSTEM and Administrators only. It holds worker.log and the API token, 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. FortiNAC takes an RSA key of 2048, 3072 or 4096 bits; a certificate with an EC key is refused as KEY_TYPE. The worker converts an unencrypted PKCS#8 key to RSA PKCS#1 in memory and uploads the certificate and its intermediate chain together. A certificate or intermediate that is already there is no error. The chain is not imported into a trust store. Only the service of the chosen target is restarted, and only when the API asks for it. The contract does not choose an HA member: the certificate is installed on the FortiNAC that FortiNACHost names. For the portal on FortiNAC-F 7.2.5 and earlier, Portal SSL mode may also have to be set to Valid SSL Certificate by hand. Management leaf SHA-256 is checked before sending the Bearer API token. An unexpected change is refused as MGMT_CERT_CHANGED. Pins are in C:\ProgramData\FairSSL\FortiNAC\<host hash>.pins.json. After an intended change of the management certificate that you have checked yourself, delete that host's pin file. For the tomcat target the new certificate is stored as an accepted pin before the upload and kept for the next renewal. Every API write is read back. Served TLS is advisory: the device API decides. Another or unreachable served certificate is a warning only; ServiceHost and ServicePort choose where to look, and radius has no check unless they are given. 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, FortiNAC's model, product name 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 token, key or certificate PEM is reported. 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
| -FortiNACHost | FortiNAC's host name or IP address. |
|---|---|
| -Port | Port of FortiNAC's REST API v2, default 8443. |
| -SecretName | Name of the API token in simple-acme's vault (wacs.exe: O, S, A); default fortinac. The script reads the vault itself, so the token never reaches a command line. |
| -VaultFile | simple-acme secrets.json to read, only when different ACME servers hold different secrets under that name. |
| -ApiToken | The API token itself, instead of SecretName. simple-acme then keeps the token in its renewal settings and its log on the server, and in PowerShell each $ and backtick in the token needs a backtick before it. |
| -Target | tomcat (Admin UI), portal, agent (Persistent Agent), radsec or radius (EAP). |
| -ServiceHost | Address where the served certificate is looked at afterwards; default FortiNACHost. |
| -ServicePort | Port for that check; default the target's own port. |
| -ManagementCertSha256 | Optional verified SHA-256 of the management leaf to pin on first contact. |
| -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-FortiNAC.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-FortiNAC.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-FortiNAC.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-FortiNAC.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