@@ -17,8 +17,9 @@ _SCRIPT_="$0"
17
17
_SUB_FOLDER_NOTIFY=" notify"
18
18
_SUB_FOLDER_DNSAPI=" dnsapi"
19
19
_SUB_FOLDER_DEPLOY=" deploy"
20
+ _SUB_FOLDER_HTTPAPI=" httpapi"
20
21
21
- _SUB_FOLDERS=" $_SUB_FOLDER_DNSAPI $_SUB_FOLDER_DEPLOY $_SUB_FOLDER_NOTIFY "
22
+ _SUB_FOLDERS=" $_SUB_FOLDER_DNSAPI $_SUB_FOLDER_DEPLOY $_SUB_FOLDER_NOTIFY $_SUB_FOLDER_HTTPAPI "
22
23
23
24
CA_LETSENCRYPT_V2=" https://acme-v02.api.letsencrypt.org/directory"
24
25
CA_LETSENCRYPT_V2_TEST=" https://acme-staging-v02.api.letsencrypt.org/directory"
@@ -72,6 +73,7 @@ DEFAULT_RENEW=60
72
73
NO_VALUE=" no"
73
74
74
75
W_DNS=" dns"
76
+ W_HTTPAPI=" http"
75
77
W_ALPN=" alpn"
76
78
DNS_ALIAS_PREFIX=" ="
77
79
@@ -3396,6 +3398,7 @@ _restoreNginx() {
3396
3398
_clearup () {
3397
3399
_stopserver " $serverproc "
3398
3400
serverproc=" "
3401
+ _cleanup_http_entries
3399
3402
_restoreApache
3400
3403
_restoreNginx
3401
3404
_clearupdns
@@ -3407,6 +3410,42 @@ _clearup() {
3407
3410
fi
3408
3411
}
3409
3412
3413
+ _cleanup_http_entries () {
3414
+ if [ -z " $_http_entries " ]; then
3415
+ _debug " _cleanup_http_entries: No HTTP entries to clean up"
3416
+ return 0
3417
+ fi
3418
+ _debug " Cleaning up HTTP entries: $_http_entries "
3419
+
3420
+ entries=$( echo " $_http_entries " | tr " $dvsep " ' ' )
3421
+ for entry in $entries ; do
3422
+ d=$( echo " $entry " | cut -d " $sep " -f 1)
3423
+ token=$( echo " $entry " | cut -d " $sep " -f 2)
3424
+ keyauthorization=$( echo " $entry " | cut -d " $sep " -f 3)
3425
+ _httpapi=$( echo " $entry " | cut -d " $sep " -f 4)
3426
+
3427
+ _debug " Removing HTTP challenge for $d using $_httpapi "
3428
+
3429
+ h_api=" $( _findHook " $d " $_SUB_FOLDER_HTTPAPI " $_httpapi " ) "
3430
+ if [ " $h_api " ]; then
3431
+ if ! . " $h_api " ; then
3432
+ _err " Error loading HTTP API file: $h_api "
3433
+ continue
3434
+ fi
3435
+
3436
+ _remove_fn=" ${_httpapi} _rm"
3437
+ if ! _exists " $_remove_fn " ; then
3438
+ _err " HTTP API file doesn't implement removal function: $_remove_fn "
3439
+ continue
3440
+ fi
3441
+
3442
+ if ! " $_remove_fn " " $d " " $token " " $keyauthorization " ; then
3443
+ _err " Error removing HTTP challenge for domain: $d "
3444
+ fi
3445
+ fi
3446
+ done
3447
+ }
3448
+
3410
3449
_clearupdns () {
3411
3450
_debug " _clearupdns"
3412
3451
_debug " dns_entries" " $dns_entries "
@@ -4987,6 +5026,56 @@ $_authorizations_map"
4987
5026
NGINX_RESTORE_VLIST=" $d$sep$_realConf$sep$_backup$dvsep$NGINX_RESTORE_VLIST "
4988
5027
fi
4989
5028
_sleep 1
5029
+ elif _startswith " $_currentRoot " " http_" ; then
5030
+ _info " Using HTTP API validation for domain: $d "
5031
+ _httpapi=" $( echo " $_currentRoot " | cut -d " _" -f 2-) "
5032
+ h_api=" $( _findHook " $d " $_SUB_FOLDER_HTTPAPI " $_currentRoot " ) "
5033
+ _debug h_api " $h_api "
5034
+
5035
+ if [ " $h_api " ]; then
5036
+ _debug " Found domain HTTP API file: $h_api "
5037
+ if ! . " $h_api " ; then
5038
+ _err " Error loading HTTP API file: $h_api "
5039
+ _cleanup_http_entries
5040
+ _clearup
5041
+ _on_issue_err " $_post_hook " " $vlist "
5042
+ return 1
5043
+ fi
5044
+
5045
+ _deploy_fn=" ${_currentRoot} _deploy"
5046
+ if ! _exists " $_deploy_fn " ; then
5047
+ _err " HTTP API file doesn't implement deployment function: $_deploy_fn "
5048
+ _cleanup_http_entries
5049
+ _clearup
5050
+ _on_issue_err " $_post_hook " " $vlist "
5051
+ return 1
5052
+ fi
5053
+
5054
+ if ! " $_deploy_fn " " $d " " $token " " $keyauthorization " ; then
5055
+ _err " Error deploying HTTP challenge for domain: $d "
5056
+ _cleanup_http_entries
5057
+ _clearup
5058
+ _on_issue_err " $_post_hook " " $vlist "
5059
+ return 1
5060
+ fi
5061
+
5062
+ _http_entries=" ${_http_entries}${d}${sep}${token}${sep}${keyauthorization}${sep}${_currentRoot}${dvsep} "
5063
+ else
5064
+ # Fall back to normal webroot challenge if no hook is found
5065
+ _info " No HTTP API hook found for $_currentRoot , falling back to normal validation"
5066
+ if [ " $_currentRoot " = " apache" ]; then
5067
+ wellknown_path=" $ACME_DIR "
5068
+ else
5069
+ wellknown_path=" $_currentRoot /.well-known/acme-challenge"
5070
+ if [ ! -d " $_currentRoot /.well-known" ]; then
5071
+ removelevel=' 1'
5072
+ elif [ ! -d " $_currentRoot /.well-known/acme-challenge" ]; then
5073
+ removelevel=' 2'
5074
+ else
5075
+ removelevel=' 3'
5076
+ fi
5077
+ fi
5078
+ fi
4990
5079
else
4991
5080
if [ " $_currentRoot " = " apache" ]; then
4992
5081
wellknown_path=" $ACME_DIR "
@@ -7073,6 +7162,7 @@ Parameters:
7073
7162
7074
7163
--password <password> Add a password to exported pfx file. Use with --to-pkcs12.
7075
7164
7165
+ --http-api <provider> Use HTTP API for challenge validation
7076
7166
7077
7167
"
7078
7168
}
@@ -7351,6 +7441,7 @@ _process() {
7351
7441
_preferred_chain=" "
7352
7442
_valid_from=" "
7353
7443
_valid_to=" "
7444
+ _http_api=" "
7354
7445
while [ ${# } -gt 0 ]; do
7355
7446
case " ${1} " in
7356
7447
@@ -7873,6 +7964,18 @@ _process() {
7873
7964
_preferred_chain=" $2 "
7874
7965
shift
7875
7966
;;
7967
+ --http-api)
7968
+ wvalue=" $W_HTTPAPI "
7969
+ if [ " $2 " ] && ! _startswith " $2 " " -" ; then
7970
+ wvalue=" $2 "
7971
+ shift
7972
+ fi
7973
+ if [ -z " $_webroot " ]; then
7974
+ _webroot=" $wvalue "
7975
+ else
7976
+ _webroot=" $_webroot ,$wvalue "
7977
+ fi
7978
+ ;;
7876
7979
* )
7877
7980
_err " Unknown parameter: $1 "
7878
7981
return 1
0 commit comments