From d53c2ea453341cb63517b8ab9533e0dcc053fe8b Mon Sep 17 00:00:00 2001 From: Gondolf <145931259+vGondolf@users.noreply.github.com> Date: Sun, 9 Feb 2025 12:55:05 +0100 Subject: [PATCH 1/8] Update shellcheck.yml --- .github/workflows/shellcheck.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 746727d4..039a9c7c 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -1,5 +1,6 @@ name: Shellcheck on: + workflow_dispatch: push: branches: - '*' From 2ab37f24285904c29939ca74c7666f1ff3c5a01d Mon Sep 17 00:00:00 2001 From: Gondolf <145931259+vGondolf@users.noreply.github.com> Date: Sun, 9 Feb 2025 12:56:39 +0100 Subject: [PATCH 2/8] Create fortigate.sh --- deploy/fortigate.sh | 166 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 deploy/fortigate.sh diff --git a/deploy/fortigate.sh b/deploy/fortigate.sh new file mode 100644 index 00000000..915ad32e --- /dev/null +++ b/deploy/fortigate.sh @@ -0,0 +1,166 @@ +#!/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, +# 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) +# +# This script is intended for use as an acme.sh deploy hook. +# +# Run `acme.sh --deploy -d example.com --deploy-hook fortigate --insecure` to use this script. +# `--insecure` is required to allow acme.sh to connect to the FortiGate API over HTTPS without a pre-existing valid certificate. + +# 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 < Date: Fri, 14 Feb 2025 10:54:49 +0100 Subject: [PATCH 3/8] Create arubacentral.sh --- deploy/arubacentral.sh | 178 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 deploy/arubacentral.sh diff --git a/deploy/arubacentral.sh b/deploy/arubacentral.sh new file mode 100644 index 00000000..0a951b24 --- /dev/null +++ b/deploy/arubacentral.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env sh +# Aruba Central deploy hook for acme.sh + +arubacentral_deploy() { + # Generate unique certificate name with a proper random number (5 digits) + _cdomain="$(echo "$1" | sed 's/*/WILDCARD_/g')_$(tr -dc '0-9' Date: Fri, 14 Feb 2025 12:12:46 +0100 Subject: [PATCH 4/8] Update arubacentral.sh fix shfmt and shellcheck --- deploy/arubacentral.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/deploy/arubacentral.sh b/deploy/arubacentral.sh index 0a951b24..99873ce8 100644 --- a/deploy/arubacentral.sh +++ b/deploy/arubacentral.sh @@ -54,7 +54,7 @@ arubacentral_deploy() { # Base64 encode the passphrase _debug "Encoding passphrase in Base64..." - _passphrase_base64=$(echo -n "$_passphrase" | _base64 | tr -d '\n') + _passphrase_base64=$(printf "%s" "$_passphrase" | _base64 | tr -d '\n') # Upload Certificate with Automatic Token Refresh on Failure _upload_certificate || return 1 @@ -116,6 +116,20 @@ _refresh_access_token() { _getdeployconf "ARUBA_ACCESS_TOKEN" _getdeployconf "ARUBA_REFRESH_TOKEN" + # 🔍 Step 1: Check if the access token is still valid + _debug "Checking if the access token is still valid..." + check_url="${ARUBA_HOST}/configuration/v1/certificates?limit=1" + _H1="Authorization: Bearer $ARUBA_ACCESS_TOKEN" + response=$(_post "" "$check_url" "" "GET" "application/json") + + if echo "$response" | grep -q '"error":"invalid_token"'; then + _debug "❌ Access token is invalid, refreshing..." + else + _debug "✅ Access token is still valid, skipping refresh." + return 0 # Skip refresh + fi + + # 🔄 Step 2: Refresh token if it's invalid _debug "Refreshing Aruba Central API token..." refresh_url="${ARUBA_HOST}/oauth2/token" @@ -139,16 +153,15 @@ EOF if [ -n "$new_token" ]; then _debug "✅ Token refreshed successfully!" _savedeployconf "ARUBA_ACCESS_TOKEN" "$new_token" 1 - + ARUBA_ACCESS_TOKEN="$new_token" + if [ -n "$new_refresh_token" ]; then _debug "🔄 Updating refresh token..." _savedeployconf "ARUBA_REFRESH_TOKEN" "$new_refresh_token" 1 + ARUBA_REFRESH_TOKEN="$new_refresh_token" else - _debug "⚠️ Aruba Central did not return a new refresh token!" + _debug "⚠️ Aruba Central did not return a new refresh token! Keeping the old one." fi - - ARUBA_ACCESS_TOKEN="$new_token" - ARUBA_REFRESH_TOKEN="$new_refresh_token" else _err "❌ Failed to refresh API token. Please manually generate a new one." return 1 @@ -158,12 +171,12 @@ EOF # Function to delete the previous certificate _delete_old_certificate() { _getdeployconf "ARUBA_LAST_CERT" - + if [ -n "$ARUBA_LAST_CERT" ]; then _debug "Found previous certificate: $ARUBA_LAST_CERT. Deleting it..." delete_url="${ARUBA_HOST}/configuration/v1/certificates/${ARUBA_LAST_CERT}" _H1="Authorization: Bearer $ARUBA_ACCESS_TOKEN" - + response=$(_post "" "$delete_url" "" "DELETE" "application/json") _debug "Delete certificate API response: $response" From 529d1789cc40f56ef3da5d489cfdec1c894edc79 Mon Sep 17 00:00:00 2001 From: Gondolf <145931259+vGondolf@users.noreply.github.com> Date: Fri, 14 Feb 2025 12:14:31 +0100 Subject: [PATCH 5/8] Update arubacentral.sh --- deploy/arubacentral.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/arubacentral.sh b/deploy/arubacentral.sh index 99873ce8..474e4cfa 100644 --- a/deploy/arubacentral.sh +++ b/deploy/arubacentral.sh @@ -126,7 +126,7 @@ _refresh_access_token() { _debug "❌ Access token is invalid, refreshing..." else _debug "✅ Access token is still valid, skipping refresh." - return 0 # Skip refresh + return 0 # Skip refresh fi # 🔄 Step 2: Refresh token if it's invalid From 6382500afabd5a3fefcf5fbb81d41e33f96de4b7 Mon Sep 17 00:00:00 2001 From: Gondolf <145931259+vGondolf@users.noreply.github.com> Date: Fri, 14 Feb 2025 12:17:26 +0100 Subject: [PATCH 6/8] Delete deploy/arubacentral.sh --- deploy/arubacentral.sh | 191 ----------------------------------------- 1 file changed, 191 deletions(-) delete mode 100644 deploy/arubacentral.sh diff --git a/deploy/arubacentral.sh b/deploy/arubacentral.sh deleted file mode 100644 index 474e4cfa..00000000 --- a/deploy/arubacentral.sh +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/env sh -# Aruba Central deploy hook for acme.sh - -arubacentral_deploy() { - # Generate unique certificate name with a proper random number (5 digits) - _cdomain="$(echo "$1" | sed 's/*/WILDCARD_/g')_$(tr -dc '0-9' Date: Fri, 14 Feb 2025 12:19:47 +0100 Subject: [PATCH 7/8] Create arubacentral.sh --- deploy/arubacentral.sh | 181 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 deploy/arubacentral.sh diff --git a/deploy/arubacentral.sh b/deploy/arubacentral.sh new file mode 100644 index 00000000..b4b58283 --- /dev/null +++ b/deploy/arubacentral.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env sh +# Aruba Central deploy hook for acme.sh + +arubacentral_deploy() { + # Generate unique certificate name with a proper random number (5 digits) + _cdomain="$(echo "$1" | sed 's/*/WILDCARD_/g')_$(tr -dc '0-9' Date: Fri, 14 Feb 2025 12:54:17 +0100 Subject: [PATCH 8/8] Update arubacentral.sh --- deploy/arubacentral.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deploy/arubacentral.sh b/deploy/arubacentral.sh index b4b58283..2191c6b0 100644 --- a/deploy/arubacentral.sh +++ b/deploy/arubacentral.sh @@ -170,8 +170,10 @@ _delete_old_certificate() { response=$(_post "" "$delete_url" "" "DELETE" "application/json") _debug "Delete certificate API response: $response" - if echo "$response" | grep -q '"error"'; then - _err "❌ Failed to delete previous certificate." + if echo "$response" | jq -e '.description | test("not present")' >/dev/null 2>&1; then + _debug "✅ Previous certificate not found - skipping." + elif echo "$response" | jq -e '.error_code' >/dev/null 2>&1; then + _err "❌ Failed to delete previous certificate: $(echo "$response" | jq -r '.description')" else _debug "✅ Previous certificate deleted successfully." fi