Commit 5363f6d6 authored by jehan's avatar jehan

srtp headers from ms2 API

parent 41db9323
......@@ -24,7 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <ortp/ortp.h>
#include <ortp/event.h>
#include <ortp/zrtp.h>
#include <ortp/ortp_srtp.h>
/* defined in srtp.h*/
typedef struct srtp_ctx_t *MSSrtpCtx;
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
......@@ -67,7 +68,16 @@ MS2_PUBLIC void ring_stop (RingStream * stream);
/**
* @}
**/
/*
* Crypto suite used configure encrypted stream*/
typedef enum _MSCryptoSuite{
MS_AES_128_SHA1_80 = 1,
MS_AES_128_SHA1_32,
MS_AES_128_NO_AUTH,
MS_NO_CIPHER_SHA1_80,
MS_AES_256_SHA1_80,
MS_AES_256_SHA1_32
} MSCryptoSuite;
typedef enum StreamType {
AudioStreamType,
......@@ -83,9 +93,10 @@ typedef void (*media_stream_process_rtcp)(MediaStream *stream, mblk_t *m);
struct _MSMediaStreamSessions{
RtpSession *rtp_session;
srtp_t srtp_session;
MSSrtpCtx srtp_session;
OrtpZrtpContext *zrtp_context;
MSTicker *ticker;
bool_t is_secured;
};
typedef struct _MSMediaStreamSessions MSMediaStreamSessions;
......@@ -148,11 +159,17 @@ MS2_PUBLIC void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_
/*
* deprecated, use media_stream_set_srtp_recv_key and media_stream_set_srtp_send_key.
**/
MS2_PUBLIC bool_t media_stream_enable_srtp(MediaStream* stream, enum ortp_srtp_crypto_suite_t suite, const char* snd_key, const char* rcv_key);
MS2_PUBLIC bool_t media_stream_enable_srtp(MediaStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key);
MS2_PUBLIC int media_stream_set_srtp_recv_key(MediaStream *stream, MSCryptoSuite suite, const char* key);
MS2_PUBLIC int media_stream_set_srtp_recv_key(MediaStream *stream, enum ortp_srtp_crypto_suite_t suite, const char* key);
MS2_PUBLIC int media_stream_set_srtp_send_key(MediaStream *stream, MSCryptoSuite suite, const char* key);
/**
* @paraa stream object
* @return true if stream is encrypted
* */
MS2_PUBLIC bool_t media_stream_is_secured(const MediaStream *stream);
MS2_PUBLIC int media_stream_set_srtp_send_key(MediaStream *stream, enum ortp_srtp_crypto_suite_t suite, const char* key);
MS2_PUBLIC const MSQualityIndicator *media_stream_get_quality_indicator(MediaStream *stream);
/* *
......@@ -206,6 +223,10 @@ MS2_PUBLIC void media_stream_reclaim_sessions(MediaStream *stream, MSMediaStream
void media_stream_iterate(MediaStream * stream);
/**
* @returns curret streams tate
* */
MS2_PUBLIC MSStreamState media_stream_get_state(const MediaStream *stream);
typedef enum EchoLimiterType{
ELInactive,
......@@ -465,9 +486,13 @@ MS2_PUBLIC float audio_stream_get_average_lq_quality_rating(AudioStream *stream)
/* enable ZRTP on the audio stream */
MS2_PUBLIC void audio_stream_enable_zrtp(AudioStream *stream, OrtpZrtpParams *params);
/**
* return TRUE if zrtp is enabled, it does not mean that stream is encrypted, but only that zrtp is configured to know encryption status, uses #
* */
bool_t audio_stream_zrtp_enabled(const AudioStream *stream);
/* enable SRTP on the audio stream */
static inline bool_t audio_stream_enable_srtp(AudioStream* stream, enum ortp_srtp_crypto_suite_t suite, const char* snd_key, const char* rcv_key) {
static inline bool_t audio_stream_enable_srtp(AudioStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key) {
return media_stream_enable_srtp(&stream->ms, suite, snd_key, rcv_key);
}
......@@ -610,7 +635,7 @@ MS2_PUBLIC void video_stream_send_only_stop(VideoStream *vs);
MS2_PUBLIC void video_stream_enable_zrtp(VideoStream *vstream, AudioStream *astream, OrtpZrtpParams *param);
/* enable SRTP on the video stream */
static inline bool_t video_stream_enable_strp(VideoStream* stream, enum ortp_srtp_crypto_suite_t suite, const char* snd_key, const char* rcv_key) {
static inline bool_t video_stream_enable_strp(VideoStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key) {
return media_stream_enable_srtp(&stream->ms, suite, snd_key, rcv_key);
}
......
......@@ -1013,3 +1013,6 @@ void audio_stream_enable_zrtp(AudioStream *stream, OrtpZrtpParams *params){
if (stream->ms.sessions.zrtp_context==NULL)
stream->ms.sessions.zrtp_context=ortp_zrtp_context_new(stream->ms.sessions.rtp_session, params);
}
bool_t audio_stream_zrtp_enabled(const AudioStream *stream) {
return stream->ms.sessions.zrtp_context!=NULL;
}
......@@ -271,11 +271,12 @@ static int check_srtp_session_created(MediaStream *stream){
stream->sessions.srtp_session=session;
srtp_transport_new(session,&rtp,&rtcp);
rtp_session_set_transports(stream->sessions.rtp_session,rtp,rtcp);
stream->sessions.is_secured=TRUE;
}
return 0;
}
static bool_t add_srtp_stream(srtp_t srtp, enum ortp_srtp_crypto_suite_t suite, uint32_t ssrc, const char* b64_key, bool_t inbound)
static bool_t add_srtp_stream(srtp_t srtp, MSCryptoSuite suite, uint32_t ssrc, const char* b64_key, bool_t inbound)
{
srtp_policy_t policy;
uint8_t* key;
......@@ -287,29 +288,29 @@ static bool_t add_srtp_stream(srtp_t srtp, enum ortp_srtp_crypto_suite_t suite,
memset(&policy,0,sizeof(policy));
switch(suite){
case AES_128_SHA1_32:
case MS_AES_128_SHA1_32:
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
// srtp doc says: not adapted to rtcp...
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtcp);
break;
case AES_128_NO_AUTH:
case MS_AES_128_NO_AUTH:
crypto_policy_set_aes_cm_128_null_auth(&policy.rtp);
// srtp doc says: not adapted to rtcp...
crypto_policy_set_aes_cm_128_null_auth(&policy.rtcp);
break;
case NO_CIPHER_SHA1_80:
case MS_NO_CIPHER_SHA1_80:
crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtp);
crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtcp);
break;
case AES_128_SHA1_80: /*default mode*/
case MS_AES_128_SHA1_80: /*default mode*/
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break;
case AES_256_SHA1_80:
case MS_AES_256_SHA1_80:
crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtp);
crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtcp);
break;
case AES_256_SHA1_32:
case MS_AES_256_SHA1_32:
crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy.rtp);
crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy.rtcp);
break;
......@@ -366,12 +367,12 @@ static uint32_t find_other_ssrc(srtp_t srtp, uint32_t ssrc){
#endif
bool_t media_stream_srtp_supported(void){
return _ORTP_HAVE_SRTP;
return _ORTP_HAVE_SRTP & ortp_srtp_supported();
}
int media_stream_set_srtp_recv_key(MediaStream *stream, enum ortp_srtp_crypto_suite_t suite, const char* key){
int media_stream_set_srtp_recv_key(MediaStream *stream, MSCryptoSuite suite, const char* key){
if (!ortp_srtp_supported() || !_ORTP_HAVE_SRTP) {
if (!media_stream_srtp_supported()) {
ms_error("ortp srtp support disabled in oRTP or mediastreamer2");
return -1;
}
......@@ -399,9 +400,9 @@ int media_stream_set_srtp_recv_key(MediaStream *stream, enum ortp_srtp_crypto_su
#endif
}
int media_stream_set_srtp_send_key(MediaStream *stream, enum ortp_srtp_crypto_suite_t suite, const char* key){
int media_stream_set_srtp_send_key(MediaStream *stream, MSCryptoSuite suite, const char* key){
if (!ortp_srtp_supported() || !_ORTP_HAVE_SRTP) {
if (!media_stream_srtp_supported()) {
ms_error("ortp srtp support disabled in oRTP or mediastreamer2");
return -1;
}
......@@ -430,7 +431,7 @@ int media_stream_set_srtp_send_key(MediaStream *stream, enum ortp_srtp_crypto_su
}
/*deprecated*/
bool_t media_stream_enable_srtp(MediaStream *stream, enum ortp_srtp_crypto_suite_t suite, const char *snd_key, const char *rcv_key) {
bool_t media_stream_enable_srtp(MediaStream *stream, MSCryptoSuite suite, const char *snd_key, const char *rcv_key) {
return media_stream_set_srtp_recv_key(stream,suite,rcv_key)==0 && media_stream_set_srtp_send_key(stream,suite,snd_key)==0;
}
......@@ -475,18 +476,23 @@ void media_stream_iterate(MediaStream *stream){
if (stream->qi && curtime>stream->last_iterate_time) ms_quality_indicator_update_local(stream->qi);
stream->last_iterate_time=curtime;
if (stream->evq){
OrtpEvent *ev=ortp_ev_queue_get(stream->evq);
if (ev!=NULL){
OrtpEvent *ev=NULL;
while ((ev=ortp_ev_queue_get(stream->evq))!=NULL){
OrtpEventType evt=ortp_event_get_type(ev);
if (evt==ORTP_EVENT_RTCP_PACKET_RECEIVED){
mblk_t *m=ortp_event_get_data(ev)->packet;
ms_message("stream [%p]: receiving RTCP %s%s",stream,(rtcp_is_SR(m)?"SR":""),(rtcp_is_RR(m)?"RR":""));
ms_message("%s stream [%p]: receiving RTCP %s%s",media_stream_type_str(stream),stream,(rtcp_is_SR(m)?"SR":""),(rtcp_is_RR(m)?"RR":""));
stream->process_rtcp(stream,m);
}else if (evt==ORTP_EVENT_RTCP_PACKET_EMITTED){
ms_message("%s_stream_iterate[%p]: local statistics available\n\tLocal's current jitter buffer size:%f ms",
media_stream_type_str(stream), stream, rtp_session_get_jitter_stats(stream->sessions.rtp_session)->jitter_buffer_size_ms);
}else if ((evt==ORTP_EVENT_STUN_PACKET_RECEIVED)&&(stream->ice_check_list)){
ice_handle_stun_packet(stream->ice_check_list,stream->sessions.rtp_session,ortp_event_get_data(ev));
} else if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED) {
OrtpEventData *evd=ortp_event_get_data(ev);
stream->sessions.is_secured=evd->info.zrtp_stream_encrypted;
ms_message("%s stream [%p] is %s ",media_stream_type_str(stream) , stream, stream->sessions.is_secured ? "encrypted" : "not encrypted");
}
ortp_event_destroy(ev);
}
......@@ -542,3 +548,9 @@ void media_stream_reclaim_sessions(MediaStream *stream, MSMediaStreamSessions *s
memcpy(sessions,&stream->sessions, sizeof(MSMediaStreamSessions));
stream->owns_sessions=FALSE;
}
bool_t media_stream_is_secured (const MediaStream *stream) {
return stream->sessions.is_secured;
}
MSStreamState media_stream_get_state(const MediaStream *stream) {
return stream->state;
}
......@@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <math.h>
#include "mediastreamer2/mediastream.h"
#include "mediastreamer2/msequalizer.h"
#include "mediastreamer2/msvolume.h"
......@@ -79,6 +78,7 @@ extern void libmsisac_init();
#define MEDIASTREAM_MAX_ICE_CANDIDATES 3
static int cond=1;
......@@ -469,8 +469,8 @@ bool_t parse_args(int argc, char** argv, MediastreamDatas* out) {
i++;
out->device_rotation=atoi(argv[i]);
} else if (strcmp(argv[i], "--srtp")==0) {
if (!ortp_srtp_supported()) {
ms_error("ortp srtp support not enabled");
if (!media_stream_srtp_supported()) {
ms_error("srtp support not enabled");
return FALSE;
}
out->enable_srtp = TRUE;
......@@ -599,16 +599,16 @@ void setup_media_streams(MediastreamDatas* args) {
// default profile require key-length = 30 bytes
// -> input : 40 b64 encoded bytes
if (!args->srtp_local_master_key) {
uint8_t tmp[30];
ortp_crypto_get_random(tmp, 30);
char tmp[30];
snprintf(tmp,sizeof(tmp),"%08x%08x%08x%08x",rand(),rand(),rand(),rand());
args->srtp_local_master_key = (char*) malloc(41);
b64_encode((const char*)tmp, 30, args->srtp_local_master_key, 40);
args->srtp_local_master_key[40] = '\0';
ms_message("Generated local srtp key: '%s'", args->srtp_local_master_key);
}
if (!args->srtp_remote_master_key) {
uint8_t tmp[30];
ortp_crypto_get_random(tmp, 30);
char tmp[30];
snprintf(tmp,sizeof(tmp),"%08x%08x%08x%08x",rand(),rand(),rand(),rand());
args->srtp_remote_master_key = (char*) malloc(41);
b64_encode((const char*)tmp, 30, args->srtp_remote_master_key, 40);
args->srtp_remote_master_key[40] = '\0';
......@@ -700,7 +700,7 @@ void setup_media_streams(MediastreamDatas* args) {
ms_message("SRTP enabled: %d",
audio_stream_enable_srtp(
args->audio,
AES_128_SHA1_80,
MS_AES_128_SHA1_80,
args->srtp_local_master_key,
args->srtp_remote_master_key));
}
......@@ -748,7 +748,7 @@ void setup_media_streams(MediastreamDatas* args) {
ms_message("SRTP enabled: %d",
video_stream_enable_strp(
args->video,
AES_128_SHA1_80,
MS_AES_128_SHA1_80,
args->srtp_local_master_key,
args->srtp_remote_master_key));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment