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

plugins/janus_sip.c: MESSAGE Authentication and Deliver Status Report #2786

Merged
merged 8 commits into from
Nov 22, 2021

Conversation

thetechpanda
Copy link
Contributor

CHANGE: sets MESSAGE Call-ID if not defined in the message event
ADD: SIP Authentication for 401 and 407 reponse to Message
ADD: messagedelivery event to report delivery status back to the peer

CHANGE: sets MESSAGE Call-ID if not defined in the message event
ADD: SIP Authentication for 401 and 407 reponse to Message
ADD: messagedelivery event to report delivery status back to the peer
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.

Thanks! Added some notes inline.

plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
@lminiero
Copy link
Member

@thetechpanda any update on this? I'm planning to do a new release soon, so I was wondering if we should wait for this too, or leave it for the next update. Thanks!

@thetechpanda
Copy link
Contributor Author

thetechpanda commented Oct 16, 2021 via email

@lminiero
Copy link
Member

@thetechpanda if you made some changes feel free to push them, then, and we'll review if they're ok. In case there's still something to fix, no problem for me to keep this on hold until you can get back to it, and publish a new release without this for the moment.

…ginating session

CHANGE removes redundant call_id and delivery status from deliveryrecepit (available through root call_id and code)
@thetechpanda
Copy link
Contributor Author

I pushed the changes they should be ok. let me know if you need me to fix anything else. cheers!

@thetechpanda
Copy link
Contributor Author

Hi @lminiero did you get a chance to look at my changes? Not being pushy I'm just very excited this could get actually get merged :)

@lminiero
Copy link
Member

@thetechpanda not yet, sorry, I was busy with preparations for a presentation I had to make. I'll look at this before the weekend, thanks!

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.

Just checked the code, and I see some potentially serious issues that need to be addressed. Once they are, I think this should be tested before it can be merged. Thanks for taking the time to expand this effort!

plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
* FIX: html div tag closed wrongly
* ADD: demo sip message UI
* FIX: plugins/janus_sip.c messagedelivery session handling
* ADD: plugins/janus_sip.c messagedelivery documentation
@thetechpanda
Copy link
Contributor Author

Hello,

I've rebuilt the test bench, using kamailio. I've tested using http and websocket transports and done multiple tests sending and receiving messages. I've debugged as extensively as I can, I've not seen any unexpected behaviour and I've carefully reviewed the locks, hope this time the patch is worthy or your time.

I've also added some documentation at the top of the plugin to cater for the new behaviour: optional call_id for message requests and messagedelivery event documentation.

I've noticed something, sending messages via Helpers works as expected and the messagedelivery event is correctly sent to the master or the helper. However inbound messages are always notified to the master session - I don't see an issue with it.

Let me know,

Kind Regards,

Comment on lines +5488 to +5537
const char *scheme = NULL;
const char *realm = NULL;
if(status == 401) {
/* Get scheme/realm from 401 error */
sip_www_authenticate_t const* www_auth = sip->sip_www_authenticate;
scheme = www_auth->au_scheme;
realm = msg_params_find(www_auth->au_params, "realm=");
} else {
/* Get scheme/realm from 407 error, proxy-auth */
sip_proxy_authenticate_t const* proxy_auth = sip->sip_proxy_authenticate;
scheme = proxy_auth->au_scheme;
realm = msg_params_find(proxy_auth->au_params, "realm=");
}
char authuser[100], secret[100];
memset(authuser, 0, sizeof(authuser));
memset(secret, 0, sizeof(secret));
if(session->helper) {
/* This is an helper session, we'll need the credentials from the master */
if(session->master == NULL) {
JANUS_LOG(LOG_WARN, "No master session for this helper, authentication will fail...\n");
} else {
session = session->master;
}
}
if(session->account.authuser && strchr(session->account.authuser, ':')) {
/* The authuser contains a colon: wrap it in quotes */
g_snprintf(authuser, sizeof(authuser), "\"%s\"", session->account.authuser);
} else {
g_snprintf(authuser, sizeof(authuser), "%s", session->account.authuser);
}
if(session->account.secret && strchr(session->account.secret, ':')) {
/* The secret contains a colon: wrap it in quotes */
g_snprintf(secret, sizeof(secret), "\"%s\"", session->account.secret);
} else {
g_snprintf(secret, sizeof(secret), "%s", session->account.secret);
}
char auth[256];
memset(auth, 0, sizeof(auth));
g_snprintf(auth, sizeof(auth), "%s%s:%s:%s:%s%s",
session->account.secret_type == janus_sip_secret_type_hashed ? "HA1+" : "",
scheme,
realm,
authuser,
session->account.secret_type == janus_sip_secret_type_hashed ? "HA1+" : "",
secret);
JANUS_LOG(LOG_VERB, "\t%s\n", auth);
/* Authenticate */
nua_authenticate(nh,
NUTAG_AUTH(auth),
TAG_END());
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed that this bloc of code repeated the third time. Could we move it to a separate function?

