Skip to content

Commit

Permalink
Shimmed libsrtp2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Dec 8, 2016
1 parent 846a7f2 commit 997c72f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 42 deletions.
23 changes: 0 additions & 23 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,7 @@ gint janus_dtls_srtp_init(const char* server_pem, const char* server_key) {
}

/* Initialize libsrtp */
#ifdef HAVE_SRTP_2
if(srtp_init() != srtp_err_status_ok) {
#else
if(srtp_init() != err_status_ok) {
#endif
JANUS_LOG(LOG_FATAL, "Ops, error setting up libsrtp?\n");
return 5;
}
Expand Down Expand Up @@ -700,13 +696,8 @@ void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len
}
/* Build master keys and set SRTP policies */
/* Remote (inbound) */
#ifdef HAVE_SRTP_2
srtp_crypto_policy_set_rtp_default(&(dtls->remote_policy.rtp));
srtp_crypto_policy_set_rtcp_default(&(dtls->remote_policy.rtcp));
#else
crypto_policy_set_rtp_default(&(dtls->remote_policy.rtp));
crypto_policy_set_rtcp_default(&(dtls->remote_policy.rtcp));
#endif
dtls->remote_policy.ssrc.type = ssrc_any_inbound;
unsigned char remote_policy_key[SRTP_MASTER_LENGTH];
dtls->remote_policy.key = (unsigned char *)&remote_policy_key;
Expand All @@ -718,13 +709,8 @@ void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len
#endif
dtls->remote_policy.next = NULL;
/* Local (outbound) */
#ifdef HAVE_SRTP_2
srtp_crypto_policy_set_rtp_default(&(dtls->local_policy.rtp));
srtp_crypto_policy_set_rtcp_default(&(dtls->local_policy.rtcp));
#else
crypto_policy_set_rtp_default(&(dtls->local_policy.rtp));
crypto_policy_set_rtcp_default(&(dtls->local_policy.rtcp));
#endif
dtls->local_policy.ssrc.type = ssrc_any_outbound;
unsigned char local_policy_key[SRTP_MASTER_LENGTH];
dtls->local_policy.key = (unsigned char *)&local_policy_key;
Expand All @@ -736,25 +722,16 @@ void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len
#endif
dtls->local_policy.next = NULL;
/* Create SRTP sessions */
#ifdef HAVE_SRTP_2
srtp_err_status_t res = srtp_create(&(dtls->srtp_in), &(dtls->remote_policy));
if(res != srtp_err_status_ok) {
#else
err_status_t res = srtp_create(&(dtls->srtp_in), &(dtls->remote_policy));
if(res != err_status_ok) {
#endif
/* Something went wrong... */
JANUS_LOG(LOG_ERR, "[%"SCNu64"] Oops, error creating inbound SRTP session for component %d in stream %d??\n", handle->handle_id, component->component_id, stream->stream_id);
JANUS_LOG(LOG_ERR, "[%"SCNu64"] -- %d (%s)\n", handle->handle_id, res, janus_get_srtp_error(res));
goto done;
}
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Created inbound SRTP session for component %d in stream %d\n", handle->handle_id, component->component_id, stream->stream_id);
res = srtp_create(&(dtls->srtp_out), &(dtls->local_policy));
#ifdef HAVE_SRTP_2
if(res != srtp_err_status_ok) {
#else
if(res != err_status_ok) {
#endif
/* Something went wrong... */
JANUS_LOG(LOG_ERR, "[%"SCNu64"] Oops, error creating outbound SRTP session for component %d in stream %d??\n", handle->handle_id, component->component_id, stream->stream_id);
JANUS_LOG(LOG_ERR, "[%"SCNu64"] -- %d (%s)\n", handle->handle_id, res, janus_get_srtp_error(res));
Expand Down
6 changes: 6 additions & 0 deletions dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include <srtp2/srtp.h>
#else
#include <srtp/srtp.h>
#define srtp_err_status_t err_status_t
#define srtp_err_status_ok err_status_ok
#define srtp_err_status_replay_fail err_status_replay_fail
#define srtp_err_status_replay_old err_status_replay_old
#define srtp_crypto_policy_set_rtp_default crypto_policy_set_rtp_default
#define srtp_crypto_policy_set_rtcp_default crypto_policy_set_rtcp_default
#endif

#include "sctp.h"
Expand Down
19 changes: 0 additions & 19 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1838,15 +1838,9 @@ void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_i
}

int buflen = len;
#ifdef HAVE_SRTP_2
srtp_err_status_t res = srtp_unprotect(component->dtls->srtp_in, buf, &buflen);
if(res != srtp_err_status_ok) {
if(res != srtp_err_status_replay_fail && res != srtp_err_status_replay_old) {
#else
err_status_t res = srtp_unprotect(component->dtls->srtp_in, buf, &buflen);
if(res != err_status_ok) {
if(res != err_status_replay_fail && res != err_status_replay_old) {
#endif
/* Only print the error if it's not a 'replay fail' or 'replay old' (which is probably just the result of us NACKing a packet) */
rtp_header *header = (rtp_header *)buf;
guint32 timestamp = ntohl(header->timestamp);
Expand Down Expand Up @@ -2025,13 +2019,8 @@ void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_i
JANUS_LOG(LOG_WARN, "[%"SCNu64"] Missing valid SRTP session (packet arrived too early?), skipping...\n", handle->handle_id);
} else {
int buflen = len;
#ifdef HAVE_SRTP_2
srtp_err_status_t res = srtp_unprotect_rtcp(component->dtls->srtp_in, buf, &buflen);
if(res != srtp_err_status_ok) {
#else
err_status_t res = srtp_unprotect_rtcp(component->dtls->srtp_in, buf, &buflen);
if(res != err_status_ok) {
#endif
JANUS_LOG(LOG_ERR, "[%"SCNu64"] SRTCP unprotect error: %s (len=%d-->%d)\n", handle->handle_id, janus_get_srtp_error(res), len, buflen);
} else {
/* Is this audio or video? */
Expand Down Expand Up @@ -3410,11 +3399,7 @@ void *janus_ice_send_thread(void *data) {
janus_mutex_unlock(&component->dtls->srtp_mutex);
}
//~ JANUS_LOG(LOG_VERB, "[%"SCNu64"] ... SRTCP protect %s (len=%d-->%d)...\n", handle->handle_id, janus_get_srtp_error(res), pkt->length, protected);
#ifdef HAVE_SRTP_2
if(res != srtp_err_status_ok) {
#else
if(res != err_status_ok) {
#endif
JANUS_LOG(LOG_ERR, "[%"SCNu64"] ... SRTCP protect error... %s (len=%d-->%d)...\n", handle->handle_id, janus_get_srtp_error(res), pkt->length, protected);
} else {
/* Shoot! */
Expand Down Expand Up @@ -3494,11 +3479,7 @@ void *janus_ice_send_thread(void *data) {
int protected = pkt->length;
int res = srtp_protect(component->dtls->srtp_out, sbuf, &protected);
//~ JANUS_LOG(LOG_VERB, "[%"SCNu64"] ... SRTP protect %s (len=%d-->%d)...\n", handle->handle_id, janus_get_srtp_error(res), pkt->length, protected);
#ifdef HAVE_SRTP_2
if(res != srtp_err_status_ok) {
#else
if(res != err_status_ok) {
#endif
rtp_header *header = (rtp_header *)sbuf;
guint32 timestamp = ntohl(header->timestamp);
guint16 seq = ntohs(header->seq_number);
Expand Down

0 comments on commit 997c72f

Please sign in to comment.