Skip to content

Commit d954e0f

Browse files
committed
Fixed broken E2EE in VideoRoom (and fixed some small leaks too)
1 parent 9389d74 commit d954e0f

File tree

1 file changed

+95
-3
lines changed

1 file changed

+95
-3
lines changed

src/plugins/janus_videoroom.c

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ room-<unique room ID>: {
11441144
*
11451145
* Once a WebRTC PeerConnection has been established for a subscriber, in
11461146
* case you want to update a subscription you have to use the \c subscribe ,
1147-
* \c unsubscribe or \update methods: as the names of the requests suggest, the
1147+
* \c unsubscribe or \c update methods: as the names of the requests suggest, the
11481148
* former allows you to add more streams to subscribe to, the second
11491149
* instructs the plugin to remove streams you're currently subscribe to,
11501150
* while the latter allows you to perform both operations at the same time.
@@ -1523,8 +1523,8 @@ room-<unique room ID>: {
15231523

15241524

15251525
/* Plugin information */
1526-
#define JANUS_VIDEOROOM_VERSION 9
1527-
#define JANUS_VIDEOROOM_VERSION_STRING "0.0.9"
1526+
#define JANUS_VIDEOROOM_VERSION 10
1527+
#define JANUS_VIDEOROOM_VERSION_STRING "0.0.10"
15281528
#define JANUS_VIDEOROOM_DESCRIPTION "This is a plugin implementing a videoconferencing SFU (Selective Forwarding Unit) for Janus, that is an audio/video router."
15291529
#define JANUS_VIDEOROOM_NAME "JANUS VideoRoom plugin"
15301530
#define JANUS_VIDEOROOM_AUTHOR "Meetecho s.r.l."
@@ -2633,6 +2633,7 @@ static void janus_videoroom_reqpli(janus_videoroom_publisher_stream *ps, const c
26332633
#define JANUS_VIDEOROOM_ERROR_NOT_PUBLISHED 435
26342634
#define JANUS_VIDEOROOM_ERROR_ID_EXISTS 436
26352635
#define JANUS_VIDEOROOM_ERROR_INVALID_SDP 437
2636+
#define JANUS_VIDEOROOM_ERROR_INVALID_FEED 438
26362637

26372638

26382639
/* RTP forwarder helpers */
@@ -3198,6 +3199,8 @@ static json_t *janus_videoroom_subscriber_offer(janus_videoroom_subscriber *subs
31983199
char *sdp = janus_sdp_write(offer);
31993200
janus_sdp_destroy(offer);
32003201
json_t *jsep = json_pack("{ssss}", "type", "offer", "sdp", sdp);
3202+
if(subscriber->e2ee)
3203+
json_object_set_new(jsep, "e2ee", json_true());
32013204
g_free(sdp);
32023205
/* Done */
32033206
return jsep;
@@ -9260,6 +9263,7 @@ static void *janus_videoroom_handler(void *data) {
92609263
gboolean autoupdate = au ? json_is_true(au) : TRUE;
92619264
/* Make sure all the feeds we're subscribing to exist */
92629265
GList *publishers = NULL;
9266+
gboolean e2ee = videoroom->require_e2ee, sub_e2ee = FALSE, first = TRUE;
92639267
size_t i = 0;
92649268
for(i=0; i<json_array_size(feeds); i++) {
92659269
json_t *s = json_array_get(feeds, i);
@@ -9328,6 +9332,49 @@ static void *janus_videoroom_handler(void *data) {
93289332
janus_refcount_decrease(&videoroom->ref);
93299333
goto error;
93309334
}
9335+
sub_e2ee = publisher->e2ee;
9336+
if(e2ee && !sub_e2ee) {
9337+
/* Attempt to subscribe to non-end-to-end encrypted
9338+
* publisher in an end-to-end encrypted subscription */
9339+
JANUS_LOG(LOG_ERR, "Can't have not end-to-end encrypted feed in this subscription (%s)\n", feed_id_str);
9340+
error_code = JANUS_VIDEOROOM_ERROR_INVALID_FEED;
9341+
g_snprintf(error_cause, 512, "Can't have not end-to-end encrypted feed in this subscription (%s)", feed_id_str);
9342+
janus_mutex_unlock(&videoroom->mutex);
9343+
/* Unref publishers we may have taken note of so far */
9344+
while(publishers) {
9345+
publisher = (janus_videoroom_publisher *)publishers->data;
9346+
janus_refcount_decrease(&publisher->session->ref);
9347+
janus_refcount_decrease(&publisher->ref);
9348+
publishers = g_list_remove(publishers, publisher);
9349+
}
9350+
janus_mutex_unlock(&sessions_mutex);
9351+
janus_refcount_decrease(&videoroom->ref);
9352+
goto error;
9353+
} else if(!e2ee && sub_e2ee) {
9354+
if(first) {
9355+
/* This subscription will use end-to-end encryption */
9356+
e2ee = TRUE;
9357+
} else {
9358+
/* Attempt to subscribe to end-to-end encrypted
9359+
* publisher in a non-end-to-end encrypted subscription */
9360+
JANUS_LOG(LOG_ERR, "Can't have end-to-end encrypted feed in this subscription (%s)\n", feed_id_str);
9361+
error_code = JANUS_VIDEOROOM_ERROR_INVALID_FEED;
9362+
g_snprintf(error_cause, 512, "Can't have end-to-end encrypted feed in this subscription (%s)", feed_id_str);
9363+
janus_mutex_unlock(&videoroom->mutex);
9364+
/* Unref publishers we may have taken note of so far */
9365+
while(publishers) {
9366+
publisher = (janus_videoroom_publisher *)publishers->data;
9367+
janus_refcount_decrease(&publisher->session->ref);
9368+
janus_refcount_decrease(&publisher->ref);
9369+
publishers = g_list_remove(publishers, publisher);
9370+
}
9371+
janus_mutex_unlock(&sessions_mutex);
9372+
janus_refcount_decrease(&videoroom->ref);
9373+
goto error;
9374+
}
9375+
}
9376+
if(first)
9377+
first = FALSE;
93319378
const char *mid = json_string_value(json_object_get(s, "mid"));
93329379
if(mid != NULL) {
93339380
/* Check the mid too */
@@ -9429,6 +9476,7 @@ static void *janus_videoroom_handler(void *data) {
94299476
subscriber->room_id = videoroom->room_id;
94309477
subscriber->room_id_str = videoroom->room_id_str ? g_strdup(videoroom->room_id_str) : NULL;
94319478
subscriber->room = videoroom;
9479+
subscriber->e2ee = e2ee;
94329480
videoroom = NULL;
94339481
subscriber->pvt_id = pvt_id;
94349482
subscriber->use_msid = use_msid;
@@ -10358,6 +10406,21 @@ static void *janus_videoroom_handler(void *data) {
1035810406
janus_refcount_decrease(&subscriber->ref);
1035910407
goto error;
1036010408
}
10409+
if(publisher->e2ee != subscriber->e2ee) {
10410+
/* Attempt to mix normal and end-to-end encrypted subscriptions */
10411+
JANUS_LOG(LOG_ERR, "Can't mix normal and end-to-end encrypted subscriptions\n");
10412+
error_code = JANUS_VIDEOROOM_ERROR_INVALID_FEED;
10413+
g_snprintf(error_cause, 512, "Can't mix normal and end-to-end encrypted subscriptions");
10414+
/* Unref publishers we may have taken note of so far */
10415+
while(publishers) {
10416+
publisher = (janus_videoroom_publisher *)publishers->data;
10417+
janus_refcount_decrease(&publisher->session->ref);
10418+
janus_refcount_decrease(&publisher->ref);
10419+
publishers = g_list_remove(publishers, publisher);
10420+
}
10421+
janus_refcount_decrease(&subscriber->ref);
10422+
goto error;
10423+
}
1036110424
const char *mid = json_string_value(json_object_get(s, "mid"));
1036210425
if(mid != NULL) {
1036310426
/* Check the mid too */
@@ -11261,6 +11324,21 @@ static void *janus_videoroom_handler(void *data) {
1126111324
janus_refcount_decrease(&subscriber->ref);
1126211325
goto error;
1126311326
}
11327+
if(publisher->e2ee != subscriber->e2ee) {
11328+
/* Attempt to mix normal and end-to-end encrypted subscriptions */
11329+
JANUS_LOG(LOG_ERR, "Can't mix normal and end-to-end encrypted subscriptions\n");
11330+
error_code = JANUS_VIDEOROOM_ERROR_INVALID_FEED;
11331+
g_snprintf(error_cause, 512, "Can't mix normal and end-to-end encrypted subscriptions");
11332+
/* Unref publishers we may have taken note of so far */
11333+
while(publishers) {
11334+
publisher = (janus_videoroom_publisher *)publishers->data;
11335+
janus_refcount_decrease(&publisher->session->ref);
11336+
janus_refcount_decrease(&publisher->ref);
11337+
publishers = g_list_remove(publishers, publisher);
11338+
}
11339+
janus_refcount_decrease(&subscriber->ref);
11340+
goto error;
11341+
}
1126411342
const char *mid = json_string_value(json_object_get(s, "mid"));
1126511343
/* Check the mid too */
1126611344
janus_mutex_lock(&publisher->streams_mutex);
@@ -11618,13 +11696,15 @@ static void *janus_videoroom_handler(void *data) {
1161811696
JANUS_LOG(LOG_ERR, "Unknown SDP type '%s'\n", msg_sdp_type);
1161911697
error_code = JANUS_VIDEOROOM_ERROR_INVALID_SDP_TYPE;
1162011698
g_snprintf(error_cause, 512, "Unknown SDP type '%s'", msg_sdp_type);
11699+
json_decref(event);
1162111700
goto error;
1162211701
}
1162311702
if(session->participant_type != janus_videoroom_p_type_publisher) {
1162411703
/* We shouldn't be here, we always offer ourselves */
1162511704
JANUS_LOG(LOG_ERR, "Only publishers send offers\n");
1162611705
error_code = JANUS_VIDEOROOM_ERROR_INVALID_SDP_TYPE;
1162711706
g_snprintf(error_cause, 512, "Only publishers send offers");
11707+
json_decref(event);
1162811708
goto error;
1162911709
} else {
1163011710
/* This is a new publisher, or an updated one */
@@ -11633,18 +11713,23 @@ static void *janus_videoroom_handler(void *data) {
1163311713
JANUS_LOG(LOG_ERR, "Invalid participant instance\n");
1163411714
error_code = JANUS_VIDEOROOM_ERROR_UNKNOWN_ERROR;
1163511715
g_snprintf(error_cause, 512, "Invalid participant instance");
11716+
json_decref(event);
1163611717
goto error;
1163711718
}
1163811719
janus_videoroom *videoroom = participant->room;
1163911720
int count = 0;
1164011721
GHashTableIter iter;
1164111722
gpointer value;
1164211723
if(!videoroom) {
11724+
janus_refcount_decrease(&participant->ref);
1164311725
error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM;
11726+
json_decref(event);
1164411727
goto error;
1164511728
}
1164611729
if(g_atomic_int_get(&videoroom->destroyed)) {
11730+
janus_refcount_decrease(&participant->ref);
1164711731
error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM;
11732+
json_decref(event);
1164811733
goto error;
1164911734
}
1165011735
janus_refcount_increase(&videoroom->ref);
@@ -11660,17 +11745,22 @@ static void *janus_videoroom_handler(void *data) {
1166011745
if(count == videoroom->max_publishers) {
1166111746
janus_mutex_unlock(&videoroom->mutex);
1166211747
janus_refcount_decrease(&videoroom->ref);
11748+
janus_refcount_decrease(&participant->ref);
1166311749
JANUS_LOG(LOG_ERR, "Maximum number of publishers (%d) already reached\n", videoroom->max_publishers);
1166411750
error_code = JANUS_VIDEOROOM_ERROR_PUBLISHERS_FULL;
1166511751
g_snprintf(error_cause, 512, "Maximum number of publishers (%d) already reached", videoroom->max_publishers);
11752+
json_decref(event);
1166611753
goto error;
1166711754
}
1166811755
janus_mutex_unlock(&videoroom->mutex);
1166911756
}
1167011757
if(videoroom->require_e2ee && !e2ee && !participant->e2ee) {
11758+
janus_refcount_decrease(&videoroom->ref);
11759+
janus_refcount_decrease(&participant->ref);
1167111760
JANUS_LOG(LOG_ERR, "Room requires end-to-end encrypted media\n");
1167211761
error_code = JANUS_VIDEOROOM_ERROR_UNAUTHORIZED;
1167311762
g_snprintf(error_cause, 512, "Room requires end-to-end encrypted media");
11763+
json_decref(event);
1167411764
goto error;
1167511765
}
1167611766
/* Now prepare the SDP to give back */
@@ -11682,10 +11772,12 @@ static void *janus_videoroom_handler(void *data) {
1168211772
janus_sdp *offer = janus_sdp_parse(msg_sdp, error_str, sizeof(error_str));
1168311773
if(offer == NULL) {
1168411774
janus_refcount_decrease(&videoroom->ref);
11775+
janus_refcount_decrease(&participant->ref);
1168511776
json_decref(event);
1168611777
JANUS_LOG(LOG_ERR, "Error parsing offer: %s\n", error_str);
1168711778
error_code = JANUS_VIDEOROOM_ERROR_INVALID_SDP;
1168811779
g_snprintf(error_cause, 512, "Error parsing offer: %s", error_str);
11780+
json_decref(event);
1168911781
goto error;
1169011782
}
1169111783
/* Prepare an answer, by iterating on all m-lines */

0 commit comments

Comments
 (0)