Adding signed_tokens to audiobridge#3635
Conversation
|
Thanks for your contribution, @mirkobrankovic82! Please make sure you sign our CLA, as it's a required step before we can merge this. |
|
Thanks! From a cursory glance it looks ok, I'll need to test this. As a side note, you may want to update the main documentation too, as we currently have text that says:
|
Thanks Lorenzo, Pushed commit with Docs update |
|
@lminiero I tested it with missing HMAC token with token: Now i'm not only sure how to test expired token usage, maybe if i set timestamp in the past? Also I don't understand how long should these token live, or how long the timestamp should be, cause for example mod_janus uses one session for all requests, so should I use long lasting token then ? and browsers can use how much i expect session to last max? |
The documentation has a Node.js snippet you can use to generate tokens. I guess you can simply modify the date they use to generate the token to generate an older one, or use a very short timeout to see it working first and then fail.
I don't think there's a rule: it's probably up to you and application specific. |
| json_t *token = json_object_get(root, "token"); | ||
| const char *token_text = token ? json_string_value(token) : NULL; | ||
| if(token_text == NULL || g_hash_table_lookup(audiobridge->allowed, token_text) == NULL) { | ||
| JANUS_LOG(LOG_ERR, "Unauthorized (not in the allowed list)\n"); |
There was a problem hiding this comment.
@mirkobrankovic82 one thing I noticed is that the check of token for the ACL is still there even when using signed tokens. This means that, if someone enables both signed tokens and ACL, the same token will be checked twice, and probably fail in one of the two since they're incompatible. I don't think it's an issue specific to your patch, since from what I can see it's in the VideoRoom too. Just mentioning so that we can keep track of it in the future, e.g., in a follow-up PR that should maybe check if both signed tokens and ACL are enabled when creating a room, and in case fail with an error so that we only accept one.
@mirkobrankovic82 FYI I made a few tests doing exactly that, trying to see how I could get AudioBridge tokens to fail, and it seems to be working as expected. I created a longer token for connecting to the handle (core), and a much shorter (60s) one for joining the AudioBridge: initially I could connect, and about a minute later I couldnt. So as far as I'm concerned, this seems to be working fine, thanks! Was there anything else you wanted to add or edit, or is this complete and good to merge for you? |
|
I'll merge in the meanwhile, since it seems to be working fine for me. In case you think there's something to revisit, we can address that in other commits. |
|
hey @lminiero, |
Summary
Adds optional HMAC signed (time-limited) token enforcement for the AudioBridge plugin, aligned with the existing VideoRoom behavior when Janus core signed-token mode is enabled (
token_auth+token_auth_secretinjanus.jcfg).Changes
signed_tokens: set via dynamiccreateand/or staticjanus.plugin.audiobridge.jcfg; written to config when saving permanent rooms (create/edit paths that persist the room).joinandchangeroom, when core signed mode is on and the room hassigned_tokens, validates the messagetokenviaauth_signature_containswith descriptorroom=<room_id>, before PIN and the opaqueallowedlist check.signed_tokensin the.jcfgexample and thecreateJSON example.Usage
token_auth+token_auth_secret).signed_tokens: true(orsigned_tokens = truein the room’s.jcfgsection).tokenwhose signed payload includesjanus.plugin.audiobridgeandroom=<id>(same signing rules as VideoRoom room tokens; see Janus auth docs).Notes
signed_tokenson a room logs a warning and does not turn on enforcement (same idea as VideoRoom).allowedopaque token list remain unchanged; signed tokens are an extra option for server-minted, expiring join credentials.