Skip to content

feat(webrtc): stable /certhash across restarts#3512

Open
lidel wants to merge 1 commit into
masterfrom
feat/webrtc-direct-deterministic-cert
Open

feat(webrtc): stable /certhash across restarts#3512
lidel wants to merge 1 commit into
masterfrom
feat/webrtc-direct-deterministic-cert

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented May 28, 2026

Important

Opened as a draft to validate browser interop. Holding off on merge until the libp2p/test-plans matrix confirms Chrome and Firefox accept the static, century-long DTLS cert this PR introduces.
If tests fail, we may need to do what js-libp2p does and just mirror 14 day cert rotation webtransport has.

Problem

The webrtc-direct transport minted a fresh random ECDSA cert on every process start. The cert's SHA-256 is the /certhash component of the listen multiaddr, so the advertised address changed on every restart and invalidated any cached entry that pinned it (peerstore TTLs, DHT records, external address books, dialer caches).

Fix

Derive the DTLS cert deterministically from the libp2p host private key:

  • HKDF over the host key produces the cert serial and the ECDSA P-256 private key.
  • Signing routes through a wrapper that signs with a nil rand source; Go 1.24+ guarantees deterministic ECDSA in that case.
  • A hardcoded 2020-01-01 to 2120-01-01 validity window keeps DER bytes byte-stable across runs.

The resulting /certhash depends only on the host key, so it stays the same across restarts.

p2p/transport/webrtc/cert.go has the full rationale and links to the libp2p webrtc-direct spec, RFC 8122, the W3C WebRTC spec, and the relevant pion behavior we rely on.

Alternatives

If this PR is not acceptable, we could just mirror what js-libp2p does, and introduce 14 day cert rotation webtransport has. Still better than creating new one on restart.

Derive the webrtc-direct DTLS cert deterministically from the host
private key (HKDF + Go 1.24 deterministic ECDSA + hardcoded validity
window) so the /certhash multiaddr component depends only on the host
key. The advertised address no longer churns on every restart, and
cached peerstore/DHT entries stay valid.

cert.go documents why this is safe under the libp2p webrtc-direct spec
and current browser DTLS behavior.
@lidel lidel requested review from MarcoPolo and sukunrt May 28, 2026 11:34
@lidel lidel marked this pull request as ready for review May 28, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant