Asterisk As Microsoft Teams Gateway

Hi,

Today I use Asterisk as a Gateway to Microsoft Teams with success.
To achieve this result, I statically modify the res_pjsip_nat.c file by replacing :
ast_sockaddr_stringify_host(&transport_state->external_signaling_address) with the FQDN of my server :

In function static pj_status_t nat_on_tx_message(pjsip_tx_data *tdata)

replace this line pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));

with this line pj_strdup2(tdata->pool, &uri->host, "<your asterisk FQDN>");

 and this line pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));
with this line pj_strdup2(tdata->pool, &via->sent_by.host, "<your asterisk FQDN>");

The FQDN is in fact used by Microsoft within the SIP:TLS frame to identify the client (Microsoft Tenant) in Teams direct routing use. The problem is that it is defined statically, compiled, and only valid for one Microsoft 365 Tenant.

Multi-Tenant is therefore not supported.

Would it be possible via the pjsip.conf configuration file to prevent the resolution of the FQDN, or specified manualy a client domain name, in certain desired cases?

Yes, it is indeed possible to configure PJSIP in Asterisk via the pjsip.conf file to specify manual settings for certain cases. Instead of modifying the source code of Asterisk, which could be cumbersome and non-portable across versions, it’s better to utilize the configuration options provided by Asterisk itself.

Here’s a basic example of how you might structure your pjsip.conf file to accommodate this:

[transport_tls_dynamic] ; Dynamic transport configuration for TLS
type=transport
protocol=tls
bind=0.0.0.0
cert_file=/path/to/your/certificate.crt
priv_key_file=/path/to/your/private/key.key

[transport_tls_static] ; Static transport configuration for TLS with a specific FQDN
type=transport
protocol=tls
bind=0.0.0.0
cert_file=/path/to/your/certificate.crt
priv_key_file=/path/to/your/private/key.key
external_signaling_address=

[endpoint_dynamic] ; Dynamic endpoint configuration
type=endpoint
context=dynamic_endpoint_context
transport=transport_tls_dynamic ; Use the dynamic transport configuration

[endpoint_static] ; Static endpoint configuration with a specific FQDN
type=endpoint
context=static_endpoint_context
transport=transport_tls_static ; Use the static transport configuration

; Define your dynamic and static contexts here in the Dialplan

Then, in your Dialplan, you define different contexts (dynamic_endpoint_context and static_endpoint_context ) to handle calls differently based on whether they use the dynamic or static endpoint configurations.

1 Like

Hi Danishhafeez !

Great idea, need to try this !!!

Many thanks for your suggestion !

For anyone who stumbles across this, a feature request was filed here[1].

[1] [improvement]: Asterisk As Microsoft Teams Gateway · Issue #30 · asterisk/asterisk-feature-requests · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.