View Source ExDTLS
DTLS and DTLS-SRTP handshake library for Elixir, based on OpenSSL.
ElixirDTLS allows user to perform DTLS handshake (including DTLS-SRTP one) without requiring any socket. Instead, it generates DTLS packets that user has to transport to the peer. Thanks to this DTLS handshake can be performed on the third party socket e.g. one used to establish connection via ICE protocol.
installation
Installation
The package can be installed by adding ex_dtls
to your list of dependencies in mix.exs
:
def deps do
[
{:ex_dtls, "~> 0.13.0"}
]
end
usage
Usage
ExDTLS
can work both as a C node or as a NIF.
By default, C node implementation is used, however, user can change it by passing proper option while starting ExDTLS
or in config.exs
by:
config :ex_dtls, impl: :nif
Init ExDTLS
on both peers with:
# One peer should be a client and use client_mode: true, the other - false
# DTLS-SRTP is the most common use case for ExDTLS, we'll enable it
{:ok, dtls} = ExDTLS.start_link(client_mode: true, dtls_srtp: true)
On a peer running in a client mode start performing DTLS handshake
{:ok, packets} = ExDTLS.do_handshake(dtls)
This will generate initial handshake packets. Now we have to pass them on the second peer. You can use for that e.g. a UDP socket, but we will not cover this here.
After receiving initial DTLS packets on the second peer pass them to ExDTLS
{:ok, packets} = ExDTLS.process(dtls, packets)
As a result, we will also get some new packets that have to be passed to the first peer.
After some back and forth DTLS handshake should be finished successfully.
Peer that finishes handshake first will return {:finished, handshake_data, packets}
message. These packets have to be sent to the second peer, so it can finish its handshake too and
return {:finished, handshake_data}
message.
ExDTLS
may also ask for retransmitting some packets if it thinks they were lost.
See ExDTLS.retransmit_msg_t/0
.
For more complete examples please refer to membrane_ice_plugin where we use ex_dtls
or to our integration tests.
copyright-and-license
Copyright and License
Copyright 2020, Software Mansion
Licensed under the Apache License, Version 2.0