# Browser HTTPS by static public IP

The browser-enabled Host package includes Let’s Encrypt enrollment and renewal
in `maximizer-browser certificates`. Customers need one Host package; Go,
Certbot, DNS records and a separate streaming server are not required.

Use the gaming Host's static **public IP**, for example `https://203.0.113.10:8443`
(replace this documentation address with the assigned IP). For IPv6, the URL
uses brackets: `https://[PUBLIC_IPV6]:8443`. Do not use the viewer's IP.

## Network and certificate lifetime

- Allow inbound **TCP 80** to this Host for HTTP-01 validation, both initially and
  on future renewals. The listener serves only the active challenge for the
  configured IP and exits after issuance. It does not serve the login page.
- Allow inbound **TCP and UDP 8443** (or the configured browser port) for HTTPS
  and WebTransport. A TCP-only reverse proxy cannot carry WebTransport.
- Allow outbound HTTPS to Let’s Encrypt and maintain a correct system clock.
- If port 80 is already served by another application, forward only
  `/.well-known/acme-challenge/` to the configured `http_listen` address while
  preserving the IP Host header. Public validation still uses port 80. This
  implementation uses HTTP-01; it does not seize another service's port or edit
  firewall/NAT rules. If public TCP80 is unavailable, resolve that before enrollment.

Let’s Encrypt's `shortlived` profile supports IP SANs and currently issues
**160-hour** certificates. The packaged timer checks hourly, including after
boot. ACME Renewal Information (ARI) determines a persisted randomized renewal
time; without ARI, renewal starts halfway through the certificate's lifetime.
A safety deadline retains at least 24 hours for retries for a 160-hour certificate.
Failures retain the previous certificate, back off across process restarts
(1/2/4/6 hours plus jitter), and honor CA rate-limit Retry-After. Monitor failed
jobs and the certificate expiry; the streaming helper also logs a 24-hour warning.

## Linux DEB/RPM setup

These commands are **operator setup instructions**, not actions run by the
installer. Replace `gaminguser` with the account that runs the Host, and replace
the IP/email. Examples assume the package prefix `/usr`; an installation built
with another prefix places the assets under that prefix's `share/sunshine`.

1. Copy the packaged units and enrollment example:

   ```sh
   sudo install -d -m 755 /etc/maximizer-browser
   sudo install -m 644 /usr/share/sunshine/browser/systemd/maximizer-browser-certificates@.service /etc/systemd/system/
   sudo install -m 644 /usr/share/sunshine/browser/systemd/maximizer-browser-certificates@.timer /etc/systemd/system/
   sudo install -m 644 /usr/share/sunshine/browser/certificates.example.json /etc/maximizer-browser/certificates-gaminguser.json
   sudoedit /etc/maximizer-browser/certificates-gaminguser.json
   ```

