refactor: reorganize certificate structure and improve hostname provisioning system

This commit is contained in:
2025-06-29 16:42:01 +02:00
parent 402b5faae6
commit 907c55164f
22 changed files with 296 additions and 394 deletions
+33 -55
View File
@@ -13,11 +13,11 @@ This project provides a dual-port Streamlit server setup for local networks:
### Usage
1. **Generate Certificates**
- Run `generate_ca_and_device_cert.sh` in `src/auracast/server/`.
- Run `generate_ca_cert.sh` in `src/auracast/server/`.
- This creates:
- `ca_cert.pem` / `ca_key.pem` (CA cert/key)
- `device_cert.pem` / `device_key.pem` (device/server cert/key)
- **Distribute `ca_cert.pem` to customers** for installation in their trust store.
- `certs/ca/ca_cert.pem` / `ca_key.pem` (CA cert/key)
- **Distribute `ca_cert.pem` or `ca_cert.crt` to customers** for installation in their trust store.
- This is a one-time operation for your organization.
2. **Start the Server**
- Run `run_http_and_https.sh` in `src/auracast/server/`.
@@ -35,57 +35,13 @@ This project provides a dual-port Streamlit server setup for local networks:
- HTTP is also available for compatibility/testing.
### Advertise Hostname with mDNS
To make your device discoverable as `your-hostname.your-domain.local` (e.g., `box1.auracast.local`) using mDNS/Avahi, you need to:
#### Manual Method (Step-by-Step)
1. **Set the Hostname (Single Label, No Dots)**
- Choose a simple hostname, e.g., `box1` or `auracast-box1` (do **not** use dots).
- Set it:
```bash
sudo hostnamectl set-hostname <your-new-hostname>
```
2. **Update `/etc/hosts` for Local Resolution**
- Ensure `127.0.1.1` maps to your new hostname:
```bash
sudo grep -q '^127.0.1.1' /etc/hosts && sudo sed -i 's/^127.0.1.1.*/127.0.1.1 <your-new-hostname>/' /etc/hosts || echo '127.0.1.1 <your-new-hostname>' | sudo tee -a /etc/hosts
```
3. **Configure Avahi Domain Name**
- Edit the Avahi config:
```bash
sudo nano /etc/avahi/avahi-daemon.conf
```
- In the `[server]` section, set or add:
```ini
domain-name=auracast.local
```
- Save and close the file.
- Restart Avahi:
```bash
sudo systemctl restart avahi-daemon
```
4. **(Optional) One-liner for Avahi Domain**
```bash
DESIRED_DOMAIN="auracast.local"; sudo sed -i -E '/^\[server\]/,/^\s*\[/{s/^\s*(#\s*)?domain-name\s*=.*/domain-name='"$DESIRED_DOMAIN"'/}' /etc/avahi/avahi-daemon.conf && sudo systemctl restart avahi-daemon
```
---
#### Automated Method (Recommended for Most Users)
Instead of the manual steps above, you can use the provided script to perform all actions safely and atomically:
```bash
cd src/auracast/server
sudo ./change_domain_hostname.sh <new_hostname> <new_domain>
sudo ./provision_domain_hostname.sh <new_hostname> <new_domain>
```
- Example:
```bash
sudo ./change_domain_hostname.sh box1 auracast.local
sudo ./provision_domain_hostname.sh box1 auracast.local
```
- The script will:
- Validate your input (no dots in hostname)
@@ -93,13 +49,12 @@ sudo ./change_domain_hostname.sh <new_hostname> <new_domain>
- Update `/etc/hosts`
- Set the Avahi domain in `/etc/avahi/avahi-daemon.conf`
- Restart Avahi
- Print status and error messages
Use the manual method if you want to understand or customize each step, or the script for a quick, reliable setup.
- Generate a unique per-device certificate and key signed by your CA, stored in `certs/per_device/<hostname>.<domain>/`.
- The certificate will have a SAN matching the device's mDNS name (e.g., `box1-summitwave.local`).
---
### Troubleshooting & Tips
- **Use .local domain** (e.g., `box1-summitwave.local`) - most clients will not resolve multi-label domains.
- **Hostnames must not contain dots** (`.`). Only use single-label names for the system hostname.
- **Avahi domain** can be multi-label (e.g., `auracast.local`).
- **Clients may need** `libnss-mdns` installed and `/etc/nsswitch.conf` configured with `mdns4_minimal` and `mdns4` for multi-label mDNS names.
@@ -108,4 +63,27 @@ Use the manual method if you want to understand or customize each step, or the s
---
After completing these steps, your device will be discoverable as `<hostname>.<domain>` (e.g., `box1.auracast.local`) on the local network via mDNS.
After completing these steps, your device will be discoverable as `<hostname>.<domain>` (e.g., `box1.auracast.local`) on the local network via mDNS.
---
## Checking Advertised mDNS Services
Once your device is configured, you can verify that its mDNS advertisement is visible on the network:
- **List all mDNS services:**
```bash
avahi-browse -a
```
Look for your hostname and service (e.g., `box1.auracast.local`).
- **Check specific hostname resolution:**
```bash
avahi-resolve-host-name box1.auracast.local
avahi-resolve-host-name -4 box1.auracast.local # IPv4 only
avahi-resolve-host-name -6 box1.auracast.local # IPv6 only
```
## Run the application with local webui
- for microphone streaming via the browser, https is required
- poetry run multicast_server.py
- sudo -E PATH="$PATH" bash ./start_frontend_https.sh
- bash start_mdns.sh