PhoenixWebTransport.Cert (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Development certificate for the WebTransport listener.

Chrome only accepts a self-signed certificate through the serverCertificateHashes option, and that option requires an ECDSA P-256 key and a validity window of at most 14 days. A mix phx.gen.cert RSA certificate is rejected, so this module generates its own 13-day ECDSA P-256 cert directly in pure Erlang (:public_key) with zero external CLI dependencies, and exposes the SHA-256 of the DER encoding for the page to pin.

Production deployments terminate QUIC with a publicly trusted certificate and never use this module.

Summary

Functions

Ensures a fresh cert/key pair exists in dir and returns their paths.

Generates an in-memory 13-day ECDSA P-256 self-signed DER certificate and ECPrivateKey record suitable for localhost / loopback WebTransport dev servers.

Lowercase hex SHA-256 of the certificate's DER bytes.

Functions

ensure!(dir)

@spec ensure!(Path.t()) :: {Path.t(), Path.t()}

Ensures a fresh cert/key pair exists in dir and returns their paths.

generate_keypair(opts \\ [])

@spec generate_keypair(keyword()) :: {binary(), tuple()}

Generates an in-memory 13-day ECDSA P-256 self-signed DER certificate and ECPrivateKey record suitable for localhost / loopback WebTransport dev servers.

hash_hex(cert_path)

@spec hash_hex(Path.t()) :: String.t()

Lowercase hex SHA-256 of the certificate's DER bytes.