2. Set the assigned public IP, an optional contact email, and `agree_tos: true`
   after reviewing the [Subscriber Agreement](https://letsencrypt.org/repository/).
   Keep `staging: true` for the first validation attempt:

   ```json
   {
     "ip": "203.0.113.10",
     "email": "operator@example.com",
     "agree_tos": true,
     "staging": true,
     "http_listen": ":80"
   }
   ```

3. Run staging validation and check its result:

   ```sh
   sudo systemctl daemon-reload
   sudo systemctl start maximizer-browser-certificates@gaminguser.service
   sudo journalctl -u maximizer-browser-certificates@gaminguser.service -n 40
   ```

   Staging certificates are **not browser-trusted**. They are stored separately
   and never replace production certificates. After staging succeeds, change
   only `staging` to `false`, run the service again, then enable the hourly timer:

   ```sh
   sudo systemctl start maximizer-browser-certificates@gaminguser.service
   sudo systemctl enable --now maximizer-browser-certificates@gaminguser.timer
   systemctl list-timers 'maximizer-browser-certificates@*'
   ```

4. Configure the Host, using the **same combined PEM for both paths**:

   ```ini
   browser_enable = enabled
   browser_port = 8443
   browser_origin = https://203.0.113.10:8443
   browser_tls_cert = /var/lib/maximizer-browser/gaminguser/production/203.0.113.10/tls.pem
   browser_tls_key = /var/lib/maximizer-browser/gaminguser/production/203.0.113.10/tls.pem
   ```

   For an IPv6 state directory, replace colons in the canonical IP with
   underscores. The command logs the exact output path. Create a Host **Users**
   streaming account and retain `auth_method=both` or `password`. Restart the
   Host once to enable browser hosting, then open the configured origin.

The certificate service runs as the Host account with only the additional
`CAP_NET_BIND_SERVICE` capability needed for TCP80. Persistent state is private
to that account (0700 directories, 0600 files). The streaming process does not
need this capability. Certificates continue to renew while that process is idle
or stopped, provided the machine and timer are running.

The packaged system service requires a native installed executable outside the
user's home directory. Flatpak/AppImage hosting needs an operator-managed native
certificate job and accessible private PEM paths; those sandbox deployments are
not configured by these systemd templates.

## Windows hosting

The same bundled executable supports the same command and JSON. Store its state
outside Program Files, for example `C:\ProgramData\Maximizer\BrowserTLS`, with
inheritance disabled and ACLs limited to Administrators, SYSTEM and the actual
Host service account. Windows permissions require ACLs; Unix mode bits are not
an ACL substitute. Preserve these ACLs on the state directory so new files inherit
them. Use an administrator-managed Task Scheduler task running under the same
account with access to this private state:

```powershell
& 'C:\Program Files\Sunshine\assets\browser\maximizer-browser.exe' certificates --config 'C:\ProgramData\Maximizer\browser-certificates.json' --state 'C:\ProgramData\Maximizer\BrowserTLS'
```

Use the actual installed helper path if different. Complete staging, then
production enrollment. Configure the task **At startup and every hour**, run
whether logged on or not, start missed tasks when available, do not start another
instance while one is running, and impose a ten-minute execution limit. Configure
Host certificate/key paths to the resulting `production\PUBLIC_IP\tls.pem`.
Keep TCP80 validation and TCP/UDP streaming routing available. The binary is
cross-built on Linux; native Windows task/ACL/runtime acceptance is separate.

## Renewal and recovery behavior

- Account keys are saved before registration; lost responses reuse the same key.
  State is isolated by production/staging and IP, and process-level OS locking
  prevents concurrent enrollment jobs. Registration/certificate keys survive
  upgrades and restarts. Back up private state securely; never commit or log it.
- Every issuance requests a single IP SAN, `shortlived` profile and a new P-256
  certificate key. Renewal orders include the previous ARI certificate ID.
  Returned identity, key match, time validity, IP, usage and chain are checked
  before publication. Production verifies against the system public trust store.
- Certificate and key are flushed and atomically published as one `tls.pem`.
  A crash between PEM and metadata publication is recovered from the actual PEM.
  Corrupt account state is rejected rather than silently creating a new account.
- The streaming helper checks its files every five seconds, validates replacements
  against the configured origin, and atomically switches the identity used by
  **both HTTPS and HTTP/3**. Existing sessions keep running. Invalid, incomplete,
  mismatched, not-yet-valid or expired replacements leave the last valid identity
  in memory; an expired active identity is rejected for certificate handshakes.
  Do not restart the Host or helper in a renewal hook.
- Complete initial production enrollment before enabling browser hosting. If the
  machine was off past expiry, run the certificate job successfully before
  starting browser hosting. Native streaming has its own certificate lifecycle.
- Keep each host's private state separate. Do not include account keys or issued
  certificates in a shared golden image. If the assigned IP changes, enroll for
  the new IP and update origin/paths; a certificate for the old IP cannot cover it.
- Do not repeatedly delete state or force issuance to work around validation
  failures. Diagnose TCP80 reachability, task permissions, system clock and the
  logged CA error. The last valid certificate is not deleted on renewal failure.

References: [Let’s Encrypt profiles](https://letsencrypt.org/docs/profiles/),
[HTTP-01 validation](https://letsencrypt.org/docs/challenge-types/),
[rate limits](https://letsencrypt.org/docs/rate-limits/). ACME library: pinned
`github.com/go-acme/lego/v4 v4.35.2` (MIT).
