Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SRTP for remote publishers #3449

Merged

Conversation

spscream
Copy link
Contributor

@spscream spscream commented Oct 9, 2024

hi, I got working SRTP encryption for remote publishers, tested and worked in our environment

@spscream spscream force-pushed the feature/am/remote-forwarders-srtp branch 2 times, most recently from 88bf274 to dc307e9 Compare October 9, 2024 14:21
@lminiero
Copy link
Member

@spscream thanks! So you got it working with the same SRTP crypto context for all streams, correct?
I'll review and get back to you in the next few days.

@lminiero lminiero added the multistream Related to Janus 1.x label Oct 14, 2024
@spscream
Copy link
Contributor Author

no, for each sender on source side rtp forwarder helper is created, so each helper have its own srtp context, and on receiving side we have srtp context per publisher stream

@spscream spscream force-pushed the feature/am/remote-forwarders-srtp branch 2 times, most recently from 071ca8b to 78951f2 Compare October 14, 2024 13:08
Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a first review of the code: it looks mostly fine to me, and in fact you'll see that most comments are editorial and nitpicking. I did add a note on SRTP error logging that could be problematic the way it's done now.

I also have a doubt on just setting a stream to disabled = TRUE in case SRTP creation failed, considering there may be other things that re-enable that same stream, e.g., by subsequent API calls that set disabled back to TRUE on a stream that has a broken SRTP context at that point. Not sure if that could cause the code to crash, but it's worth investigating what could happen in that case.

src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
src/plugins/janus_videoroom.c Outdated Show resolved Hide resolved
guint32 timestamp = ntohl(rtp->timestamp);
guint16 seq = ntohs(rtp->seq_number);
JANUS_LOG(LOG_ERR, "[%s] Publisher stream (#%d) SRTP unprotect error: %s (len=%d-->%d, ts=%"SCNu32", seq=%"SCNu16")\n",
publisher->user_id_str, ps->mindex, janus_srtp_error_str(res), bytes, buflen, timestamp, seq);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will flood your logs in case you start getting traffic that's inconsistent with your SRTP context, since it will print a log line for every incoming RTP packet, and there may be a lot of them. In the core we try to limit that by showing an error summary every couple of seconds or so to limit the damage. An alternative might be having some sort of toggle: the first time you get an SRTP error you print the error, and then you don't anymore until you get a proper error (SRTP decoding succeeded) that resets the toggle (but this could still cause log flooding if success/error alternate often).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any example from core, where you summarize logs? I copied this part from streaming plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it in ice.c, I'll make the same - write to debug log on every packet and write summary periodically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's there too then nevermind, I can look into this later on and fix it on both. I just noticed that a few of the nits I mentioned were actually in that code too (e.g., the &policy->rtp no parenthesis thing).

Copy link
Member

@lminiero lminiero Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it in ice.c, I'll make the same - write to debug log on every packet and write summary periodically.

No need, don't worry: I'll take care of that in both plugins myself so that it's done in a consistent way (I'll have to check if the same happens in SIP and NoSIP plugins too).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think about disabled, maybe we should add new flag for stream? like srtp_init_failed or similar and set it to true and add required checks in logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, what will be suitable decision for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that, to keep things simple, besides setting disabled to FALSE it may be enough to simply set the stream is_srtp to FALSE as well. This way, even if a stream disabled is forcibly set to TRUE later on, there will be no SRTP code involved that may find broken SRTP structures: of course audio/video would not work at all, because we'd be relaying encoded packets, but that's to be expected, since configuring that stream failed in the first place. I only want to ensure there's not a crash when that state changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, updated pr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw it was is_rtp=FALSE by default, I set it to be more explicit.

@spscream spscream force-pushed the feature/am/remote-forwarders-srtp branch 4 times, most recently from 9e86ead to 47d63bb Compare October 28, 2024 13:36
@lminiero
Copy link
Member

Just as a side note, please notice that this will be merged only after #3359 is merged too (also considering I asked @fancycode to do rebases more than once already 😅 ). You may want to have a look at/review that PR as well, since it's aimed at addressing some memory leaks that apparently remote publishers cause (and since you've started using them, you'll probably be interested in that).

@fancycode
Copy link
Contributor

Just as a side note, please notice that this will be merged only after #3359 is merged too (also considering I asked @fancycode to do rebases more than once already 😅 ).

Thanks 😆 happy to do more rebases if necessary - the change in my PR is not very large, so rebases are not too difficult. But even better if it would get merged at some point 👍

@spscream
Copy link
Contributor Author

so what is the plan? I could rebase myself, this is not the problem

@lminiero
Copy link
Member

I'm out of office today, there's a few PRs (including this one) that I plan to review one last time and then merge early next week.

@lminiero
Copy link
Member

@spscream I wanted to merge this too, but I think merging your metadata PR introduced a new conflict here: could you fix this?

@spscream spscream force-pushed the feature/am/remote-forwarders-srtp branch 3 times, most recently from 835776a to 22d3dd0 Compare November 18, 2024 11:18
@spscream spscream force-pushed the feature/am/remote-forwarders-srtp branch from 22d3dd0 to 23c3a93 Compare November 18, 2024 11:20
@spscream
Copy link
Contributor Author

sure, updated

@lminiero lminiero merged commit 02cbae1 into meetecho:master Nov 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multistream Related to Janus 1.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants