Fork me on GitHub
Macros | Functions
dtls.c File Reference

DTLS/SRTP processing. More...

#include "janus.h"
#include "debug.h"
#include "dtls.h"
#include "rtp.h"
#include "rtcp.h"
#include "events.h"
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/asn1.h>
Include dependency graph for dtls.c:

Macros

#define DTLS_CIPHERS   "ALL:NULL:eNULL:aNULL"
 
#define DTLS_AUTOCERT_DURATION   60*60*24*365
 

Functions

const gchar * janus_get_dtls_srtp_state (janus_dtls_state state)
 Helper method to get a string representation of a Janus DTLS state. More...
 
const gchar * janus_get_dtls_srtp_role (janus_dtls_role role)
 Helper method to get a string representation of a DTLS role. More...
 
gchar * janus_dtls_get_local_fingerprint (void)
 Method to return a string representation (SHA-256) of the certificate fingerprint. More...
 
gint janus_dtls_srtp_init (const char *server_pem, const char *server_key)
 DTLS stuff initialization. More...
 
void janus_dtls_srtp_cleanup (void)
 Method to cleanup DTLS stuff before exiting. More...
 
janus_dtls_srtpjanus_dtls_srtp_create (void *ice_component, janus_dtls_role role)
 Create a janus_dtls_srtp instance. More...
 
void janus_dtls_srtp_handshake (janus_dtls_srtp *dtls)
 Start a DTLS handshake. More...
 
void janus_dtls_srtp_incoming_msg (janus_dtls_srtp *dtls, char *buf, uint16_t len)
 Handle an incoming DTLS message. More...
 
void janus_dtls_srtp_send_alert (janus_dtls_srtp *dtls)
 Send an alert on a janus_dtls_srtp instance. More...
 
void janus_dtls_srtp_destroy (janus_dtls_srtp *dtls)
 Destroy a janus_dtls_srtp instance. More...
 
void janus_dtls_callback (const SSL *ssl, int where, int ret)
 DTLS alert callback (http://www.openssl.org/docs/ssl/SSL_CTX_set_info_callback.html) More...
 
int janus_dtls_verify_callback (int preverify_ok, X509_STORE_CTX *ctx)
 DTLS certificate verification callback (http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html) More...
 
void janus_dtls_fd_bridge (janus_dtls_srtp *dtls)
 DTLS BIOs to/from socket bridge. More...
 
gboolean janus_dtls_retry (gpointer stack)
 DTLS retransmission timer. More...
 

Detailed Description

DTLS/SRTP processing.

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Implementation (based on OpenSSL and libsrtp) of the DTLS/SRTP transport. The code takes care of the DTLS handshake between peers and the gateway, and sets the proper SRTP and SRTCP context up accordingly. A DTLS alert from a peer is notified to the plugin handling him/her by means of the hangup_media callback.

Protocols

Macro Definition Documentation

◆ DTLS_AUTOCERT_DURATION

#define DTLS_AUTOCERT_DURATION   60*60*24*365

◆ DTLS_CIPHERS

#define DTLS_CIPHERS   "ALL:NULL:eNULL:aNULL"

Function Documentation

◆ janus_dtls_callback()

void janus_dtls_callback ( const SSL *  ssl,
int  where,
int  ret 
)

DTLS alert callback (http://www.openssl.org/docs/ssl/SSL_CTX_set_info_callback.html)

Parameters
[in]sslSSL instance where the alert occurred
[in]whereThe context where the event occurred
[in]retThe error code

◆ janus_dtls_fd_bridge()

void janus_dtls_fd_bridge ( janus_dtls_srtp dtls)

DTLS BIOs to/from socket bridge.

As libnice is going to actually send and receive data, and not OpenSSL, a read/write BIO is used to "bridge" the data between the crypto stuff and the network.

Parameters
[in]dtlsThe janus_dtls_srtp instance to use

◆ janus_dtls_get_local_fingerprint()

gchar* janus_dtls_get_local_fingerprint ( void  )

Method to return a string representation (SHA-256) of the certificate fingerprint.

◆ janus_dtls_retry()

gboolean janus_dtls_retry ( gpointer  stack)

DTLS retransmission timer.

As libnice is going to actually send and receive data, OpenSSL cannot handle retransmissions by itself: this timed callback (g_source_set_callback) deals with this.

Parameters
[in]stackOpaque pointer to the janus_dtls_srtp instance to use
Returns
true if a retransmission is still needed, false otherwise

◆ janus_dtls_srtp_cleanup()

void janus_dtls_srtp_cleanup ( void  )

Method to cleanup DTLS stuff before exiting.

◆ janus_dtls_srtp_create()

janus_dtls_srtp* janus_dtls_srtp_create ( void *  component,
janus_dtls_role  role 
)

Create a janus_dtls_srtp instance.

Parameters
[in]componentOpaque pointer to the component owning that will use the stack
[in]roleThe role of the DTLS stack (client/server)
Returns
A new janus_dtls_srtp instance if successful, NULL otherwise

◆ janus_dtls_srtp_destroy()

void janus_dtls_srtp_destroy ( janus_dtls_srtp dtls)

Destroy a janus_dtls_srtp instance.

Parameters
[in]dtlsThe janus_dtls_srtp instance to destroy

◆ janus_dtls_srtp_handshake()

void janus_dtls_srtp_handshake ( janus_dtls_srtp dtls)

Start a DTLS handshake.

Parameters
[in]dtlsThe janus_dtls_srtp instance to start the handshake on

◆ janus_dtls_srtp_incoming_msg()

void janus_dtls_srtp_incoming_msg ( janus_dtls_srtp dtls,
char *  buf,
uint16_t  len 
)

Handle an incoming DTLS message.

Parameters
[in]dtlsThe janus_dtls_srtp instance to start the handshake on
[in]bufThe DTLS message data
[in]lenThe DTLS message data lenght

◆ janus_dtls_srtp_init()

gint janus_dtls_srtp_init ( const char *  server_pem,
const char *  server_key 
)

DTLS stuff initialization.

Parameters
[in]server_pemPath to the certificate to use
[in]server_keyPath to the key to use
Returns
0 in case of success, a negative integer on errors

◆ janus_dtls_srtp_send_alert()

void janus_dtls_srtp_send_alert ( janus_dtls_srtp dtls)

Send an alert on a janus_dtls_srtp instance.

Parameters
[in]dtlsThe janus_dtls_srtp instance to send the alert on

◆ janus_dtls_verify_callback()

int janus_dtls_verify_callback ( int  preverify_ok,
X509_STORE_CTX *  ctx 
)

DTLS certificate verification callback (http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html)

This method always returns 1 (true), in order not to fail when a certificate verification is requested. This is especially needed because all certificates used for DTLS in WebRTC are self signed, and as such a formal verification would fail.

Parameters
[in]preverify_okWhether the verification of the certificate was passed
[in]ctxcontext used for the certificate verification

◆ janus_get_dtls_srtp_role()

const gchar* janus_get_dtls_srtp_role ( janus_dtls_role  role)

Helper method to get a string representation of a DTLS role.

Parameters
[in]roleThe DTLS role
Returns
A string representation of the role

◆ janus_get_dtls_srtp_state()

const gchar* janus_get_dtls_srtp_state ( janus_dtls_state  state)

Helper method to get a string representation of a Janus DTLS state.

Parameters
[in]stateThe Janus DTLS state
Returns
A string representation of the state