[GH-ISSUE #4875] [Bug]: SSL setup leaves broken acme.sh state on cert issuance failure, --install-cert hook not configured when using option 5 after manual #3405

Closed
opened 2026-10-31 20:32:12 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Mitrl on GitHub (Jun 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4875

Describe the bug

When the Let's Encrypt certificate issuance fails during the initial install (e.g. due to an ACME account sync race condition), the installer leaves behind a partial acme.sh domain configuration. Subsequent attempts via menu option 19 → 1 incorrectly detect this broken state as an "existing certificate" and attempt to reuse it, resulting in an empty fullchain.pem (0 bytes). Additionally, menu option 19 → 5 only updates x-ui's internal cert path config but does not set up the acme.sh --install-cert hook, so auto-renewal silently stops copying the renewed cert to the configured paths.

How to reproduce the problem

Steps to reproduce
1.Run the install script. During SSL setup, choose option 1 (Let's Encrypt for Domain). The issuance fails (e.g. ACME accountDoesNotExist error on a fresh acme.sh install).
2.Installation completes without SSL. Enter the panel and go to menu 19 → 1 to retry.
3.The script detects the partial acme.sh config as "Existing certificate found" and skips re-issuance, producing an empty fullchain.pem.
4.Manually delete the broken state and run acme.sh --issue to obtain a valid cert.
5.Go to menu 19 → 5 to set cert paths for the panel. This updates x-ui's config but does not register the --install-cert hook in acme.sh.
6.Verify with acme.sh --info -d : Le_RealCertPath and Le_RealCACertPath are empty; Le_RealFullChainPath may also be unset depending on the path taken.

Expected behavior

On cert issuance failure, the installer should clean up the partial acme.sh domain config and cert directory, not leave broken state behind.
Menu option 19 → 1 should verify that a detected "existing certificate" actually contains valid, non-empty files before reusing it.
Menu option 19 → 5 should also run acme.sh --install-cert with the configured paths and --reloadcmd "x-ui restart" to ensure auto-renewal copies the cert to the correct location.

Actual behavior

Partial acme.sh state persists after failed issuance.
fullchain.pem is created as an empty file (0 bytes).
After manual cert issuance + using option 5, the --install-cert hook is not registered; auto-renewal will not copy the renewed cert to x-ui's configured paths.

Relevant logs

[...] Error getting authz.
[...] _authorizations_map=',{"type":"urn:ietf:params:acme:error:accountDoesNotExist",
      "detail":"Unable to validate JWS :: Account \"https://acme-v02.api.letsencrypt.org
      /acme/acct/[ACCOUNT_ID]\" not found","status": 400}'
Issuing certificate failed, please check logs.
SSL certificate setup failed for domain mode.

[INF] Existing certificate found for example.com, will reuse it.
[INF] Using existing certificate, installing certificates...
cat: /root/.acme.sh/example.com_ecc/fullchain.cer: No such file or directory

-rw-r--r-- 1 root root    0 Jun  3 14:22 fullchain.pem
-rw------- 1 root root  227 Jun  3 14:22 privkey.pem

Le_RealCertPath=
Le_RealCACertPath=
Le_RealKeyPath=/root/cert/example.com/privkey.pem
Le_ReloadCmd=x-ui restart
Le_RealFullChainPath=/root/cert/example.com/fullchain.pem

Screenshots

No response

3x-ui version

v3.2.6

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Debian 13.5

Which parts of the panel are affected?

Install / upgrade script

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @Mitrl on GitHub (Jun 3, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4875 ### Describe the bug When the Let's Encrypt certificate issuance fails during the initial install (e.g. due to an ACME account sync race condition), the installer leaves behind a partial acme.sh domain configuration. Subsequent attempts via menu option 19 → 1 incorrectly detect this broken state as an "existing certificate" and attempt to reuse it, resulting in an empty fullchain.pem (0 bytes). Additionally, menu option 19 → 5 only updates x-ui's internal cert path config but does not set up the acme.sh --install-cert hook, so auto-renewal silently stops copying the renewed cert to the configured paths. ### How to reproduce the problem Steps to reproduce 1.Run the install script. During SSL setup, choose option 1 (Let's Encrypt for Domain). The issuance fails (e.g. ACME accountDoesNotExist error on a fresh acme.sh install). 2.Installation completes without SSL. Enter the panel and go to menu 19 → 1 to retry. 3.The script detects the partial acme.sh config as "Existing certificate found" and skips re-issuance, producing an empty fullchain.pem. 4.Manually delete the broken state and run acme.sh --issue to obtain a valid cert. 5.Go to menu 19 → 5 to set cert paths for the panel. This updates x-ui's config but does not register the --install-cert hook in acme.sh. 6.Verify with acme.sh --info -d <domain>: Le_RealCertPath and Le_RealCACertPath are empty; Le_RealFullChainPath may also be unset depending on the path taken. ### Expected behavior On cert issuance failure, the installer should clean up the partial acme.sh domain config and cert directory, not leave broken state behind. Menu option 19 → 1 should verify that a detected "existing certificate" actually contains valid, non-empty files before reusing it. Menu option 19 → 5 should also run acme.sh --install-cert with the configured paths and --reloadcmd "x-ui restart" to ensure auto-renewal copies the cert to the correct location. ### Actual behavior Partial acme.sh state persists after failed issuance. fullchain.pem is created as an empty file (0 bytes). After manual cert issuance + using option 5, the --install-cert hook is not registered; auto-renewal will not copy the renewed cert to x-ui's configured paths. ### Relevant logs ```shell [...] Error getting authz. [...] _authorizations_map=',{"type":"urn:ietf:params:acme:error:accountDoesNotExist", "detail":"Unable to validate JWS :: Account \"https://acme-v02.api.letsencrypt.org /acme/acct/[ACCOUNT_ID]\" not found","status": 400}' Issuing certificate failed, please check logs. SSL certificate setup failed for domain mode. [INF] Existing certificate found for example.com, will reuse it. [INF] Using existing certificate, installing certificates... cat: /root/.acme.sh/example.com_ecc/fullchain.cer: No such file or directory -rw-r--r-- 1 root root 0 Jun 3 14:22 fullchain.pem -rw------- 1 root root 227 Jun 3 14:22 privkey.pem Le_RealCertPath= Le_RealCACertPath= Le_RealKeyPath=/root/cert/example.com/privkey.pem Le_ReloadCmd=x-ui restart Le_RealFullChainPath=/root/cert/example.com/fullchain.pem ``` ### Screenshots _No response_ ### 3x-ui version v3.2.6 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Debian 13.5 ### Which parts of the panel are affected? Install / upgrade script ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:32:12 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 3, 2026):

Thanks for the detailed report and the clear reproduction steps. I've reviewed the relevant code and can confirm all three issues you described.


Issue 1: Partial acme.sh state after failed issuance

In install.sh (line ~300) and x-ui.sh (ssl_cert_issue, line 1614), the cleanup on failure does:

rm -rf ~/.acme.sh/${domain}

However, acme.sh defaults to ECC (ECDSA) keys and stores those in ~/.acme.sh/${domain}_ecc/, not ~/.acme.sh/${domain}/. So the ECC directory is not removed on failure. After the install-time failure, ~/.acme.sh/${domain}_ecc/ persists with partial state.

Issue 2: "Existing certificate" check has no file validity guard

In ssl_cert_issue() (x-ui.sh, line 1581), the check that sets cert_exists=1 is:

if ~/.acme.sh/acme.sh --list 2>/dev/null | awk '{print $1}' | grep -Fxq "${domain}"; then

This detects an acme.sh domain entry (from the leftover _ecc/ directory) and immediately sets cert_exists=1, skipping re-issuance entirely (line 1608). It then goes straight to --installcert, which attempts to copy ~/.acme.sh/${domain}_ecc/fullchain.cer — a file that never existed because issuance failed. The result is the 0-byte fullchain.pem you observed.

A missing guard here would be: check that both ~/.acme.sh/${domain}_ecc/fullchain.cer (or ~/.acme.sh/${domain}/fullchain.cer) and the key file are non-empty before trusting cert_exists=1.

Issue 3: Option 5 ("Set Cert paths for the panel") skips the --installcert hook

In ssl_cert_issue_main() (x-ui.sh, lines 1254–1279), option 5 only calls:

${xui_folder}/x-ui cert -webCert "$webCertFile" -webCertKey "$webKeyFile"

This writes the paths into x-ui's settings but never calls acme.sh --installcert. As a result, acme.sh's domain config (~/.acme.sh/${domain}_ecc/${domain}.conf) never gets Le_RealKeyPath, Le_RealFullChainPath, or Le_ReloadCmd set. Auto-renewal will trigger a new certificate but will not copy it to /root/cert/${domain}/ and will not restart x-ui.

This matches exactly what you observed with acme.sh --info -d <domain> showing empty Le_RealCertPath / Le_RealCACertPath / Le_RealFullChainPath.


Workarounds until a fix lands

For bug 1 & 2 — clean the broken state, then re-issue normally via menu option 19 → 1:

# Remove both RSA and ECC partial state for your domain
rm -rf ~/.acme.sh/<your-domain> ~/.acme.sh/<your-domain>_ecc
# Also remove the empty cert directory so option 1 starts fresh
rm -rf /root/cert/<your-domain>

Then run x-ui → option 19 → option 1 to re-issue.

For bug 3 — after option 5 has set the x-ui cert paths, manually register the acme.sh --installcert hook so renewals copy the cert and restart the panel:

~/.acme.sh/acme.sh --installcert -d <your-domain> \
  --key-file /root/cert/<your-domain>/privkey.pem \
  --fullchain-file /root/cert/<your-domain>/fullchain.pem \
  --reloadcmd "x-ui restart"

Then verify with:

~/.acme.sh/acme.sh --info -d <your-domain>

You should see Le_RealKeyPath, Le_RealFullChainPath, and Le_ReloadCmd all populated.

<!-- gh-comment-id:4616000474 --> @github-actions[bot] commented on GitHub (Jun 3, 2026): Thanks for the detailed report and the clear reproduction steps. I've reviewed the relevant code and can confirm all three issues you described. --- ## Issue 1: Partial acme.sh state after failed issuance In `install.sh` (line ~300) and `x-ui.sh` (`ssl_cert_issue`, line 1614), the cleanup on failure does: ```bash rm -rf ~/.acme.sh/${domain} ``` However, acme.sh defaults to ECC (ECDSA) keys and stores those in **`~/.acme.sh/${domain}_ecc/`**, not `~/.acme.sh/${domain}/`. So the ECC directory is **not removed** on failure. After the install-time failure, `~/.acme.sh/${domain}_ecc/` persists with partial state. ## Issue 2: "Existing certificate" check has no file validity guard In `ssl_cert_issue()` (x-ui.sh, line 1581), the check that sets `cert_exists=1` is: ```bash if ~/.acme.sh/acme.sh --list 2>/dev/null | awk '{print $1}' | grep -Fxq "${domain}"; then ``` This detects an acme.sh domain entry (from the leftover `_ecc/` directory) and immediately sets `cert_exists=1`, skipping re-issuance entirely (line 1608). It then goes straight to `--installcert`, which attempts to copy `~/.acme.sh/${domain}_ecc/fullchain.cer` — a file that never existed because issuance failed. The result is the 0-byte `fullchain.pem` you observed. A missing guard here would be: check that both `~/.acme.sh/${domain}_ecc/fullchain.cer` (or `~/.acme.sh/${domain}/fullchain.cer`) and the key file are non-empty before trusting `cert_exists=1`. ## Issue 3: Option 5 ("Set Cert paths for the panel") skips the `--installcert` hook In `ssl_cert_issue_main()` (x-ui.sh, lines 1254–1279), option 5 only calls: ```bash ${xui_folder}/x-ui cert -webCert "$webCertFile" -webCertKey "$webKeyFile" ``` This writes the paths into x-ui's settings but **never calls `acme.sh --installcert`**. As a result, acme.sh's domain config (`~/.acme.sh/${domain}_ecc/${domain}.conf`) never gets `Le_RealKeyPath`, `Le_RealFullChainPath`, or `Le_ReloadCmd` set. Auto-renewal will trigger a new certificate but will not copy it to `/root/cert/${domain}/` and will not restart x-ui. This matches exactly what you observed with `acme.sh --info -d <domain>` showing empty `Le_RealCertPath` / `Le_RealCACertPath` / `Le_RealFullChainPath`. --- ## Workarounds until a fix lands **For bug 1 & 2** — clean the broken state, then re-issue normally via menu option 19 → 1: ```bash # Remove both RSA and ECC partial state for your domain rm -rf ~/.acme.sh/<your-domain> ~/.acme.sh/<your-domain>_ecc # Also remove the empty cert directory so option 1 starts fresh rm -rf /root/cert/<your-domain> ``` Then run `x-ui` → option 19 → option 1 to re-issue. **For bug 3** — after option 5 has set the x-ui cert paths, manually register the acme.sh `--installcert` hook so renewals copy the cert and restart the panel: ```bash ~/.acme.sh/acme.sh --installcert -d <your-domain> \ --key-file /root/cert/<your-domain>/privkey.pem \ --fullchain-file /root/cert/<your-domain>/fullchain.pem \ --reloadcmd "x-ui restart" ``` Then verify with: ```bash ~/.acme.sh/acme.sh --info -d <your-domain> ``` You should see `Le_RealKeyPath`, `Le_RealFullChainPath`, and `Le_ReloadCmd` all populated.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3405
No description provided.