Skip to content

Commit b244c76

Browse files
authored
Add --list-profiles command to show CA profiles
This commit introduces a new command, `--list-profiles`, to allow users to discover the certificate profiles supported by a Certificate Authority. The command queries the `meta.profiles` object within the ACME directory JSON for the selected server and formats the output for readability. If a CA does not publish profiles in its directory, the command reports that none were found. Usage: acme.sh --list-profiles [--server letsencrypt]
1 parent f2dbf56 commit b244c76

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

acme.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5838,6 +5838,49 @@ list() {
58385838

58395839
}
58405840

5841+
list_profiles() {
5842+
_initpath
5843+
_initAPI
5844+
5845+
_l_server_url="$ACME_DIRECTORY"
5846+
_l_server_name="$(_getCAShortName "$_l_server_url")"
5847+
_info "Fetching profiles from $_l_server_name ($_l_server_url)..."
5848+
5849+
# _initAPI fetches the directory, so we just need to parse its response.
5850+
response=$(_get "$_l_server_url" "" 10)
5851+
if [ "$?" != "0" ]; then
5852+
_err "Failed to connect to CA directory: $_l_server_url"
5853+
return 1
5854+
fi
5855+
5856+
# Isolate the profiles object using the script's regex tool
5857+
profiles_json=$(echo "$response" | _egrep_o '"profiles" *: *\{[^\}]*\}')
5858+
5859+
if [ -z "$profiles_json" ]; then
5860+
_info "The CA '$_l_server_name' does not publish certificate profiles via its directory endpoint."
5861+
return 0
5862+
fi
5863+
5864+
# Strip the outer layer to get the key-value pairs
5865+
profiles_kv=$(echo "$profiles_json" | sed 's/"profiles" *: *{//' | sed 's/}$//' | tr ',' '\n')
5866+
5867+
printf "\n%-15s %s\n" "name" "info"
5868+
printf -- "--------------------------------------------------------------------\n"
5869+
5870+
_old_IFS="$IFS"
5871+
IFS='
5872+
'
5873+
for pair in $profiles_kv; do
5874+
# Trim quotes and whitespace
5875+
_name=$(echo "$pair" | cut -d: -f1 | tr -d '" \t')
5876+
_info_url=$(echo "$pair" | cut -d: -f2- | sed 's/^ *//' | tr -d '"')
5877+
printf "%-15s %s\n" "$_name" "$_info_url"
5878+
done
5879+
IFS="$_old_IFS"
5880+
5881+
return 0
5882+
}
5883+
58415884
_deploy() {
58425885
_d="$1"
58435886
_hooks="$2"
@@ -7498,6 +7541,9 @@ _process() {
74987541
--set-default-chain)
74997542
_CMD="setdefaultchain"
75007543
;;
7544+
--list-profiles)
7545+
_CMD="list_profiles"
7546+
;;
75017547
-d | --domain)
75027548
_dvalue="$2"
75037549

@@ -8063,6 +8109,9 @@ _process() {
80638109
setdefaultchain)
80648110
setdefaultchain "$_preferred_chain"
80658111
;;
8112+
list_profiles)
8113+
list_profiles
8114+
;;
80668115
*)
80678116
if [ "$_CMD" ]; then
80688117
_err "Invalid command: $_CMD"

0 commit comments

Comments
 (0)