I am implementing publish command and will repeat it a fourth time. For sure I could do it in my PR, just curious is it the right way of refactoring, or is there some other sense in repeating the same code several times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be a function or could be before the main switch(event) in janus_sip_sofia_callback. Auth and ProxyAuth are not used outside of this function, IMHO it is better to split code into functions only if used elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

We do re-use the same auth code for different SIP responses, true. Anyway, this isn't something I'd do here: this is a change I'd do separately in another PR, devoted just to that, so I can look into this once we merge this effort.

@lminiero
Copy link
Member

lminiero commented Nov 8, 2021

Hello,

I've rebuilt the test bench, using kamailio. I've tested using http and websocket transports and done multiple tests sending and receiving messages. I've debugged as extensively as I can, I've not seen any unexpected behaviour and I've carefully reviewed the locks, hope this time the patch is worthy or your time.

Contributions are always worthy of my time! ☺️
I'll try to make some tests, too, e.g., to check if there can be minor leaks 👍

I've also added some documentation at the top of the plugin to cater for the new behaviour: optional call_id for message requests and messagedelivery event documentation.

Ack, thx!

I've noticed something, sending messages via Helpers works as expected and the messagedelivery event is correctly sent to the master or the helper. However inbound messages are always notified to the master session - I don't see an issue with it.

I guess this depends on what kind of message this is. If this is an out-of-dialog MESSAGE, then yes, it will be delivered to the owner of SIP stack, so the master session: if it's an in-dialog MESSAGE, though, as part of an ongoing call, it should go to the session that's actually handling that call. I guess you tested the former? We'll probably also want to make some tests with in-dialog MESSAGE transactions, just to make sure nothing breaks there.

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.

Just checked your changes, and added some more notes inline 👍

html/siptest.html Outdated Show resolved Hide resolved
html/siptest.js Outdated Show resolved Hide resolved
html/siptest.js Outdated Show resolved Hide resolved
plugins/janus_sip.c Show resolved Hide resolved
plugins/janus_sip.c Outdated Show resolved Hide resolved
* CHANGE: introduces sip_session_dereference
* CHANGE: html/siptest.js doMessage() renames suffix to helperId
* FIX: html/siptest.js helpers failing to make calls if they previously attempted to make a call to invalid SIP uri
@thetechpanda
Copy link
Contributor Author

I've done the requested changes, I'm not too sure about the function name janus_sip_session_dereference as it is used only by the messageids hashtable.

I've tested in-dialog and out-of-dialog messages and seem to work as expected. I've also fixed an issue I was having with siptest.js where the helpers could not make the call after trying to dial an invalid SIP uri.

If you still feel we don't need the out-of-dialog message UI, let me know and I'll revert the changes, if you want me to change the ui I am more than happy to do further changes.

Apologies for the long time this is taking and thank you for taking the time to review my code.

@lminiero
Copy link
Member

Apologies for the delay, but I've been quite busy last week. Your latest changes do look fine to me now! To address your notes:

I'm not too sure about the function name janus_sip_session_dereference as it is used only by the messageids hashtable.

That's fine: it's a good function to have in case we'll need it again for other hashtables or lists in the future.

If you still feel we don't need the out-of-dialog message UI, let me know and I'll revert the changes, if you want me to change the ui I am more than happy to do further changes.

Yeah, I personally don't think we need this new UI, which would complicate and make the UI even more confusing than it currently is (which is my fault!). For now, I think it's enough to have it documented in Doxygen that "message" can be used both in-dialog and out-of-dialog. We can always consider changes to the UI in separate PRs in the future, if it's needed.

Apologies for the long time this is taking and thank you for taking the time to review my code.

No problem at all, no one's in a hurry! I always appreciate contributions, and I know people are busy, so I never expect anyone to do things any faster than they can/want: that's how open source works 🙂

@thetechpanda
Copy link
Contributor Author

For some reason VSCode kept changing the spacing for my changes after I'd save, hope you don't mind the two styling commits in the latest code push.

I've removed the out-of-dialog ui, anything else you'd like me to address?

@lminiero
Copy link
Member

I think that the two </div> fixes are actually correct, and a typo on my end originally.
Looks good now, thanks again for the effort and the patience! Merging 👍

@lminiero lminiero merged commit d5e3d2e into meetecho:master Nov 22, 2021
@thetechpanda
Copy link
Contributor Author

thetechpanda commented Nov 22, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants