When a TLS connection arrives with an SNI for a domain that has no certificate yet, we want to automatically kick off certificate issuance (ACME HTTP-01 or DNS-01) so the domain is provisioned on the fly without prior manual configuration.
- In `ts/networkproxy/classes.np.networkproxy.ts` (or within `CertificateManager.handleSNI`), after looking up `certificateCache`, if no cert is found:
- Return HTTP 503 with a message like “Certificate issuance in progress.”
3. CertProvisioner & events:
- Ensure `CertProvisioner` is subscribed to `Port80Handler` for newly added domains.
- After certificate issuance completes, `Port80Handler` emits `CERTIFICATE_ISSUED`, `CertificateManager` caches and writes disk, and future SNI callbacks will serve the new cert.
4. Metrics and cleanup:
- Track dynamic requests count via a `certificateRequested` event or metric.
- Handle error paths: if ACME/DNS fails, emit `CERTIFICATE_FAILED` and continue serving default cert.
5. Tests:
- Simulate a TLS ClientHello for an unconfigured domain:
• Verify `port80Handler.addDomain` is called and `certificateRequested` event emitted.
• Confirm handshake completes with default cert context.
- Simulate HTTP-01 challenge flow for a new domain:
• Verify on first HTTP request, `addDomain` is invoked and 503 returned.
• After manually injecting a challenge in `Http01MemoryHandler`, verify 200 with key authorization.
- Simulate successful ACME response and ensure SNI now returns the real cert.
6. Final validation:
- Run `pnpm test` to ensure all existing tests pass.
- Add new unit/integration tests for the dynamic provisioning flow.