# Browser HTTPS by static public IP

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

## Automatic first-time setup (Linux browser-enabled DEB)

1. In the Host Web UI, create a **Users streaming account**. Keep authentication
   set to **Both** to retain existing PIN pairing. The separate administrative
   Web UI password is not a browser streaming account.
2. Open **Configuration → Network → Desktop Browser Client**. Enable browser
   streaming and choose **Automatic Let’s Encrypt**. Review and explicitly accept
   the linked Subscriber Agreement, then **Save and Apply while idle**.
3. Watch **Browser HTTPS** on that page. The Host detects its public IPv4 through
   a direct, bounded HTTPS request to `api.ipify.org`, requests a trusted IP
   certificate, derives the HTTPS origin and private paths, and starts HTTPS and
   HTTP/3. Open the client link once status is **ready**.

There are **no certificate-path, JSON, service or renewal-timer setup commands**
in automatic mode. An assigned stable public IPv4/IPv6 and contact email can be
supplied under Optional settings, but neither is required for public-IPv4 discovery.
The installer never accepts the CA agreement or contacts a CA on the user's behalf.
An account/order is made only after explicit opt-in and agreement.

State is saved under `browser-https/production/IP/` next to the Host's configuration
file (IPv6 colons become underscores), with 0700 directories and 0600 account/PEM
files. Back up this private state securely. Never clone it into shared images.
The Linux package grants only `CAP_NET_BIND_SERVICE` to the root-owned bundled
helper for HTTP-01 TCP80; no root web server or router/firewall modifications.
An incompatible filesystem capability policy or blocked port is reported in the
Host logs/status, not bypassed with an insecure certificate.

The running Host/helper checks renewal hourly, uses the persisted ARI/backoff
schedule below, and reloads renewed certificates without interrupting active
streams. While the Host is stopped, automatic-mode renewal is stopped too. If its
certificate expires while off, the next start enrolls/renews **before** browser
TLS is accepted; native Host startup does not wait for CA validation. Keep the
machine running and TCP80 reachable to renew before expiration.

Existing deployments with certificate paths and no explicit `browser_tls_mode`
retain **manual** mode, including their existing account state and timers. Selecting
automatic mode removes only manual configuration references, never certificate
files. Switching back to manual requires supplying the previous paths again.
Automatic mode is currently Linux-only; Windows retains the manual method below.
Use a stable public IP. After an IP change, update any override and restart the
Host so discovery/enrollment selects the new IP; old IP state is retained.

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.
- In manual mode, 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. Automatic mode checks while the Host runs; the optional
manual 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.

## Optional manual 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_tls_mode = manual
   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.

In this manual arrangement, 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 native streaming Host does not
need this capability. Certificates continue to renew while the streaming 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.
- Manual mode requires initial production enrollment before enabling browser
  hosting, and a successful certificate job after an off period past expiry.
  Automatic mode does both itself. 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 manual origin/paths (or restart automatic discovery);
  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).
