webrtc_dtls_cert (webrtc v0.1.0)
View SourceCertificates for DTLS in WebRTC.
WebRTC endpoints use self-signed certificates whose identity is the fingerprint carried in SDP (RFC 8122, RFC 8827 §6.5). This module generates such certificates, computes and formats fingerprints, and extracts the public key used to check handshake signatures.
Summary
Functions
Fingerprint of a DER certificate (RFC 8122 §5).
Format as in SDP: sha-256 AB:CD:....
Generate an ECDSA P-256 self-signed certificate (the algorithm browsers use by default).
Options: key is ecdsa_p256 (default) or {rsa, Bits}; common_name (binary); days of validity (default 30).
True when the DER certificate matches one of the fingerprints. RFC 8122 §5: a match with any fingerprint whose hash is supported is sufficient. SHA-1 and SHA-224 fingerprints are ignored: they are not strong enough to bind the certificate. Comparison is constant time.
Parse the value of an a=fingerprint attribute.
Public key of a DER certificate, in the form accepted by public_key:verify/4.
Types
-type cert() :: #{der := binary(), key := public_key:private_key()}.
-type hash() :: sha | sha224 | sha256 | sha384 | sha512.
Functions
-spec fingerprint(hash(), binary()) -> fingerprint().
Fingerprint of a DER certificate (RFC 8122 §5).
-spec format_fingerprint(fingerprint()) -> binary().
Format as in SDP: sha-256 AB:CD:....
-spec generate() -> cert().
Generate an ECDSA P-256 self-signed certificate (the algorithm browsers use by default).
Options: key is ecdsa_p256 (default) or {rsa, Bits}; common_name (binary); days of validity (default 30).
-spec matches(binary(), [fingerprint()]) -> boolean().
True when the DER certificate matches one of the fingerprints. RFC 8122 §5: a match with any fingerprint whose hash is supported is sufficient. SHA-1 and SHA-224 fingerprints are ignored: they are not strong enough to bind the certificate. Comparison is constant time.
-spec parse_fingerprint(binary()) -> {ok, fingerprint()} | {error, bad_fingerprint}.
Parse the value of an a=fingerprint attribute.
-spec public_key(binary()) -> {ok, {ecdsa, term()} | {rsa, #'RSAPublicKey'{modulus :: term(), publicExponent :: term()}} | {eddsa, term()}} | {error, term()}.
Public key of a DER certificate, in the form accepted by public_key:verify/4.