res_pjsip: Implement additional SIP RFCs for Google Voice trunk compatability

This change implements a few different generic things which were brought
on by Google Voice SIP.

1.  The concept of flow transports have been introduced.  These are
configurable transports in pjsip.conf which can be used to reference a
flow of signaling to a target.  These have runtime configuration that can
be changed by the signaling itself (such as Service-Routes and
P-Preferred-Identity).  When used these guarantee an individual connection
(in the case of TCP or TLS) even if multiple flow transports exist to the
same target.

2.  Service-Routes (RFC 3608) support has been added to the outbound
registration module which when received will be stored on the flow
transport and used for requests referencing it.

3.  P-Associated-URI / P-Preferred-Identity (RFC 3325) support has been
added to the outbound registration module.  If a P-Associated-URI header
is received it will be used on requests as the P-Preferred-Identity.

4.  Configurable outbound extension support has been added to the outbound
registration module.  When set the extension will be placed in the
Supported header.

5.  Header parameters can now be configured on an outbound registration
which will be placed in the Contact header.

6.  Google specific OAuth / Bearer token authentication
(draft-ietf-sipcore-sip-authn-02) has been added to the outbound
registration module.

All functionality changes are controlled by pjsip.conf configuration
options and do not affect non-configured pjsip endpoints otherwise.

ASTERISK-27971 #close

Change-Id: Id214c2d1c550a41fcf564b7df8f3da7be565bd58
This commit is contained in:
Nick French
2018-07-18 07:45:26 -05:00
committed by George Joseph
parent 51b5f0f193
commit 37b2e68628
16 changed files with 1190 additions and 52 deletions

View File

