Skip to content

Commit 094d03b

Browse files
authored
Merge pull request #6542 from szhu25/list-profiles
Implement discovery of CA certificate profiles
2 parents f2dbf56 + 0f5093c commit 094d03b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

acme.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5838,6 +5838,48 @@ 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+
response=$(_get "$_l_server_url" "" 10)
5850+
if [ "$?" != "0" ]; then
5851+
_err "Failed to connect to CA directory: $_l_server_url"
5852+
return 1
5853+
fi
5854+
5855+
normalized_response=$(echo "$response" | _normalizeJson)
5856+
profiles_json=$(echo "$normalized_response" | _egrep_o '"profiles" *: *\{[^\}]*\}')
5857+
5858+
if [ -z "$profiles_json" ]; then
5859+
_info "The CA '$_l_server_name' does not publish certificate profiles via its directory endpoint."
5860+
return 0
5861+
fi
5862+
5863+
# Strip the outer layer to get the key-value pairs
5864+
profiles_kv=$(echo "$profiles_json" | sed 's/"profiles" *: *{//' | sed 's/}$//' | tr ',' '\n')
5865+
5866+
printf "\n%-15s %s\n" "name" "info"
5867+
printf -- "--------------------------------------------------------------------\n"
5868+
5869+
_old_IFS="$IFS"
5870+
IFS='
5871+
'
5872+
for pair in $profiles_kv; do
5873+
# Trim quotes and whitespace
5874+
_name=$(echo "$pair" | cut -d: -f1 | tr -d '" \t')
5875+
_info_url=$(echo "$pair" | cut -d: -f2- | sed 's/^ *//' | tr -d '"')
5876+
printf "%-15s %s\n" "$_name" "$_info_url"
5877+
done
5878+
IFS="$_old_IFS"
5879+
5880+
return 0
5881+
}
5882+
58415883
_deploy() {
58425884
_d="$1"
58435885
_hooks="$2"
@@ -7498,6 +7540,9 @@ _process() {
74987540
--set-default-chain)
74997541
_CMD="setdefaultchain"
75007542
;;
7543+
--list-profiles)
7544+
_CMD="list_profiles"
7545+
;;
75017546
-d | --domain)
75027547
_dvalue="$2"
75037548

@@ -8063,6 +8108,9 @@ _process() {
80638108
setdefaultchain)
80648109
setdefaultchain "$_preferred_chain"
80658110
;;
8111+
list_profiles)
8112+
list_profiles
8113+
;;
80668114
*)
80678115
if [ "$_CMD" ]; then
80688116
_err "Invalid command: $_CMD"

0 commit comments

Comments
 (0)