Fork me on GitHub
dtls.h
Go to the documentation of this file.
1 
15 #ifndef _JANUS_DTLS_H
16 #define _JANUS_DTLS_H
17 
18 #include <inttypes.h>
19 #include <glib.h>
20 
21 #include "rtp.h"
22 #include "rtpsrtp.h"
23 #include "sctp.h"
24 #include "refcount.h"
25 #include "dtls-bio.h"
26 
32 gint janus_dtls_srtp_init(const char *server_pem, const char *server_key, const char *password);
34 void janus_dtls_srtp_cleanup(void);
37 
38 
40 typedef enum janus_dtls_role {
45 
47 typedef enum janus_dtls_state {
53 
55 typedef struct janus_dtls_srtp {
57  void *component;
63  gint64 dtls_started;
67  SSL *ssl;
69  BIO *read_bio;
71  BIO *write_bio;
73  BIO *filter_bio;
75  gint srtp_valid;
79  srtp_t srtp_in;
81  srtp_t srtp_out;
83  srtp_policy_t remote_policy;
85  srtp_policy_t local_policy;
87  int ready;
90 #ifdef HAVE_SCTP
91 
92  janus_sctp_association *sctp;
93 #endif
94 
95  volatile gint destroyed;
99 
100 
120 void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len);
127 
132 void janus_dtls_callback(const SSL *ssl, int where, int ret);
133 
138 int janus_dtls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx);
139 
144 
145 #ifdef HAVE_SCTP
146 
150 void janus_dtls_wrap_sctp_data(janus_dtls_srtp *dtls, char *buf, int len);
151 
157 int janus_dtls_send_sctp_data(janus_dtls_srtp *dtls, char *buf, int len);
158 
163 void janus_dtls_notify_data(janus_dtls_srtp *dtls, char *buf, int len);
164 #endif
165 
170 gboolean janus_dtls_retry(gpointer stack);
171 
175 const gchar *janus_get_dtls_srtp_state(janus_dtls_state state);
176 
180 const gchar *janus_get_dtls_srtp_role(janus_dtls_role role);
181 
185 const gchar *janus_get_dtls_srtp_profile(int profile);
186 
187 #endif
gchar * janus_dtls_get_local_fingerprint(void)
Method to return a string representation (SHA-256) of the certificate fingerprint.
Definition: dtls.c:114
gint janus_dtls_srtp_init(const char *server_pem, const char *server_key, const char *password)
DTLS stuff initialization.
Definition: dtls.c:321
SCTP processing for data channels (headers)
Definition: dtls.h:49
Reference counter mechanism.
struct janus_dtls_srtp janus_dtls_srtp
Janus DTLS-SRTP handle.
const gchar * janus_get_dtls_srtp_profile(int profile)
Helper method to get a string representation of an SRTP profile.
Definition: dtls.c:58
Definition: dtls.h:51
Definition: dtls.h:48
Definition: dtls.h:41
void janus_dtls_fd_bridge(janus_dtls_srtp *dtls)
DTLS BIOs to/from socket bridge.
Definition: dtls.c:963
OpenSSL BIO filter for fragmentation.
janus_dtls_state dtls_state
DTLS state of this component: -1=failed, 0=nothing, 1=trying, 2=connected.
Definition: dtls.h:61
SRTP definitions (headers)
void janus_dtls_srtp_cleanup(void)
Method to cleanup DTLS stuff before exiting.
Definition: dtls.c:449
Definition: refcount.h:78
BIO * filter_bio
Filter BIO (fix MTU fragmentation on outgoing DTLS data, if required)
Definition: dtls.h:73
Definition: dtls.h:50
SSL * ssl
SSL context used for DTLS for this component.
Definition: dtls.h:67
void janus_dtls_srtp_destroy(janus_dtls_srtp *dtls)
Destroy a janus_dtls_srtp instance.
Definition: dtls.c:911
int retransmissions
The number of retransmissions that have occurred for this DTLS instance so far.
Definition: dtls.h:89
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)
Definition: dtls.c:957
srtp_policy_t local_policy
libsrtp policy for outgoing SRTP packets
Definition: dtls.h:85
void janus_dtls_srtp_send_alert(janus_dtls_srtp *dtls)
Send an alert on a janus_dtls_srtp instance.
Definition: dtls.c:901
gint srtp_valid
Whether SRTP has been correctly set up for this component or not.
Definition: dtls.h:75
srtp_t srtp_out
libsrtp context for outgoing SRTP packets
Definition: dtls.h:81
Definition: dtls.h:43
janus_refcount ref
Reference counter for this instance.
Definition: dtls.h:97
Janus DTLS-SRTP handle.
Definition: dtls.h:55
void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len)
Handle an incoming DTLS message.
Definition: dtls.c:607
int ready
Whether this DTLS stack is now ready to be used for messages as well (e.g., SCTP encapsulation) ...
Definition: dtls.h:87
gboolean janus_dtls_retry(gpointer stack)
DTLS retransmission timer.
Definition: dtls.c:1052
gint64 dtls_connected
Monotonic time of when the DTLS state has switched to connected.
Definition: dtls.h:65
BIO * write_bio
Write BIO (outgoing DTLS data)
Definition: dtls.h:71
void janus_dtls_srtp_handshake(janus_dtls_srtp *dtls)
Start a DTLS handshake.
Definition: dtls.c:560
Definition: dtls.h:42
gint64 dtls_started
Monotonic time of when the DTLS handhake has started.
Definition: dtls.h:63
const gchar * janus_get_dtls_srtp_state(janus_dtls_state state)
Helper method to get a string representation of a Janus DTLS state.
Definition: dtls.c:28
gint srtp_profile
The SRTP profile currently in use.
Definition: dtls.h:77
volatile gint destroyed
Atomic flag to check if this instance has been destroyed.
Definition: dtls.h:95
RTP processing (headers)
void * component
Opaque pointer to the component this DTLS-SRTP context belongs to.
Definition: dtls.h:57
janus_dtls_role dtls_role
DTLS role of the gateway for this stream: 1=client, 0=server.
Definition: dtls.h:59
janus_dtls_srtp * janus_dtls_srtp_create(void *component, janus_dtls_role role)
Create a janus_dtls_srtp instance.
Definition: dtls.c:468
janus_dtls_state
DTLS state.
Definition: dtls.h:47
srtp_policy_t remote_policy
libsrtp policy for incoming SRTP packets
Definition: dtls.h:83
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) ...
Definition: dtls.c:927
janus_dtls_role
DTLS roles.
Definition: dtls.h:40
int janus_dtls_srtp_create_sctp(janus_dtls_srtp *dtls)
Create an SCTP association, for data channels.
Definition: dtls.c:580
const gchar * janus_get_dtls_srtp_role(janus_dtls_role role)
Helper method to get a string representation of a DTLS role.
Definition: dtls.c:44
BIO * read_bio
Read BIO (incoming DTLS data)
Definition: dtls.h:69
srtp_t srtp_in
libsrtp context for incoming SRTP packets
Definition: dtls.h:79