Skip to content

Commit

Permalink
Automatically update ACCOUNT_EMAIL (contact) in registration
Browse files Browse the repository at this point in the history
Also fixes bug that caused previous registrations to be invalid.
  • Loading branch information
tlhackque committed Mar 17, 2024
1 parent a30d054 commit e54ef1b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions getssl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
# 2023-02-22 Remove cronie from deb package dependencies (2.48)
# 2024-03-16 Use FTP_PORT when deleting ftp tokens. Delete tokens when using sftp, davfs, ftpes, ftps (#693,#839) (tlhackque)
# 2024 03-16 Fix dns-01's CNAME processing. (#840) (tlhackque)
# 2024-03-17 Automatically update the ACCOUNT_EMAIL (#827) (tlhackque)
# ----------------------------------------------------------------------------------------

case :$SHELLOPTS: in
Expand Down Expand Up @@ -3449,14 +3450,14 @@ info "Registering account"
# send the request to the ACME server.
if [[ $API -eq 1 ]]; then
if [[ "$ACCOUNT_EMAIL" ]] ; then
regjson='{"resource": "new-reg", "contact": ["mailto: '$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
regjson='{"resource": "new-reg", "contact": ["mailto:'$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
else
regjson='{"resource": "new-reg", "agreement": "'$AGREEMENT'"}'
fi
send_signed_request "$URL_new_reg" "$regjson"
elif [[ $API -eq 2 ]]; then
if [[ "$ACCOUNT_EMAIL" ]] ; then
regjson='{"termsOfServiceAgreed": true, "contact": ["mailto: '$ACCOUNT_EMAIL'"]}'
regjson='{"termsOfServiceAgreed": true, "contact": ["mailto:'$ACCOUNT_EMAIL'"]}'
else
regjson='{"termsOfServiceAgreed": true}'
fi
Expand All @@ -3479,6 +3480,23 @@ elif [[ "$code" == '200' ]] ; then
KID=$(echo "$responseHeaders" | grep -i "^location" | awk '{print $2}'| tr -d '\r\n ')
debug responseHeaders "$responseHeaders"
debug "Already registered account, AccountId=${KID}"
email="$(json_get "$response" "contact")"
if [[ "${email#mailto:}" != "$ACCOUNT_EMAIL" ]]; then
# Update account E-Mail (Note that a list is allowed by the RFC)
if [[ -n "$ACCOUNT_EMAIL" ]]; then
info "Updating account contact e-mail from '${email#mailto:}' to '$ACCOUNT_EMAIL'"
send_signed_request "$KID" '{"contact": ["mailto:'$ACCOUNT_EMAIL'"]}'
else
info "Removing account contact email '${email#mailto:}'"
send_signed_request "$KID" '{"contact": []}'
fi
if [[ "$code" == '200' ]]; then
info " - update succeeded"
else
info " - updaate failed"
fi
debug responseHeaders "$responseHeaders"
fi
else
error_exit "Error registering account ...$responseHeaders ... $(json_get "$response" detail)"
fi
Expand Down

0 comments on commit e54ef1b

Please sign in to comment.