@@ -0,0 +1,115 @@
"""add pjsip google voice sip options
Revision ID: 465f47f880be
Revises: 7f85dd44c775
Create Date: 2018-09-25 17:26:12.892161
"""
# revision identifiers, used by Alembic.
revision = '465f47f880be'
down_revision = '7f85dd44c775'
from alembic import op
from sqlalchemy.dialects.postgresql import ENUM
import sqlalchemy as sa
AST_BOOL_NAME = 'ast_bool_values'
# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write
# those aliases.
AST_BOOL_VALUES = [ '0', '1',
'off', 'on',
'false', 'true',
'no', 'yes' ]
PJSIP_TRANSPORT_PROTOCOL_OLD_NAME = 'pjsip_transport_protocol_values'
PJSIP_TRANSPORT_PROTOCOL_NEW_NAME = 'pjsip_transport_protocol_values_v2'
PJSIP_TRANSPORT_PROTOCOL_OLD_VALUES = ['udp', 'tcp', 'tls', 'ws', 'wss']
PJSIP_TRANSPORT_PROTOCOL_NEW_VALUES = ['udp', 'tcp', 'tls', 'ws', 'wss', 'flow']
PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE = sa.Enum(*PJSIP_TRANSPORT_PROTOCOL_OLD_VALUES,
name=PJSIP_TRANSPORT_PROTOCOL_OLD_NAME)
PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE = sa.Enum(*PJSIP_TRANSPORT_PROTOCOL_NEW_VALUES,
name=PJSIP_TRANSPORT_PROTOCOL_NEW_NAME)
PJSIP_AUTH_TYPE_OLD_NAME = 'pjsip_auth_type_values'
PJSIP_AUTH_TYPE_NEW_NAME = 'pjsip_auth_type_values_v2'
PJSIP_AUTH_TYPE_OLD_VALUES = ['md5', 'userpass']
PJSIP_AUTH_TYPE_NEW_VALUES = ['md5', 'userpass', 'google_oauth']
PJSIP_AUTH_TYPE_OLD_TYPE = sa.Enum(*PJSIP_AUTH_TYPE_OLD_VALUES,
name=PJSIP_AUTH_TYPE_OLD_NAME)
PJSIP_AUTH_TYPE_NEW_TYPE = sa.Enum(*PJSIP_AUTH_TYPE_NEW_VALUES,
name=PJSIP_AUTH_TYPE_NEW_NAME)
def upgrade():
if op.get_context().bind.dialect.name == 'postgresql':
enum = PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE
enum.create(op.get_bind(), checkfirst=False)
op.execute('ALTER TABLE ps_transports ALTER COLUMN protocol TYPE'
' ' + PJSIP_TRANSPORT_PROTOCOL_NEW_NAME + ' USING'
' protocol::text::' + PJSIP_TRANSPORT_PROTOCOL_NEW_NAME)
ENUM(name=PJSIP_TRANSPORT_PROTOCOL_OLD_NAME).drop(op.get_bind(), checkfirst=False)
enum = PJSIP_AUTH_TYPE_NEW_TYPE
enum.create(op.get_bind(), checkfirst=False)
op.execute('ALTER TABLE ps_auths ALTER COLUMN auth_type TYPE'
' ' + PJSIP_AUTH_TYPE_NEW_NAME + ' USING'
' auth_type::text::' + PJSIP_AUTH_TYPE_NEW_NAME)
ENUM(name=PJSIP_AUTH_TYPE_OLD_NAME).drop(op.get_bind(), checkfirst=False)
else:
op.alter_column('ps_transports', 'protocol',
type_=PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE,
existing_type=PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE)
op.alter_column('ps_auths', 'auth_type',
type_=PJSIP_AUTH_TYPE_NEW_TYPE,
existing_type=PJSIP_AUTH_TYPE_OLD_TYPE)
# ast_bool_values have already been created, so use postgres enum object
# type to get around "already created" issue - works okay with mysql
ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
op.add_column('ps_registrations', sa.Column('support_outbound', ast_bool_values))
op.add_column('ps_registrations', sa.Column('contact_header_params', sa.String(255)))
op.add_column('ps_auths', sa.Column('refresh_token', sa.String(255)))
op.add_column('ps_auths', sa.Column('oauth_clientid', sa.String(255)))
op.add_column('ps_auths', sa.Column('oauth_secret', sa.String(255)))
def downgrade():
# First we need to ensure that columns are not using the enum values
# that are going away.
op.execute("UPDATE ps_transports SET protocol='udp' WHERE protocol='flow'")
op.execute("UPDATE ps_auths SET auth_type='userpass' WHERE auth_type='google_oauth'")
if op.get_context().bind.dialect.name == 'postgresql':
enum = PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE
enum.create(op.get_bind(), checkfirst=False)
op.execute('ALTER TABLE ps_transports ALTER COLUMN protocol TYPE'
' ' + PJSIP_TRANSPORT_PROTOCOL_OLD_NAME + ' USING'
' protocol::text::' + PJSIP_TRANSPORT_PROTOCOL_OLD_NAME)
ENUM(name=PJSIP_TRANSPORT_PROTOCOL_NEW_NAME).drop(op.get_bind(), checkfirst=False)
enum = PJSIP_AUTH_TYPE_OLD_TYPE
enum.create(op.get_bind(), checkfirst=False)
op.execute('ALTER TABLE ps_auths ALTER COLUMN auth_type TYPE'
' ' + PJSIP_AUTH_TYPE_OLD_NAME + ' USING'
' auth_type::text::' + PJSIP_AUTH_TYPE_OLD_NAME)
ENUM(name=PJSIP_AUTH_TYPE_NEW_NAME).drop(op.get_bind(), checkfirst=False)
else:
op.alter_column('ps_transports', 'protocol',
type_=PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE,
existing_type=PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE)
op.alter_column('ps_auths', 'auth_type',
type_=PJSIP_AUTH_TYPE_OLD_TYPE,
existing_type=PJSIP_AUTH_TYPE_NEW_TYPE)
op.drop_column('ps_registrations', 'support_outbound')
op.drop_column('ps_registrations', 'contact_header_params')
op.drop_column('ps_auths', 'refresh_token')
op.drop_column('ps_auths', 'oauth_clientid')
op.drop_column('ps_auths', 'oauth_secret')