webrtc_dtls_cert (webrtc v0.1.0)

View Source

Certificates 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

cert/0

-type cert() :: #{der := binary(), key := public_key:private_key()}.

fingerprint/0

-type fingerprint() :: {hash(), binary()}.

hash/0

-type hash() :: sha | sha224 | sha256 | sha384 | sha512.

Functions

fingerprint(Hash, Der)

-spec fingerprint(hash(), binary()) -> fingerprint().

Fingerprint of a DER certificate (RFC 8122 §5).

format_fingerprint(_)

-spec format_fingerprint(fingerprint()) -> binary().

Format as in SDP: sha-256 AB:CD:....

generate()

-spec generate() -> cert().

Generate an ECDSA P-256 self-signed certificate (the algorithm browsers use by default).

generate(Opts)

-spec generate(map()) -> cert().

Options: key is ecdsa_p256 (default) or {rsa, Bits}; common_name (binary); days of validity (default 30).

matches(Der, Fingerprints)

-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.

parse_fingerprint(Value)

-spec parse_fingerprint(binary()) -> {ok, fingerprint()} | {error, bad_fingerprint}.

Parse the value of an a=fingerprint attribute.

public_key(Der)

-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.