@@ -59,7 +59,7 @@ query_le_v2() {
5959 # Save http response to file passed as "$4" arg or print to stdout if not provided
6060 # http response headers are always sent to stdout
6161 local save_to_file=${4:- " /dev/stdout" }
62- curl --location --insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout --data " $post_data " " $1 " --header " $content " --output " $save_to_file "
62+ curl --location --user-agent " HestiaCP " -- insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout --data " $post_data " " $1 " --header " $content " --output " $save_to_file "
6363 debug_log " API call" " exit status: $? "
6464}
6565
@@ -208,7 +208,7 @@ if [ -n "$DNS_SYSTEM" ]; then
208208fi
209209
210210# Requesting nonce / STEP 1
211- answer= $( curl -s -I " $LE_API /directory" )
211+ answer= $( curl --user-agent " HestiaCP " - s -I " $LE_API /directory" )
212212nonce= $( echo " $answer " | grep -i nonce | cut -f2 -d \ | tr -d ' \r\n' )
213213status= $( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
214214
@@ -242,8 +242,9 @@ nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \ | tr -d '\r\n')
242242authz= $( echo " $answer " | grep " acme/authz" | cut -f2 -d ' "' )
243243finalize= $( echo " $answer " | grep ' finalize":' | cut -f4 -d ' "' )
244244status= $( echo " $answer " | grep HTTP/ | tail -n1 | cut -f2 -d ' ' )
245+ order= $( echo -e " $answer " | grep -i location | cut -f2 -d \ | tr -d ' \r\n' )
245246
246- debug_log " Step 2" " - status: ${status} \n- nonce: ${nonce} \n- authz: ${authz} \n- finalize: ${finalize} \n- payload: ${payload} \n- answer: ${answer} "
247+ debug_log " Step 2" " - status: ${status} \n- nonce: ${nonce} \n- authz: ${authz} \n- finalize: ${finalize} \n- payload: ${payload} \n- answer: ${answer} \n order: ${order} "
247248
248249if [[ " $status " -ne 201 ]]; then
249250 # Delete DNS CAA record
@@ -461,6 +462,25 @@ if [[ "$status" -ne 200 ]]; then
461462 check_result " $E_CONNECT " " Let's Encrypt finalize bad status $status ($domain )"
462463fi
463464
465+ if [ -z " $certificate " ]; then
466+ validation=" processing"
467+ i=1
468+ while [ " $validation " = " processing" ]; do
469+ answer=$( query_le_v2 " $order " " " " $nonce " )
470+ i=$(( i + 1 ))
471+
472+ nonce=$( echo " $answer " | grep -i nonce | cut -f2 -d \ | tr -d ' \r\n' )
473+ status=$( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
474+ validation=$( echo " $answer " | grep ' status":' | cut -f4 -d ' "' )
475+ certificate=$( echo " $answer " | grep ' certificate":' | cut -f4 -d ' "' )
476+ sleep $(( i * 2 )) # Sleep for 2s, 4s, 6s, 8s
477+ if [ $i -gt 10 ]; then
478+ check_result " $E_CONNECT " " Certificate processing timeout ($domain )"
479+ fi
480+ debug_log " Step 7" " - status: ${status} \n- nonce: ${nonce} \n- payload: ${payload} \n- certificate: ${certificate} \n- answer: ${answer} "
481+ done
482+ fi
483+
464484# Downloading signed certificate / STEP 7
465485status= 0
466486retry= 0
@@ -470,7 +490,7 @@ while [[ $status != 200 && $retry -lt 3 ]]; do
470490 answer=$( query_le_v2 " $certificate " " " " $nonce " " $ssl_dir /$domain .pem" )
471491 status=$( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
472492
473- debug_log " Step 7 " " - status: ${status} \n- retry: ${retry} \n- answer: ${answer} "
493+ debug_log " Step 8 " " - status: ${status} \n- retry: ${retry} \n- answer: ${answer} "
474494
475495 if [[ $status != 200 ]]; then
476496 retry=$(( retry + 1 ))
@@ -481,10 +501,10 @@ done
481501
482502# Fallback on depreciated download method for certs (unauthenticated GET)
483503if [[ $status != 200 ]]; then
484- answer=$( curl --insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout " $certificate " --output " $ssl_dir /$domain .pem" )
504+ answer=$( curl --insecure --user-agent " HestiaCP " -- retry 5 --retry-connrefused --silent --dump-header /dev/stdout " $certificate " --output " $ssl_dir /$domain .pem" )
485505 status=$( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
486506
487- debug_log " Step 7 - Fallback" " - status: ${status} \n- answer: ${answer} "
507+ debug_log " Step 8 - Fallback" " - status: ${status} \n- answer: ${answer} "
488508fi
489509
490510debug_log " CERT DIR" " $( ls -las " $ssl_dir /" ) "
0 commit comments