<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18186">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_pjsip: Add secure bridge signaling and media.<br><br>Adds support to PJSIP for the channel tech-agnostic<br>secure_bridge_signaling and secure_bridge_media options.<br><br>These options can both be read or set as with chan_sip<br>and other supporting channel drivers.<br><br>ASTERISK-26329<br><br>Change-Id: I089ec68601c80daf293193c8f4933fd87d7b2a17<br>---<br>M channels/chan_pjsip.c<br>1 file changed, 84 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/86/18186/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index e8fbb3d..ccbfa6d 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -102,6 +102,7 @@</span><br><span> static int chan_pjsip_transfer(struct ast_channel *ast, const char *target);</span><br><span> static int chan_pjsip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);</span><br><span> static int chan_pjsip_devicestate(const char *data);</span><br><span style="color: hsl(120, 100%, 40%);">+static int chan_pjsip_setoption(struct ast_channel *ast, int option, void *data, int datalen);</span><br><span> static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);</span><br><span> static const char *chan_pjsip_get_uniqueid(struct ast_channel *ast);</span><br><span> </span><br><span>@@ -126,6 +127,7 @@</span><br><span> .transfer = chan_pjsip_transfer,</span><br><span> .fixup = chan_pjsip_fixup,</span><br><span> .devicestate = chan_pjsip_devicestate,</span><br><span style="color: hsl(120, 100%, 40%);">+ .setoption = chan_pjsip_setoption,</span><br><span> .queryoption = chan_pjsip_queryoption,</span><br><span> .func_channel_read = pjsip_acf_channel_read,</span><br><span> .get_pvt_uniqueid = chan_pjsip_get_uniqueid,</span><br><span>@@ -1234,12 +1236,66 @@</span><br><span> return state;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Function called to set options on a channel */</span><br><span style="color: hsl(120, 100%, 40%);">+static int chan_pjsip_setoption(struct ast_channel *ast, int option, void *data, int datalen)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PJSIP_GET_DEST_INFO</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_dialog *dlg;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_host_info dest;</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_pool_t *pool;</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (option) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_OPTION_SECURE_SIGNALING:</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PJSIP_GET_DEST_INFO</span><br><span style="color: hsl(120, 100%, 40%);">+ dlg = channel->session->inv_session->dlg;</span><br><span style="color: hsl(120, 100%, 40%);">+ pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "secure-check", 128, 128);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_get_dest_info(dlg->target, NULL, pool, &dest);</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((*(unsigned int *) data) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ dest.flag &= ~PJSIP_TRANSPORT_SECURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if ((*(unsigned int *) data) == 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ dest.flag |= PJSIP_TRANSPORT_SECURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject which does not have the required functionality to support secure_bridge_signaling. Please upgrade to version 2.3 or later.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_OPTION_SECURE_MEDIA:</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((*(unsigned int *) data) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ channel->session->endpoint->media.rtp.encryption = AST_SIP_MEDIA_ENCRYPT_NONE;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if ((*(unsigned int *) data) == 1 && channel->session->endpoint->media.rtp.encryption != AST_SIP_MEDIA_ENCRYPT_DTLS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If we're not already configured to do DTLS, add SDES encryption. Otherwise, leave as is. */</span><br><span style="color: hsl(120, 100%, 40%);">+ channel->session->endpoint->media.rtp.encryption = AST_SIP_MEDIA_ENCRYPT_SDES;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ default:</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Function called to query options on a channel */</span><br><span> static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)</span><br><span> {</span><br><span> struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);</span><br><span> int res = -1;</span><br><span> enum ast_t38_state state = T38_STATE_UNAVAILABLE;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session_media *media;</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PJSIP_GET_DEST_INFO</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_dialog *dlg;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_host_info dest;</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_pool_t *pool;</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span> </span><br><span> if (!channel) {</span><br><span> return -1;</span><br><span>@@ -1269,6 +1325,34 @@</span><br><span> res = 0;</span><br><span> </span><br><span> break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_OPTION_SECURE_SIGNALING:</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PJSIP_GET_DEST_INFO</span><br><span style="color: hsl(120, 100%, 40%);">+ dlg = channel->session->inv_session->dlg;</span><br><span style="color: hsl(120, 100%, 40%);">+ pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "secure-check", 128, 128);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_get_dest_info(dlg->target, NULL, pool, &dest);</span><br><span style="color: hsl(120, 100%, 40%);">+ *((unsigned int *) data) = dest.flag & PJSIP_TRANSPORT_SECURE ? 1 : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Asterisk has been built against a version of pjproject which does not have the required functionality to support secure_bridge_signaling. Please upgrade to version 2.3 or later.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_OPTION_SECURE_MEDIA:</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (channel->session->endpoint->media.rtp.encryption) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_SIP_MEDIA_ENCRYPT_SDES:</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_SIP_MEDIA_ENCRYPT_DTLS:</span><br><span style="color: hsl(120, 100%, 40%);">+ media = channel->session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO];</span><br><span style="color: hsl(120, 100%, 40%);">+ *((unsigned int *) data) = ast_test_flag(media->srtp, AST_SRTP_CRYPTO_OFFER_OK) ? 1 : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_SIP_MEDIA_ENCRYPT_NONE:</span><br><span style="color: hsl(120, 100%, 40%);">+ *((unsigned int *) data) = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ default: /* includes AST_SIP_MEDIA_TRANSPORT_INVALID */</span><br><span style="color: hsl(120, 100%, 40%);">+ *((unsigned int *) data) = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span> default:</span><br><span> break;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18186">change 18186</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18186"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I089ec68601c80daf293193c8f4933fd87d7b2a17 </div>
<div style="display:none"> Gerrit-Change-Number: 18186 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>