Cloudflare Worker API for boneIO Black PWA - handles DNS registration and SSL certificate distribution.
- DNS Registration: Devices register their serial + local IP → creates
{serial}.black.boneio.appDNS record - SSL Certificate Distribution: Wildcard cert for
*.black.boneio.appdistributed to devices - HMAC Authentication: Device tokens derived from serial + shared secret (HMAC-SHA256)
- Private IP Validation: Only private IP ranges allowed (10.x, 172.16-31.x, 192.168.x)
- Rate Limiting: 10 requests/hour per IP to prevent abuse
All endpoints (except /health) require HMAC-SHA256 authentication.
The device computes its token as HMAC-SHA256(MASTER_SECRET, serial) and sends it in the Authorization header:
Authorization: Bearer <hmac-hex>
Python example:
import hmac, hashlib
token = hmac.new(MASTER_SECRET.encode(), serial.encode(), hashlib.sha256).hexdigest()| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /register |
HMAC | Register/update device DNS |
| GET | /cert?serial=blkXXXXXX |
HMAC | Get SSL certificate (device must be registered) |
| GET | /health |
None | Health check |
Headers:
Authorization: Bearer <hmac-token>
Body:
{
"serial": "blkf8dc18",
"ip": "192.168.1.100"
}Response:
{
"success": true,
"domain": "blkf8dc18.black.boneio.app",
"ip": "192.168.1.100"
}Headers:
Authorization: Bearer <hmac-token>
Response:
{
"cert": "base64-encoded-certificate",
"key": "base64-encoded-private-key",
"domain": "*.black.boneio.app",
"expiresAt": "2024-03-15T00:00:00Z"
}wrangler kv:namespace create BONEIO_KVUpdate wrangler.toml with the returned namespace ID.
wrangler secret put CF_API_TOKEN # Cloudflare API token with DNS edit
wrangler secret put CF_ZONE_ID # Zone ID for boneio.app
wrangler secret put MASTER_SECRET # Shared secret for HMAC device authCF_API_TOKEN- Cloudflare API token (Workers deploy)CF_DNS_API_TOKEN- Cloudflare API token (DNS edit for cert)CF_ACCOUNT_ID- Cloudflare account IDCF_ZONE_ID- Zone ID for boneio.appCF_KV_NAMESPACE_ID- KV namespace IDMASTER_SECRET- Shared secret for HMAC device authenticationCERT_EMAIL- Email for Let's Encrypt
npm install
npm run deployRun the "Renew SSL Certificate" workflow manually to generate the first certificate.
npm install
npm run dev