Asterisk TLS+SRTP, 415 Unsupported Media Type

Hello to all. I configured Asterisk 15 + PJSIP + TLS + SRTP.
I want to use mutiregistration in the PJSIP.

I have two softphones: Bria 5 for android (TLS + SRTP) and a telephone for macos (upd, no encryption).
Both softphones are registered under one endpoint 1111 at the same time.

vs-ita-deb-01*CLI> pjsip show contacts

  Contact:  <Aor/ContactUri..............................> <Hash....> <Status> <RTT(ms)..>
==========================================================================================

  Contact:  andre/sip:andre@107.1.90.170:62550;ob      4f695c7b8f Avail       304.796
  Contact:  andre/sip:andre@107.1.90.170:62550;ob      4f695c7b8f Avail       304.796
  Contact:  andre/sip:andre@212.90.62.145:39952;transp 02562592f5 Avail        19.324
  Contact:  andre/sip:andre@212.90.62.145:39952;transp 02562592f5 Avail        19.324act:  

pjsip.conf
[transport-udp-nat]
type = transport
protocol = udp
bind = 0.0.0.0
; NAT settings
local_net=10.11.10.0/24
local_net=127.0.0.1/32
local_net=192.168.210.0/24
external_media_address = 85.34.54..184
external_signaling_address = 85.34.54..184

[transport-tls]
type=transport
protocol=tls
bind=0.0.0.0:443
ca_list_file=/etc/letsencrypt/live/pbx05.test.ua/fullchain.pem
cert_file=/etc/letsencrypt/live/pbx05.test.ua/cert.pem
priv_key_file=/etc/letsencrypt/live/pbx05.test.ua/privkey.pem
domain=pbx05.test.ua
external_media_address=85.34.54..184
external_signaling_address=85.34.54..184
require_client_cert=no
verify_client=no
verify_server=no
local_net=10.11.10.0/24
local_net=127.0.0.1/32
local_net=192.168.210.0/24
method=tlsv1
allow_reload=true

[endpoint-nat](!)
type = endpoint
context = context
allow = !all,opus,silk8,silk12,silk16
direct_media = no
trust_id_outbound = yes
device_state_busy_at = 2
dtmf_mode=rfc4733
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes

[aor-multiple-reg](!)
type = aor
max_contacts = 10
qualify_frequency = 300
[andre](endpoint-nat)
allow_subscribe=yes
auth = andre
aors = andre
media_encryption_optimistic=yes
media_encryption=sdes
callerid = K Andre <595402>

[andre](auth-userpass)
password = PASSWORD
username = andre

[andre](aor-multiple-reg)
mailboxes = 1111@example

Outgoing calls work without problems.

exten = 595402,1,Verbose(1, "User ${CALLERID(num)} dialed ${EXTEN}.")      
same = n,Set(DNUM=andre)    
same = n,Dial(${PJSIP_DIAL_CONTACTS(${DNUM})}${INTERNAL_DIAL_OPT})
same = n,Hangup(17)

But, I can’t make an incoming call to both softphones at the same time using the dialplan. One of phone answer “415 Unsupported Media Type”.

When I swich media_encryption_optimistic to yes - work telephone for macOS and swich to media_encryption_optimistic=no make Bria work.

pjsip.dump Here I make call from 5406 to 595402


Asterisk 15.7.1, Copyright (C) 1999 - 2016, Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================

Connected to Asterisk 15.7.1 currently running on vs-ita-deb-01 (pid = 526)
<--- Received SIP request (875 bytes) from UDP:10.13.30.11:5060 --->
INVITE sip:595402@10.11.10.7:5060 SIP/2.0
Via: SIP/2.0/UDP 10.13.30.11:5060;branch=z9hG4bK7670f997
Max-Forwards: 70
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7:5060>
Contact: <sip:5406@10.13.30.11:5060>
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 13.14.1~dfsg-2+deb9u4
Date: Mon, 21 Jan 2019 21:46:43 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 288

v=0
o=root 1935386886 1935386886 IN IP4 10.13.30.11
s=Asterisk PBX 13.14.1~dfsg-2+deb9u4
c=IN IP4 10.13.30.11
t=0 0
m=audio 14532 RTP/AVP 8 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

Setting global variable 'SIPDOMAIN' to '10.11.10.7'
<--- Transmitting SIP response (327 bytes) to UDP:10.13.30.11:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.13.30.11:5060;rport=5060;received=10.13.30.11;branch=z9hG4bK7670f997
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7>
CSeq: 102 INVITE
Server: Asterisk PBX 15.7.1
Content-Length:  0


    -- Executing [595402@zadarma-in:1] Verbose("PJSIP/tr-kv-ak01-0000000c", " "User 5406 dialed 595402."") in new stack
  "User 5406 dialed 595402."
    -- Executing [595402@zadarma-in:2] Set("PJSIP/tr-kv-ak01-0000000c", "DNUM=andre") in new stack 
    -- Executing [595402@zadarma-in:7] Dial("PJSIP/tr-kv-ak01-0000000c", "PJSIP/andre/sip:andre@212.90.62.145:39952;transport=TLS;rinstance=5d3d1e72eabb5309&PJSIP/andre/sip:andre@107.1.90.170:62550;ob,30") in new stack
