Free ACME scripts / Windows

Palo Alto

Installs a simple-acme certificate on a Palo Alto firewall or Panorama over the XML API, in the background, and keeps trying until the firewall serves it.

Version
1.5
Language
PowerShell
SHA-256
7ec7e21dc2c3b248dec41c57adbe4b1790605822dd2c677b290faba2655298d8
Licence
Apache-2.0, copyright FairSSL A/S
Download paloalto-1.5.ps1

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

What it does

simple-acme runs this script as its installation step. The script checks the PEM files, hands the job to a worker and returns 0 straight away; simple-acme is never held up by the firewall. When an administrator runs wacs.exe by hand, the script shows the worker's progress until its first attempt ends.

The worker is a scheduled task, "FairSSL PaloAlto <id>", that runs once as SYSTEM with no time limit, one copy per firewall and certificate. Workers for the same firewall take turns, one attempt at a time. On every attempt it:

  • reads PAN-OS version, HA state and the API administrator's own pending changes, and stops when that administrator has uncommitted changes of its own (another administrator's changes are left alone: the commit is partial);
  • uploads certificate, intermediates and key as PEM in one new object fssl-<id6>-<fp12> (24 characters), in Shared, in a vsys (-Vsys) or in a Panorama template or template stack (-Template, -TemplateStack);
  • points the SSL/TLS service profiles named in -Profiles at it, and adds it to the SSL Inbound Inspection rules named in -DecryptionRules beside the certificate the server presents now (the firewall decrypts with the server's own certificate, so the server gets the same certificate too); a name that does not exist stops the attempt and lists the names that do;
  • deletes older objects of its own, keeping the new and the previous one;
  • commits only the API administrator's changes and follows the commit job for as long as it moves; on Panorama it then pushes the template or template stack and follows each push job (the push sends everything committed to that template or template stack, also what other administrators committed without pushing); a push that reaches no firewall is a failed attempt;
  • on an HA pair, works on the active peer and also sets the management certificate on the other peer, whose management configuration does not sync;
  • checks with TLS handshakes that every service that served the replaced certificate before now serves the new one, and that every server behind a decryption rule that answered before still answers; if one does not, the previous certificate is put back.

A failed attempt takes back its uncommitted changes and is tried again after 1, 2, 5, 10 and 30 minutes and then every hour, with no end, until the firewall serves the certificate. A newer certificate from simple-acme in the meantime is taken along. After a restart of the server the task starts again by itself. A certificate browsers would refuse is not installed: one that has expired, is not valid until more than a day from now, has an empty subject, or has a key other than RSA or ECDSA.

Each attempt's result goes to the report address (-ReportUrl; FairSSL's control panel in FairSSL's download): the ACME account, renewal id, domain, thumbprint, expiry, whether the installation worked, the error and the worker's own log of that attempt; also this script's file name, version and SHA-256, the firewall's model and PAN-OS version, the server's Windows and PowerShell version and the certificate's key type and SHA-256 fingerprint. Never the API key, the private key or the certificate. A report the receiver has not confirmed waits in the job folder and is sent again. simple-acme's own result of each run is reported by Scripts\FairSSLResultNotification.ps1; its help and fairssl-readme.txt list the fields.

The firewall's management certificate is accepted when Windows trusts it for the address, and otherwise kept on first contact for the whole machine in C:\ProgramData\FairSSL\PaloAlto\pins.json. A certificate this script installs on management is added there before it is committed. A changed certificate is refused and reported as MGMT_CERT_CHANGED; when it changed on purpose, delete the firewall's line there.

-NewApiKey asks for the password of a firewall administrator, creates its API key (keygen, POST), checks it, lists the SSL/TLS service profiles and decryption rules with the certificate each uses, and stores the key in simple-acme's vault. The password is not stored. The key is stored encrypted for this machine, so the renewal task, which runs as SYSTEM, reads it through '{vault://json/paloalto}'. On Panorama no list is shown: select the template at the top of the Device tab, and the profiles are under Device > Certificate Management > SSL/TLS Service Profile.

The API administrator has an admin role with everything off under Web UI and REST API and only Configuration, Import, Commit and Operational Requests on under XML API (Device > Admin Roles, then Device > Administrators; on Panorama a Panorama role under Panorama > Admin Roles and Panorama > Administrators), and exists once the role and the administrator are committed. PAN-OS 11.2.15 and 11.2.16 allow certificate import only for the Superuser role: there the administrator has that role. Use the account for nothing else: an attempt waits for as long as this administrator has uncommitted changes of its own.

simple-acme's scheduled task starts the renewal check, and a renewed certificate is installed with a commit on the firewall. The time of day is ScheduledTask.StartBoundary in C:\simple-acme\settings.json (settings_default.json until wacs.exe has run for the first time), and RandomDelay lets the task start up to that much later. After a change in settings.json, run "wacs.exe --setuptaskscheduler" once as Administrator.

The worker writes its log to C:\ProgramData\FairSSL\PaloAlto\<id>\worker.log. On the firewall the certificate is under Device > Certificate Management > Certificates with a name that starts with fssl-. When a firewall is taken out of service, delete the task "FairSSL PaloAlto <id>" in Task Scheduler and its folder under C:\ProgramData\FairSSL\PaloAlto, and delete the renewal in simple-acme (wacs.exe, Manage renewals).

Requires Windows PowerShell 4.0 or newer and .NET Framework 4.5 or newer, and a server that reaches the management address over HTTPS (-Port).

Requirements

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

Parameters

-StorePath Folder where simple-acme stores PEM files.
-FilePrefix PEM filename prefix configured in simple-acme.
-FirewallHost Management address of the firewall or Panorama: IP address or host name. For an HA pair, the active firewall's address.
-Port HTTPS port of the management interface. Defaults to 443.
-CertLabel Name of this certificate in the object names. Defaults to FilePrefix.
-ApiKey The XML API key, in plain text or as '{vault://json/<name>}' in simple-acme's --scriptparameters, which simple-acme replaces before it starts this script.
-Profiles SSL/TLS service profiles that get the certificate, comma-separated, as named under Device > Certificate Management > SSL/TLS Service Profile. Management, GlobalProtect portals and gateways, Authentication (Captive) Portal and URL admin override all use their certificate through such a profile. Names are written as in the web interface, upper and lower case included: -Profiles 'GP-Portal,GP-Gateway'. Which profile a service uses is shown under: - management: Device > Setup > Management > General Settings - GlobalProtect portal: Network > GlobalProtect > Portals > the portal > Authentication - GlobalProtect gateway: Network > GlobalProtect > Gateways > the gateway > Authentication - Authentication (Captive) Portal: Device > User Identification > Authentication Portal Settings - URL admin override: Device > Setup > Content-ID > URL Admin Override
-DecryptionRules Decryption policy rules of type SSL Inbound Inspection that get the certificate, comma-separated, as named under Policies > Decryption. The new certificate is added to the rule; the rule keeps the certificates it has, except this certificate's objects older than the previous one. The firewall decrypts with the certificate the server presents, so install the same certificate on the server too. Not on Panorama: there decryption rules live in device groups, which this script does not change.
-Vsys The virtual system (vsys1, vsys2, ...) that holds the certificate and the profiles. Leave it out to put the certificate in Shared.
-Template Panorama: the template that holds the certificate and the profiles. Give the template stack its firewalls belong to with -TemplateStack as well: a template on its own has no firewalls to push to.
-TemplateStack Panorama: the template stack to push. Without -Template the certificate and the profiles are in the template stack itself.
-RenewalId simple-acme's {RenewalId}, used in the reports.
-NewApiKey Creates the API key for -UserName on -FirewallHost and stores it in simple-acme's vault as vault://json/<-VaultName>.
-UserName Used with -NewApiKey: the firewall administrator the key belongs to.
-VaultName Used with -NewApiKey: the vault entry name. Defaults to paloalto.
-BaseUri Used with -NewApiKey: the ACME address the renewal uses (wacs.exe --baseuri). simple-acme keeps a vault per ACME address, so the key must be stored under the same one.
-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

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\Deploy-PaloAlto.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\Deploy-PaloAlto.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\Deploy-PaloAlto.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\Deploy-PaloAlto.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.

See how sslbrain works

Feedback and improvements are welcome: info@fairssl.dk