Free ACME scripts / Linux
FortiMail (Linux)
Installs the certificate that lego keeps on this server on a FortiMail, over SSH, and keeps trying until it is installed. Reports every result when it has a report address.
- Version
- 1.2.0
- Language
- bash
- SHA-256
- 8c89447919b8677e0e19d669cfbe1cb26f713a22fc809f19c6f196053383aa4b
- Licence
- Apache-2.0, copyright FairSSL A/S
Download it on the server, check the SHA-256 and keep it as /usr/local/bin/fairssl-fortimail, so a newer version later replaces it without a change to your renewal:
curl -fsSL -o /tmp/fortimail-linux-1.2.0.sh 'https://sslbrain.com/scripts/files/fortimail-linux-1.2.0.sh'
echo '8c89447919b8677e0e19d669cfbe1cb26f713a22fc809f19c6f196053383aa4b /tmp/fortimail-linux-1.2.0.sh' | sha256sum -c -
sudo install -m 0755 /tmp/fortimail-linux-1.2.0.sh /usr/local/bin/fairssl-fortimail What it does
Used by FairSSL's guide "FortiMail (Linux Agent)" and, with any ACME service, as lego's deploy hook.
fairssl-fortimail setup --name NAME --host ADDRESS [--port 22] [--user admin] [--report-url URL] Asks for the FortiMail password and keeps it in /etc/fairssl-fortimail/NAME.password (root only, 0600), pins FortiMail's SSH host key in /etc/fairssl-fortimail/known_hosts, logs in once and shows what it found. fairssl-fortimail deploy NAME Installs the certificate now and shows the result. If the attempt fails, a background worker keeps trying. fairssl-fortimail hook NAME lego's --deploy-hook: starts the background worker and returns at once. fairssl-fortimail resume NAME At boot: starts the worker again when a restart interrupted a deployment. fairssl-fortimail status NAME Shows the settings (never the password), the last result and the log.
What the worker does, each attempt: it reads the certificate and key lego saved, logs in to FortiMail with the password from the root-only file (handed to ssh by this script as its askpass program, never in a command line, the environment or a log), uploads the certificate with its intermediates as a local certificate named fssl-<6 hex of the certificate name>-<12 hex of the certificate's SHA-256>, makes it FortiMail's default certificate (HTTPS, webmail and mail over TLS), reloads httpd and smtpd, and looks with TLS handshakes on HTTPS and SMTP (STARTTLS) at what it serves; the default certificate read back over SSH decides. If a listener that answered before stops answering, the previous certificate is put back. It keeps the previous certificate object and deletes older objects of its own. A failed attempt is reported and tried again after 1, 2, 5, 15, 30 and then every 60 minutes, for as long as it takes, also after a restart of this server. Every result is sent to the report address (a failure that repeats unchanged once a day); a report the receiver has not confirmed waits in /var/lib/fairssl-fortimail/outbox and is sent again.
Requires: bash 4, OpenSSH client, openssl, curl, flock and setsid (util-linux), run as root.
Requirements
- A Linux server with bash, run as root
- One of the ACME clients lego, certbot or acme.sh
Parameters
| --name | setup: the certificate's name, as lego knows it (--cert.name). The other commands take it as NAME. |
|---|---|
| --host | setup: FortiMail's IP address or host name. |
| --port | setup: FortiMail's SSH port. Defaults to 22. |
| --user | setup: the FortiMail administrator the script logs in as. Defaults to admin. |
| --https-port | setup: FortiMail's HTTPS port for the TLS check. Defaults to 443. |
| --smtp-port | setup: FortiMail's SMTP port for the TLS check (STARTTLS). Defaults to 25. |
| --report-url | setup: where each result is reported, an https address. Leave it out: the address set up before is kept, otherwise DEFAULT_REPORT_URL below is used; when that is empty too, nothing is sent. |
| --lego-path | setup: lego's --path. Defaults to /etc/ssl/fortimail. |
Get a certificate and run the script
The ACME client orders the certificate and runs the script after the first issuance and after each renewal. Replace
www.example.com, the e-mail address and the script's arguments (see
Parameters). The HTTP challenge is answered from /var/www/html;
use your web server's document root.
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
lego
sudo /usr/local/bin/lego run --domains "www.example.com" \
--server "https://acme-v02.api.letsencrypt.org/directory" \
--accept-tos --email "you@example.com" \
--http --http.webroot /var/www/html \
--path /etc/ssl/fortimail \
--deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" Renew from cron, for example daily at 03:30 in /etc/cron.d/lego-fortimail-linux:
30 3 * * * root /usr/local/bin/lego run --domains "www.example.com" --server "https://acme-v02.api.letsencrypt.org/directory" --accept-tos --email "you@example.com" --http --http.webroot /var/www/html --path /etc/ssl/fortimail --renew-days 30 --deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" certbot
sudo certbot certonly --webroot -w /var/www/html -d www.example.com \
--server "https://acme-v02.api.letsencrypt.org/directory" \
--agree-tos -m you@example.com \
--deploy-hook 'install -D -m 600 "$RENEWED_LINEAGE/fullchain.pem" /etc/ssl/fortimail/certificates/www.example.com.crt && install -D -m 600 "$RENEWED_LINEAGE/privkey.pem" /etc/ssl/fortimail/certificates/www.example.com.key && /usr/local/bin/fairssl-fortimail <arguments>' acme.sh
# As root, with acme.sh installed for root
mkdir -p /etc/ssl/fortimail/certificates
acme.sh --register-account --server letsencrypt -m you@example.com
acme.sh --issue --server letsencrypt -d www.example.com -w /var/www/html
acme.sh --install-cert -d www.example.com \
--key-file /etc/ssl/fortimail/certificates/www.example.com.key \
--fullchain-file /etc/ssl/fortimail/certificates/www.example.com.crt \
--reloadcmd "/usr/local/bin/fairssl-fortimail <arguments>" 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
lego
sudo /usr/local/bin/lego run --domains "www.example.com" \
--server "https://dv.acme-v02.api.pki.goog/directory" \
--eab --eab.kid "EAB_KID" --eab.hmac "EAB_HMAC" \
--accept-tos --email "you@example.com" \
--http --http.webroot /var/www/html \
--path /etc/ssl/fortimail \
--deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" Renew from cron, for example daily at 03:30 in /etc/cron.d/lego-fortimail-linux:
30 3 * * * root /usr/local/bin/lego run --domains "www.example.com" --server "https://dv.acme-v02.api.pki.goog/directory" --accept-tos --email "you@example.com" --http --http.webroot /var/www/html --path /etc/ssl/fortimail --renew-days 30 --deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" certbot
sudo certbot certonly --webroot -w /var/www/html -d www.example.com \
--server "https://dv.acme-v02.api.pki.goog/directory" \
--eab-kid "EAB_KID" --eab-hmac-key "EAB_HMAC" \
--agree-tos -m you@example.com \
--deploy-hook 'install -D -m 600 "$RENEWED_LINEAGE/fullchain.pem" /etc/ssl/fortimail/certificates/www.example.com.crt && install -D -m 600 "$RENEWED_LINEAGE/privkey.pem" /etc/ssl/fortimail/certificates/www.example.com.key && /usr/local/bin/fairssl-fortimail <arguments>' acme.sh
# As root, with acme.sh installed for root
mkdir -p /etc/ssl/fortimail/certificates
acme.sh --register-account --server google -m you@example.com \
--eab-kid "EAB_KID" --eab-hmac-key "EAB_HMAC"
acme.sh --issue --server google -d www.example.com -w /var/www/html
acme.sh --install-cert -d www.example.com \
--key-file /etc/ssl/fortimail/certificates/www.example.com.key \
--fullchain-file /etc/ssl/fortimail/certificates/www.example.com.crt \
--reloadcmd "/usr/local/bin/fairssl-fortimail <arguments>" 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
lego
sudo /usr/local/bin/lego run --domains "www.example.com" \
--server "https://acme.zerossl.com/v2/DV90" \
--eab --eab.kid "EAB_KID" --eab.hmac "EAB_HMAC" \
--accept-tos --email "you@example.com" \
--http --http.webroot /var/www/html \
--path /etc/ssl/fortimail \
--deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" Renew from cron, for example daily at 03:30 in /etc/cron.d/lego-fortimail-linux:
30 3 * * * root /usr/local/bin/lego run --domains "www.example.com" --server "https://acme.zerossl.com/v2/DV90" --accept-tos --email "you@example.com" --http --http.webroot /var/www/html --path /etc/ssl/fortimail --renew-days 30 --deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" certbot
sudo certbot certonly --webroot -w /var/www/html -d www.example.com \
--server "https://acme.zerossl.com/v2/DV90" \
--eab-kid "EAB_KID" --eab-hmac-key "EAB_HMAC" \
--agree-tos -m you@example.com \
--deploy-hook 'install -D -m 600 "$RENEWED_LINEAGE/fullchain.pem" /etc/ssl/fortimail/certificates/www.example.com.crt && install -D -m 600 "$RENEWED_LINEAGE/privkey.pem" /etc/ssl/fortimail/certificates/www.example.com.key && /usr/local/bin/fairssl-fortimail <arguments>' acme.sh
# As root, with acme.sh installed for root
mkdir -p /etc/ssl/fortimail/certificates
acme.sh --register-account --server zerossl -m you@example.com \
--eab-kid "EAB_KID" --eab-hmac-key "EAB_HMAC"
acme.sh --issue --server zerossl -d www.example.com -w /var/www/html
acme.sh --install-cert -d www.example.com \
--key-file /etc/ssl/fortimail/certificates/www.example.com.key \
--fullchain-file /etc/ssl/fortimail/certificates/www.example.com.crt \
--reloadcmd "/usr/local/bin/fairssl-fortimail <arguments>" 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
lego
sudo /usr/local/bin/lego run --domains "www.example.com" \
--server "https://acme.sslbrain.com/acme/directory" \
--eab --eab.kid "EAB_KID" --eab.hmac "EAB_HMAC" \
--accept-tos --email "you@example.com" \
--http --http.webroot /var/www/html \
--path /etc/ssl/fortimail \
--deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" Renew from cron, for example daily at 03:30 in /etc/cron.d/lego-fortimail-linux:
30 3 * * * root /usr/local/bin/lego run --domains "www.example.com" --server "https://acme.sslbrain.com/acme/directory" --accept-tos --email "you@example.com" --http --http.webroot /var/www/html --path /etc/ssl/fortimail --renew-days 30 --deploy-hook "/usr/local/bin/fairssl-fortimail <arguments>" certbot
sudo certbot certonly --manual --manual-auth-hook /bin/true -d www.example.com \
--server "https://acme.sslbrain.com/acme/directory" \
--eab-kid "EAB_KID" --eab-hmac-key "EAB_HMAC" \
--agree-tos -m you@example.com \
--deploy-hook 'install -D -m 600 "$RENEWED_LINEAGE/fullchain.pem" /etc/ssl/fortimail/certificates/www.example.com.crt && install -D -m 600 "$RENEWED_LINEAGE/privkey.pem" /etc/ssl/fortimail/certificates/www.example.com.key && /usr/local/bin/fairssl-fortimail <arguments>' acme.sh
# As root, with acme.sh installed for root
mkdir -p /etc/ssl/fortimail/certificates
acme.sh --register-account --server "https://acme.sslbrain.com/acme/directory" -m you@example.com \
--eab-kid "EAB_KID" --eab-hmac-key "EAB_HMAC"
acme.sh --issue --server "https://acme.sslbrain.com/acme/directory" -d www.example.com -w /var/www/html
acme.sh --install-cert -d www.example.com \
--key-file /etc/ssl/fortimail/certificates/www.example.com.key \
--fullchain-file /etc/ssl/fortimail/certificates/www.example.com.crt \
--reloadcmd "/usr/local/bin/fairssl-fortimail <arguments>" - lego keeps the certificate and key under certificates/ in the --path folder and runs the --deploy-hook after the first issuance and each renewal.
- certbot runs the --deploy-hook after each renewal from its own timer; the hook copies the full chain and key to the folder and names lego uses, so the script finds them there.
- acme.sh copies the full chain and key to lego's folder and names given in --install-cert and runs --reloadcmd after each renewal from its own cron job.
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
--report-url 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.
One script per server, or sslbrain does it for all your servers without scripts.
Feedback and improvements are welcome: info@fairssl.dk