[0K<--- Transmitting SIP request (1180 bytes) to TLS:212.90.62.145:39952 --->
INVITE sip:andre@212.90.62.145:39952;transport=TLS;rinstance=5d3d1e72eabb5309 SIP/2.0
Via: SIP/2.0/TLS 85.34.54..184:443;rport;branch=z9hG4bKPj8bff4b66-d286-4409-9c16-5826d7e314ca;alias
From: "Test User 6" <sip:5406@85.34.54..184>;tag=eafc2db5-56cf-402f-8b67-2ab1050e5daa
To: <sip:andre@212.90.62.145;rinstance=5d3d1e72eabb5309>
Contact: <sip:asterisk@85.34.54..184:443;transport=TLS>
Call-ID: 8cc95e90-9e6c-417f-91fb-8752b39cc54f
CSeq: 21564 INVITE
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 15.7.1
Content-Type: application/sdp
Content-Length:   415

v=0
o=- 1335118044 1335118044 IN IP4 85.34.54..184
s=Asterisk
c=IN IP4 85.34.54..184
t=0 0
m=audio 13738 RTP/AVP 107 98 109 113 101
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:9AC7CD9dy7ZfiYs6tHuyvTUMN56Kiy5Zbp4QIovV
a=rtpmap:107 opus/48000/2
a=rtpmap:98 SILK/8000
a=rtpmap:109 SILK/12000
a=rtpmap:113 SILK/16000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:20
a=sendrecv

    -- Called PJSIP/andre/sip:andre@212.90.62.145:39952;transport=TLS;rinstance=5d3d1e72eabb5309
    -- Called PJSIP/andre/sip:andre@107.1.90.170:62550;ob
    -- PJSIP/andre-0000000e connected line has changed. Saving it until answer for PJSIP/tr-kv-ak01-0000000c
    -- PJSIP/andre-0000000d connected line has changed. Saving it until answer for PJSIP/tr-kv-ak01-0000000c
[0K<--- Transmitting SIP request (1096 bytes) to UDP:107.1.90.170:62550 --->
INVITE sip:andre@107.1.90.170:62550;ob SIP/2.0
Via: SIP/2.0/UDP 85.34.54..184:5060;rport;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>
Contact: <sip:asterisk@85.34.54..184:5060>
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
CSeq: 10294 INVITE
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 15.7.1
Content-Type: application/sdp
Content-Length:   413

v=0
o=- 797474622 797474622 IN IP4 85.34.54..184
s=Asterisk
c=IN IP4 85.34.54..184
t=0 0
m=audio 13322 RTP/AVP 107 98 109 113 101
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:Es6NyopK/WK8SgCiHHX2MMOJ0FrVJUzOjEXGDzbj
a=rtpmap:107 opus/48000/2
a=rtpmap:98 SILK/8000
a=rtpmap:109 SILK/12000
a=rtpmap:113 SILK/16000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:20
a=sendrecv

[0K<--- Received SIP response (424 bytes) from TLS:212.90.62.145:39952 --->
SIP/2.0 415 Unsupported Media Type
Via: SIP/2.0/TLS 85.34.54..184:443;rport=443;branch=z9hG4bKPj8bff4b66-d286-4409-9c16-5826d7e314ca;alias
To: <sip:andre@212.90.62.145;rinstance=5d3d1e72eabb5309>;tag=d61d3620
From: "Test User 6" <sip:5406@85.34.54..184>;tag=eafc2db5-56cf-402f-8b67-2ab1050e5daa
Call-ID: 8cc95e90-9e6c-417f-91fb-8752b39cc54f
CSeq: 21564 INVITE
User-Agent: Zoiper rv2.8.87-mod
Content-Length: 0


[0K<--- Transmitting SIP request (486 bytes) to TLS:212.90.62.145:39952 --->
ACK sip:andre@212.90.62.145:39952;transport=TLS;rinstance=5d3d1e72eabb5309 SIP/2.0
Via: SIP/2.0/TLS 85.34.54..184:443;rport;branch=z9hG4bKPj8bff4b66-d286-4409-9c16-5826d7e314ca;alias
From: "Test User 6" <sip:5406@85.34.54..184>;tag=eafc2db5-56cf-402f-8b67-2ab1050e5daa
To: <sip:andre@212.90.62.145;rinstance=5d3d1e72eabb5309>;tag=d61d3620
Call-ID: 8cc95e90-9e6c-417f-91fb-8752b39cc54f
CSeq: 21564 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 15.7.1
Content-Length:  0


[0K<--- Received SIP response (358 bytes) from UDP:107.1.90.170:62550 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 85.34.54..184:5060;rport=5060;received=85.34.54..184;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>
CSeq: 10294 INVITE
Content-Length:  0


[0K<--- Received SIP response (550 bytes) from UDP:107.1.90.170:62550 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 85.34.54..184:5060;rport=5060;received=85.34.54..184;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>;tag=eaBkYZJIHsZWXNcNDDjk-WSeyTE3QrmN
CSeq: 10294 INVITE
Contact: "andre" <sip:andre@192.168.4.10:54098;ob>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length:  0


    -- PJSIP/andre-0000000e is ringing
[0K<--- Transmitting SIP response (516 bytes) to UDP:10.13.30.11:5060 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.13.30.11:5060;rport=5060;received=10.13.30.11;branch=z9hG4bK7670f997
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7>;tag=7d2434e3-1dca-4c79-aa7a-786f18e5618f
CSeq: 102 INVITE
Server: Asterisk PBX 15.7.1
Contact: <sip:85.34.54..184:5060>
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER
Content-Length:  0


    -- PJSIP/andre-0000000e is ringing
[0K<--- Received SIP request (359 bytes) from UDP:10.13.30.11:5060 --->
CANCEL sip:595402@10.11.10.7:5060 SIP/2.0
Via: SIP/2.0/UDP 10.13.30.11:5060;branch=z9hG4bK7670f997
Max-Forwards: 70
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7:5060>
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
CSeq: 102 CANCEL
User-Agent: Asterisk PBX 13.14.1~dfsg-2+deb9u4
Content-Length: 0


[0K<--- Transmitting SIP response (364 bytes) to UDP:10.13.30.11:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.13.30.11:5060;rport=5060;received=10.13.30.11;branch=z9hG4bK7670f997
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7>;tag=7d2434e3-1dca-4c79-aa7a-786f18e5618f
CSeq: 102 CANCEL
Server: Asterisk PBX 15.7.1
Content-Length:  0


<--- Transmitting SIP response (491 bytes) to UDP:10.13.30.11:5060 --->
SIP/2.0 487 Request Terminated
Via: SIP/2.0/UDP 10.13.30.11:5060;rport=5060;received=10.13.30.11;branch=z9hG4bK7670f997
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7>;tag=7d2434e3-1dca-4c79-aa7a-786f18e5618f
CSeq: 102 INVITE
Server: Asterisk PBX 15.7.1
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER
Content-Length:  0


[1;30m  == Spawn extension (zadarma-in, 595402, 7) exited non-zero on 'PJSIP/tr-kv-ak01-0000000c'
[1;30m    -- Executing [h@zadarma-in:1] Hangup("PJSIP/tr-kv-ak01-0000000c", "") in new stack
[1;30m  == Spawn extension (zadarma-in, h, 1) exited non-zero on 'PJSIP/tr-kv-ak01-0000000c'
<--- Transmitting SIP request (433 bytes) to UDP:107.1.90.170:62550 --->
CANCEL sip:andre@107.1.90.170:62550;ob SIP/2.0
Via: SIP/2.0/UDP 85.34.54..184:5060;rport;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
CSeq: 10294 CANCEL
Reason: Q.850;cause=0
Max-Forwards: 70
User-Agent: Asterisk PBX 15.7.1
Content-Length:  0


[0K<--- Received SIP request (429 bytes) from UDP:10.13.30.11:5060 --->
ACK sip:85.34.54..184:5060 SIP/2.0
Via: SIP/2.0/UDP 10.13.30.11:5060;branch=z9hG4bK7670f997
Max-Forwards: 70
From: "Test User 6" <sip:5406@10.13.30.11>;tag=as4c252777
To: <sip:595402@10.11.10.7:5060>;tag=7d2434e3-1dca-4c79-aa7a-786f18e5618f
Contact: <sip:5406@10.13.30.11:5060>
Call-ID: 62d5209a4363d83e4d5d539e5c2302cb@10.13.30.11:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX 13.14.1~dfsg-2+deb9u4
Content-Length: 0


[0K<--- Received SIP response (391 bytes) from UDP:107.1.90.170:62550 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 85.34.54..184:5060;rport=5060;received=85.34.54..184;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>;tag=eaBkYZJIHsZWXNcNDDjk-WSeyTE3QrmN
CSeq: 10294 CANCEL
Content-Length:  0


[0K<--- Received SIP response (505 bytes) from UDP:107.1.90.170:62550 --->
SIP/2.0 487 Request Terminated
Via: SIP/2.0/UDP 85.34.54..184:5060;rport=5060;received=85.34.54..184;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>;tag=eaBkYZJIHsZWXNcNDDjk-WSeyTE3QrmN
CSeq: 10294 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length:  0


[0K<--- Transmitting SIP request (441 bytes) to UDP:107.1.90.170:62550 --->
ACK sip:andre@107.1.90.170:62550;ob SIP/2.0
Via: SIP/2.0/UDP 85.34.54..184:5060;rport;branch=z9hG4bKPj3fb03370-36df-4532-b425-d66649464fde
From: "Test User 6" <sip:5406@85.34.54..184>;tag=dc242cea-e221-4358-87df-b62f157f329b
To: <sip:andre@107.1.90.170;ob>;tag=eaBkYZJIHsZWXNcNDDjk-WSeyTE3QrmN
Call-ID: f1d76d8d-5f6d-4ea8-b864-12f409b32cdf
CSeq: 10294 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 15.7.1
Content-Length:  0

There’s nothing in Asterisk you can really do to control the remote endpoints. You need to ensure they can all support the configuration you have set, or use separate endpoints/AORs.

I don’t nead to control remote endpoints. I have two contacts with different transports and I just need to send different INVITE to the contact with TLS and UDP.

To UDP contact
m=audio 13322 RTP/AVP 107 98 109 113 101

To TLS contact
m=audio 13322 RTP/SAVP 107 98 109 113 101

You can’t. The endpoint configuration is what controls that, and there is no ability to differentiate the configuration.

I turn to the side of evil, there are cookies. FREESWITCH