#!/usr/bin/env sh # Script to deploy a certificate to FortiGate via API and set it as the current web GUI certificate. # # FortiGate's native ACME integration does not support wildcard certificates or domain validation, # and is not supported if you have a custom management web port (eg. DNAT web traffic). # # REQUIRED: # export FGT_HOST="fortigate_hostname-or-ip" # export FGT_TOKEN="fortigate_api_token" # # OPTIONAL: # export FGT_PORT="10443" # Custom HTTPS port (defaults to 443 if not set) # # Run `acme.sh --deploy -d example.com --deploy-hook fortigate --insecure` to use this script. # `--insecure` is required on first run if not already using a valid SSL certificate on firewall. # Function to parse response parse_response() { response="$1" func="$2" status=$(echo "$response" | grep -o '"status":[ ]*"[^"]*"' | sed 's/"status":[ ]*"\([^"]*\)"/\1/') if [ "$status" != "success" ]; then _err "[$func] Operation failed. Deploy with --insecure if current certificate is invalid. Try deploying with --debug to troubleshoot." return 1 else _debug "[$func] Operation successful." return 0 fi } # Function to deploy base64-encoded certificate to firewall deployer() { cert_base64=$(_base64 <"$_cfullchain" | tr -d '\n') key_base64=$(_base64 <"$_ckey" | tr -d '\n') payload=$( cat <