Skip to content

Commit

Permalink
Merge pull request #670 from pabuhler/fix-byte-order-remove-stream
Browse files Browse the repository at this point in the history
fix srtp_remove_stream to use SSRC in host byte order
  • Loading branch information
pabuhler authored Jan 4, 2024
2 parents dbc58d2 + af78e62 commit c823a57
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 60 deletions.
6 changes: 3 additions & 3 deletions fuzzer/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
/* Keep removing streams until the set of SSRCs extracted from the
* fuzzer input is exhausted */
if (i < num_remove_stream) {
if (srtp_remove_stream(srtp_ctx, remove_stream_ssrc[i]) !=
if (srtp_stream_remove(srtp_ctx, remove_stream_ssrc[i]) !=
srtp_err_status_ok) {
goto end;
}
Expand All @@ -860,11 +860,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
* extracted from the fuzzer input is exhausted */
if (j < num_set_roc * 2) {
uint32_t roc;
if (srtp_set_stream_roc(srtp_ctx, set_roc[j], set_roc[j + 1]) !=
if (srtp_stream_set_roc(srtp_ctx, set_roc[j], set_roc[j + 1]) !=
srtp_err_status_ok) {
goto end;
}
if (srtp_get_stream_roc(srtp_ctx, set_roc[j + 1], &roc) !=
if (srtp_stream_get_roc(srtp_ctx, set_roc[j + 1], &roc) !=
srtp_err_status_ok) {
goto end;
}
Expand Down
40 changes: 22 additions & 18 deletions include/srtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ srtp_err_status_t srtp_unprotect_mki(srtp_t ctx,
* for the session. The struct may be a single element, or it may be
* the head of a list, in which case each element of the list is
* processed. It may also be NULL, in which case streams should be added
* later using srtp_add_stream(). The final element of the list @b must
* later using srtp_stream_add(). The final element of the list @b must
* have its `next' field set to NULL.
*
* @return
Expand All @@ -595,10 +595,10 @@ srtp_err_status_t srtp_unprotect_mki(srtp_t ctx,
srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);

/**
* @brief srtp_add_stream() allocates and initializes an SRTP stream
* @brief srtp_stream_add() allocates and initializes an SRTP stream
* within a given SRTP session.
*
* The function call srtp_add_stream(session, policy) allocates and
* The function call srtp_stream_add(session, policy) allocates and
* initializes a new SRTP stream within a given, previously created
* session, applying the policy given as the other argument to that
* stream.
Expand All @@ -608,30 +608,34 @@ srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
* - srtp_err_status_alloc_fail if stream allocation failed
* - srtp_err_status_init_fail if stream initialization failed.
*/
srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
srtp_err_status_t srtp_stream_add(srtp_t session, const srtp_policy_t *policy);

/**
* @brief srtp_remove_stream() deallocates an SRTP stream.
* @brief srtp_stream_remove() deallocates an SRTP stream.
*
* The function call srtp_remove_stream(session, ssrc) removes
* The function call srtp_stream_remove(session, ssrc) removes
* the SRTP stream with the SSRC value ssrc from the SRTP session
* context given by the argument session.
*
* @param session is the SRTP session from which the stream
* will be removed.
* will be removed.
*
* @param ssrc is the SSRC value of the stream to be removed
* in network byte order.
* in host byte order.
*
* @attention In libSRTP version before 3.0.0 the SSRC param was in network
* byte order, this was changed in 3.0.0 to host byte order to be
* consistant with the rest of the api.
*
* @warning Wildcard SSRC values cannot be removed from a
* session.
* session.
*
* @return
* - srtp_err_status_ok if the stream deallocation succeeded.
* - [other] otherwise.
*
*/
srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
srtp_err_status_t srtp_stream_remove(srtp_t session, unsigned int ssrc);

/**
* @brief srtp_update() updates all streams in the session.
Expand Down Expand Up @@ -660,9 +664,9 @@ srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);

/**
* @brief srtp_update_stream() updates a SRTP stream.
* @brief srtp_stream_update() updates a SRTP stream.
*
* The function call srtp_update_stream(session, policy) updates
* The function call srtp_stream_update(session, policy) updates
* the stream(s) in the session that match applying the given
* policy and key. The existing ROC value of all stream(s) will
* be preserved.
Expand All @@ -680,7 +684,7 @@ srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
* - [other] otherwise.
*
*/
srtp_err_status_t srtp_update_stream(srtp_t session,
srtp_err_status_t srtp_stream_update(srtp_t session,
const srtp_policy_t *policy);

/**
Expand Down Expand Up @@ -1558,7 +1562,7 @@ void *srtp_get_user_data(srtp_t ctx);
* reached, an SRTP stream will enter an `expired' state in which no
* more packets can be protected or unprotected. When this happens,
* it is likely that you will want to either deallocate the stream
* (using srtp_remove_stream()), and possibly allocate a new one.
* (using srtp_stream_remove()), and possibly allocate a new one.
*
* When an SRTP stream expires, the other streams in the same session
* are unaffected, unless key sharing is used by that stream. In the
Expand Down Expand Up @@ -1721,28 +1725,28 @@ srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session,
uint32_t *length);

/**
* @brief srtp_set_stream_roc(session, ssrc, roc)
* @brief srtp_stream_set_roc(session, ssrc, roc)
*
* Set the roll-over-counter on a session for a given SSRC
*
* returns err_status_ok on success, srtp_err_status_bad_param if there is no
* stream found
*
*/
srtp_err_status_t srtp_set_stream_roc(srtp_t session,
srtp_err_status_t srtp_stream_set_roc(srtp_t session,
uint32_t ssrc,
uint32_t roc);

/**
* @brief srtp_get_stream_roc(session, ssrc, roc)
* @brief srtp_stream_get_roc(session, ssrc, roc)
*
* Get the roll-over-counter on a session for a given SSRC
*
* returns err_status_ok on success, srtp_err_status_bad_param if there is no
* stream found
*
*/
srtp_err_status_t srtp_get_stream_roc(srtp_t session,
srtp_err_status_t srtp_stream_get_roc(srtp_t session,
uint32_t ssrc,
uint32_t *roc);

Expand Down
10 changes: 5 additions & 5 deletions srtp.def
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ srtp_protect_mki
srtp_unprotect
srtp_unprotect_mki
srtp_create
srtp_add_stream
srtp_remove_stream
srtp_stream_add
srtp_stream_remove
srtp_update
srtp_update_stream
srtp_stream_update
srtp_get_stream
srtp_crypto_policy_set_rtp_default
srtp_crypto_policy_set_rtcp_default
Expand Down Expand Up @@ -41,9 +41,9 @@ srtp_protect_rtcp
srtp_protect_rtcp_mki
srtp_unprotect_rtcp
srtp_unprotect_rtcp_mki
srtp_set_stream_roc
srtp_stream_set_roc
srtp_set_user_data
srtp_get_stream_roc
srtp_stream_get_roc
srtp_get_user_data
srtp_install_event_handler
srtp_get_version_string
Expand Down
26 changes: 13 additions & 13 deletions srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,7 @@ srtp_err_status_t srtp_dealloc(srtp_t session)
return srtp_err_status_ok;
}

srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy)
srtp_err_status_t srtp_stream_add(srtp_t session, const srtp_policy_t *policy)
{
srtp_err_status_t status;
srtp_stream_t tmp;
Expand Down Expand Up @@ -3025,7 +3025,7 @@ srtp_err_status_t srtp_create(srtp_t *session, /* handle for session */
* initializing a stream for each element
*/
while (policy != NULL) {
stat = srtp_add_stream(ctx, policy);
stat = srtp_stream_add(ctx, policy);
if (stat) {
/* clean up everything */
srtp_dealloc(*session);
Expand All @@ -3040,7 +3040,7 @@ srtp_err_status_t srtp_create(srtp_t *session, /* handle for session */
return srtp_err_status_ok;
}

srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc)
srtp_err_status_t srtp_stream_remove(srtp_t session, uint32_t ssrc)
{
srtp_stream_ctx_t *stream;
srtp_err_status_t status;
Expand All @@ -3050,7 +3050,7 @@ srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc)
return srtp_err_status_bad_param;

/* find and remove stream from the list */
stream = srtp_stream_list_get(session->stream_list, ssrc);
stream = srtp_stream_list_get(session->stream_list, htonl(ssrc));
if (stream == NULL) {
return srtp_err_status_no_ctx;
}
Expand Down Expand Up @@ -3081,7 +3081,7 @@ srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy)
}

while (policy != NULL) {
stat = srtp_update_stream(session, policy);
stat = srtp_stream_update(session, policy);
if (stat) {
return stat;
}
Expand Down Expand Up @@ -3125,7 +3125,7 @@ static int update_template_stream_cb(srtp_stream_t stream, void *raw_data)
old_rtcp_rdb = stream->rtcp_rdb;

/* remove stream */
data->status = srtp_remove_stream(session, ssrc);
data->status = srtp_stream_remove(session, ssrc);
if (data->status) {
return 1;
}
Expand Down Expand Up @@ -3212,7 +3212,7 @@ static srtp_err_status_t update_template_streams(srtp_t session,
return srtp_err_status_ok;
}

static srtp_err_status_t update_stream(srtp_t session,
static srtp_err_status_t stream_update(srtp_t session,
const srtp_policy_t *policy)
{
srtp_err_status_t status;
Expand All @@ -3234,12 +3234,12 @@ static srtp_err_status_t update_stream(srtp_t session,
old_index = stream->rtp_rdbx.index;
old_rtcp_rdb = stream->rtcp_rdb;

status = srtp_remove_stream(session, htonl(policy->ssrc.value));
status = srtp_stream_remove(session, htonl(policy->ssrc.value));
if (status) {
return status;
}

status = srtp_add_stream(session, policy);
status = srtp_stream_add(session, policy);
if (status) {
return status;
}
Expand All @@ -3256,7 +3256,7 @@ static srtp_err_status_t update_stream(srtp_t session,
return srtp_err_status_ok;
}

srtp_err_status_t srtp_update_stream(srtp_t session,
srtp_err_status_t srtp_stream_update(srtp_t session,
const srtp_policy_t *policy)
{
srtp_err_status_t status;
Expand All @@ -3277,7 +3277,7 @@ srtp_err_status_t srtp_update_stream(srtp_t session,
status = update_template_streams(session, policy);
break;
case (ssrc_specific):
status = update_stream(session, policy);
status = stream_update(session, policy);
break;
case (ssrc_undefined):
default:
Expand Down Expand Up @@ -4817,7 +4817,7 @@ srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func,
return srtp_err_status_ok;
}

srtp_err_status_t srtp_set_stream_roc(srtp_t session,
srtp_err_status_t srtp_stream_set_roc(srtp_t session,
uint32_t ssrc,
uint32_t roc)
{
Expand All @@ -4832,7 +4832,7 @@ srtp_err_status_t srtp_set_stream_roc(srtp_t session,
return srtp_err_status_ok;
}

srtp_err_status_t srtp_get_stream_roc(srtp_t session,
srtp_err_status_t srtp_stream_get_roc(srtp_t session,
uint32_t ssrc,
uint32_t *roc)
{
Expand Down
2 changes: 1 addition & 1 deletion test/rtp_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ int rtp_decoder_init(rtp_decoder_t dcdr,
}

if (policy.ssrc.type == ssrc_specific && roc != 0) {
if (srtp_set_stream_roc(dcdr->srtp_ctx, policy.ssrc.value, roc)) {
if (srtp_stream_set_roc(dcdr->srtp_ctx, policy.ssrc.value, roc)) {
return 1;
}
}
Expand Down
Loading

0 comments on commit c823a57

Please sign in to comment.