Compare commits

...

10 Commits

Author SHA1 Message Date
Joshua Colp
6afc128fee Update for 13.17.2 2017-09-19 11:05:14 -05:00
Richard Mudgett
01b56b7a71 AST-2017-008: Improve RTP and RTCP packet processing.
Validate RTCP packets before processing them.

* Validate that the received packet is of a minimum length and apply the
RFC3550 RTCP packet validation checks.

* Fixed potentially reading garbage beyond the received RTCP record data.

* Fixed rtp->themssrc only being set once when the remote could change
the SSRC.  We would effectively stop handling the RTCP statistic records.

* Fixed rtp->themssrc to not treat a zero value as special by adding
rtp->themssrc_valid to indicate if rtp->themssrc is available.

ASTERISK-27274

Make strict RTP learning more flexible.

Direct media can cause strict RTP to attempt to learn a remote address
again before it has had a chance to learn the remote address the first
time.  Because of the rapid relearn requests, strict RTP could latch onto
the first remote address and fail to latch onto the direct media remote
address.  As a result, you have one way audio until the call is placed on
and off hold.

The new algorithm learns remote addresses for a set time (1.5 seconds)
before locking the remote address.  In addition, we must see a configured
number of remote packets from the same address in a row before switching.

* Fixed strict RTP learning from always accepting the first new address
packet as the new stream.

* Fixed strict RTP to initialize the expected sequence number with the
last received sequence number instead of the last transmitted sequence
number.

* Fixed the predicted next sequence number calculation in
rtp_learning_rtp_seq_update() to handle overflow.

ASTERISK-27252

Change-Id: Ia2d3aa6e0f22906c25971e74f10027d96525f31c
2017-09-15 15:47:18 -05:00
Kevin Harwell
49d56dc9d2 Update for 13.17.1 2017-08-31 10:44:55 -05:00
Joshua Colp
e1b755ac30 Merge "pjsip_message_ip_updater: Fix issue handling "tel" URIs" into 13.17 2017-08-31 06:38:42 -05:00
Joshua Colp
55646e51d6 Merge "AST-2017-006: Fix app_minivm application MinivmNotify command injection" into 13.17 2017-08-31 06:36:10 -05:00
George Joseph
0e5b7743d9 pjsip_message_ip_updater: Fix issue handling "tel" URIs
sanitize_tdata was assuming all URIs were SIP URIs so when a non
SIP uri was in the From, To or Contact headers, the unconditional
cast of a non-pjsip_sip_uri structure to pjsip_sip_uri caused
a segfault when trying to access uri->other_param.

* Added PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri)
  checks before attempting to cast or use the returned uri.

ASTERISK-27152
Reported-by: Ross Beer

Change-Id: Id380df790e6622c8058a96035f8b8f4aa0b8551f
2017-08-30 18:48:58 +00:00
Corey Farrell
707892089d AST-2017-006: Fix app_minivm application MinivmNotify command injection
An admin can configure app_minivm with an externnotify program to be run
when a voicemail is received.  The app_minivm application MinivmNotify
uses ast_safe_system() for this purpose which is vulnerable to command
injection since the Caller-ID name and number values given to externnotify
can come from an external untrusted source.

* Add ast_safe_execvp() function.  This gives modules the ability to run
external commands with greater safety compared to ast_safe_system().
Specifically when some parameters are filled by untrusted sources the new
function does not allow malicious input to break argument encoding.  This
may be of particular concern where CALLERID(name) or CALLERID(num) may be
used as a parameter to a script run by ast_safe_system() which could
potentially allow arbitrary command execution.

* Changed app_minivm.c:run_externnotify() to use the new ast_safe_execvp()
instead of ast_safe_system() to avoid command injection.

* Document code injection potential from untrusted data sources for other
shell commands that are under user control.

ASTERISK-27103

Change-Id: I7552472247a84cde24e1358aaf64af160107aef1
2017-08-30 18:48:22 +00:00
Joshua Colp
3ee5c6dcbe res_rtp_asterisk: Only learn a new source in learn state.
This change moves the logic which learns a new source address
for RTP so it only occurs in the learning state. The learning
state is entered on initial allocation of RTP or if we are
told that the remote address for the media has changed. While
in the learning state if we continue to receive media from
the original source we restart the learning process. It is
only once we receive a sufficient number of RTP packets from
the new source that we will switch to it. Once this is done
the closed state is entered where all packets that do not
originate from the expected source are dropped.

The learning process has also been improved to take into
account the time between received packets so a flood of them
while in the learning state does not cause media to be switched.

Finally RTCP now drops packets which are not for the learned
SSRC if strict RTP is enabled.

ASTERISK-27013

Change-Id: I56a96e993700906355e79bc880ad9d4ad3ab129c
2017-08-30 18:47:34 +00:00
George Joseph
22f1f880c4 Update for 13.17.0 2017-07-12 06:12:08 -05:00
George Joseph
0c00ee754b Update for 13.17.0-rc1 2017-07-06 06:52:04 -05:00
28 changed files with 58998 additions and 145 deletions

1
.lastclean Normal file
View File

@@ -0,0 +1 @@
40

1
.version Normal file
View File

@@ -0,0 +1 @@
13.17.2

52188
ChangeLog Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -94,6 +94,13 @@ your ITSP in a place where you didn't expect to allow it. There are a couple of
ways in which you can mitigate this impact: stricter pattern matching, or using
the FILTER() dialplan function.
The CALLERID(num) and CALLERID(name) values are other commonly used values that
are sources of data potentially supplied by outside sources. If you use these
values as parameters to the System(), MixMonitor(), or Monitor() applications
or the SHELL() dialplan function, you can allow injection of arbitrary operating
system command execution. The FILTER() dialplan function is available to remove
dangerous characters from untrusted strings to block the command injection.
Strict Pattern Matching
-----------------------

View File

@@ -1757,21 +1757,35 @@ static int play_record_review(struct ast_channel *chan, char *playfile, char *re
/*! \brief Run external notification for voicemail message */
static void run_externnotify(struct ast_channel *chan, struct minivm_account *vmu)
{
char arguments[BUFSIZ];
char fquser[AST_MAX_CONTEXT * 2];
char *argv[5] = { NULL };
struct ast_party_caller *caller;
char *cid;
int idx;
if (ast_strlen_zero(vmu->externnotify) && ast_strlen_zero(global_externnotify))
if (ast_strlen_zero(vmu->externnotify) && ast_strlen_zero(global_externnotify)) {
return;
}
snprintf(arguments, sizeof(arguments), "%s %s@%s %s %s&",
ast_strlen_zero(vmu->externnotify) ? global_externnotify : vmu->externnotify,
vmu->username, vmu->domain,
(ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str)
? ast_channel_caller(chan)->id.name.str : "",
(ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str)
? ast_channel_caller(chan)->id.number.str : "");
snprintf(fquser, sizeof(fquser), "%s@%s", vmu->username, vmu->domain);
ast_debug(1, "Executing: %s\n", arguments);
ast_safe_system(arguments);
caller = ast_channel_caller(chan);
idx = 0;
argv[idx++] = ast_strlen_zero(vmu->externnotify) ? global_externnotify : vmu->externnotify;
argv[idx++] = fquser;
cid = S_COR(caller->id.name.valid, caller->id.name.str, NULL);
if (cid) {
argv[idx++] = cid;
}
cid = S_COR(caller->id.number.valid, caller->id.number.str, NULL);
if (cid) {
argv[idx++] = cid;
}
argv[idx] = NULL;
ast_debug(1, "Executing: %s %s %s %s\n",
argv[0], argv[1], argv[2] ?: "", argv[3] ?: "");
ast_safe_execvp(1, argv[0], argv);
}
/*!\internal

View File

@@ -138,6 +138,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<para>Will be executed when the recording is over.</para>
<para>Any strings matching <literal>^{X}</literal> will be unescaped to <variable>X</variable>.</para>
<para>All variables will be evaluated at the time MixMonitor is called.</para>
<warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
or <variable>CALLERID(name)</variable> as part of the command parameters. You
risk a command injection attack executing arbitrary commands if the untrusted
strings aren't filtered to remove dangerous characters. See function
<variable>FILTER()</variable>.</para></warning>
</parameter>
</syntax>
<description>
@@ -150,6 +155,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<para>Will contain the filename used to record.</para>
</variable>
</variablelist>
<warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
or <variable>CALLERID(name)</variable> as part of ANY of the application's
parameters. You risk a command injection attack executing arbitrary commands
if the untrusted strings aren't filtered to remove dangerous characters. See
function <variable>FILTER()</variable>.</para></warning>
</description>
<see-also>
<ref type="application">Monitor</ref>
@@ -224,6 +234,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<para>Will be executed when the recording is over.
Any strings matching <literal>^{X}</literal> will be unescaped to <variable>X</variable>.
All variables will be evaluated at the time MixMonitor is called.</para>
<warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
or <variable>CALLERID(name)</variable> as part of the command parameters. You
risk a command injection attack executing arbitrary commands if the untrusted
strings aren't filtered to remove dangerous characters. See function
<variable>FILTER()</variable>.</para></warning>
</parameter>
</syntax>
<description>

View File

@@ -48,6 +48,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="command" required="true">
<para>Command to execute</para>
<warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
or <variable>CALLERID(name)</variable> as part of the command parameters. You
risk a command injection attack executing arbitrary commands if the untrusted
strings aren't filtered to remove dangerous characters. See function
<variable>FILTER()</variable>.</para></warning>
</parameter>
</syntax>
<description>
@@ -73,6 +78,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="command" required="true">
<para>Command to execute</para>
<warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
or <variable>CALLERID(name)</variable> as part of the command parameters. You
risk a command injection attack executing arbitrary commands if the untrusted
strings aren't filtered to remove dangerous characters. See function
<variable>FILTER()</variable>.</para></warning>
</parameter>
</syntax>
<description>

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><title>Release Summary - asterisk-13.17.2</title><h1 align="center"><a name="top">Release Summary</a></h1><h3 align="center">asterisk-13.17.2</h3><h3 align="center">Date: 2017-09-19</h3><h3 align="center">&lt;asteriskteam@digium.com&gt;</h3><hr><h2 align="center">Table of Contents</h2><ol>
<li><a href="#summary">Summary</a></li>
<li><a href="#contributors">Contributors</a></li>
<li><a href="#closed_issues">Closed Issues</a></li>
<li><a href="#diffstat">Diffstat</a></li>
</ol><hr><a name="summary"><h2 align="center">Summary</h2></a><center><a href="#top">[Back to Top]</a></center><p>This release has been made to address one or more security vulnerabilities that have been identified. A security advisory document has been published for each vulnerability that includes additional information. Users of versions of Asterisk that are affected are strongly encouraged to review the advisories and determine what action they should take to protect their systems from these issues.</p><p>Security Advisories:</p><ul>
<li><a href="http://downloads.asterisk.org/pub/security/AST-2017-008.html">AST-2017-008</a></li>
</ul><p>The data in this summary reflects changes that have been made since the previous release, asterisk-13.17.1.</p><hr><a name="contributors"><h2 align="center">Contributors</h2></a><center><a href="#top">[Back to Top]</a></center><p>This table lists the people who have submitted code, those that have tested patches, as well as those that reported issues on the issue tracker that were resolved in this release. For coders, the number is how many of their patches (of any size) were committed into this release. For testers, the number is the number of times their name was listed as assisting with testing a patch. Finally, for reporters, the number is the number of issues that they reported that were affected by commits that went into this release.</p><table width="100%" border="0">
<tr><th width="33%">Coders</th><th width="33%">Testers</th><th width="33%">Reporters</th></tr>
<tr valign="top"><td width="33%">1 Richard Mudgett <rmudgett@digium.com><br/></td><td width="33%"><td width="33%">1 Richard Mudgett <rmudgett@digium.com><br/></td></tr>
</table><hr><a name="closed_issues"><h2 align="center">Closed Issues</h2></a><center><a href="#top">[Back to Top]</a></center><p>This is a list of all issues from the issue tracker that were closed by changes that went into this release.</p><h3>Bug</h3><h4>Category: Resources/res_rtp_asterisk</h4><a href="https://issues.asterisk.org/jira/browse/ASTERISK-27274">ASTERISK-27274</a>: RTCP needs better packet validation to resist port scans.<br/>Reported by: Richard Mudgett<ul>
<li><a href="https://code.asterisk.org/code/changelog/asterisk?cs=01b56b7a712470036475cc06a9572bd949ba33e7">[01b56b7a71]</a> Richard Mudgett -- AST-2017-008: Improve RTP and RTCP packet processing.</li>
</ul><a href="https://issues.asterisk.org/jira/browse/ASTERISK-27252">ASTERISK-27252</a>: RTP: One way audio with direct media and strictrtp=yes.<br/>Reported by: Richard Mudgett<ul>
<li><a href="https://code.asterisk.org/code/changelog/asterisk?cs=01b56b7a712470036475cc06a9572bd949ba33e7">[01b56b7a71]</a> Richard Mudgett -- AST-2017-008: Improve RTP and RTCP packet processing.</li>
</ul><br><hr><a name="diffstat"><h2 align="center">Diffstat Results</h2></a><center><a href="#top">[Back to Top]</a></center><p>This is a summary of the changes to the source code that went into this release that was generated using the diffstat utility.</p><pre>res_rtp_asterisk.c | 472 +++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 390 insertions(+), 82 deletions(-)</pre><br></html>

View File

@@ -0,0 +1,88 @@
Release Summary
asterisk-13.17.2
Date: 2017-09-19
<asteriskteam@digium.com>
----------------------------------------------------------------------
Table of Contents
1. Summary
2. Contributors
3. Closed Issues
4. Diffstat
----------------------------------------------------------------------
Summary
[Back to Top]
This release has been made to address one or more security vulnerabilities
that have been identified. A security advisory document has been published
for each vulnerability that includes additional information. Users of
versions of Asterisk that are affected are strongly encouraged to review
the advisories and determine what action they should take to protect their
systems from these issues.
Security Advisories:
* AST-2017-008
The data in this summary reflects changes that have been made since the
previous release, asterisk-13.17.1.
----------------------------------------------------------------------
Contributors
[Back to Top]
This table lists the people who have submitted code, those that have
tested patches, as well as those that reported issues on the issue tracker
that were resolved in this release. For coders, the number is how many of
their patches (of any size) were committed into this release. For testers,
the number is the number of times their name was listed as assisting with
testing a patch. Finally, for reporters, the number is the number of
issues that they reported that were affected by commits that went into
this release.
Coders Testers Reporters
1 Richard Mudgett 1 Richard Mudgett
----------------------------------------------------------------------
Closed Issues
[Back to Top]
This is a list of all issues from the issue tracker that were closed by
changes that went into this release.
Bug
Category: Resources/res_rtp_asterisk
ASTERISK-27274: RTCP needs better packet validation to resist port scans.
Reported by: Richard Mudgett
* [01b56b7a71] Richard Mudgett -- AST-2017-008: Improve RTP and RTCP
packet processing.
ASTERISK-27252: RTP: One way audio with direct media and strictrtp=yes.
Reported by: Richard Mudgett
* [01b56b7a71] Richard Mudgett -- AST-2017-008: Improve RTP and RTCP
packet processing.
----------------------------------------------------------------------
Diffstat Results
[Back to Top]
This is a summary of the changes to the source code that went into this
release that was generated using the diffstat utility.
res_rtp_asterisk.c | 472 +++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 390 insertions(+), 82 deletions(-)

View File

@@ -51,7 +51,7 @@ silencethreshold=128
; If you need to have an external program, i.e. /usr/bin/myapp called when a
; voicemail is received by the server. The arguments are
;
; <app> <username@domain> <callerid-number> <callerid-name>
; <app> <username@domain> <callerid-name> <callerid-number>
;
;externnotify=/usr/bin/myapp
; The character set for voicemail messages can be specified here

View File

@@ -0,0 +1,44 @@
BEGIN TRANSACTION;
CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL
);
GO
-- Running upgrade -> 210693f3123d
CREATE TABLE cdr (
accountcode VARCHAR(20) NULL,
src VARCHAR(80) NULL,
dst VARCHAR(80) NULL,
dcontext VARCHAR(80) NULL,
clid VARCHAR(80) NULL,
channel VARCHAR(80) NULL,
dstchannel VARCHAR(80) NULL,
lastapp VARCHAR(80) NULL,
lastdata VARCHAR(80) NULL,
start DATETIME NULL,
answer DATETIME NULL,
[end] DATETIME NULL,
duration INTEGER NULL,
billsec INTEGER NULL,
disposition VARCHAR(45) NULL,
amaflags VARCHAR(45) NULL,
userfield VARCHAR(256) NULL,
uniqueid VARCHAR(150) NULL,
linkedid VARCHAR(150) NULL,
peeraccount VARCHAR(20) NULL,
sequence INTEGER NULL
);
GO
INSERT INTO alembic_version (version_num) VALUES ('210693f3123d');
GO
COMMIT;
GO

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
BEGIN TRANSACTION;
CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL
);
GO
-- Running upgrade -> a2e9769475e
CREATE TABLE voicemail_messages (
dir VARCHAR(255) NOT NULL,
msgnum INTEGER NOT NULL,
context VARCHAR(80) NULL,
macrocontext VARCHAR(80) NULL,
callerid VARCHAR(80) NULL,
origtime INTEGER NULL,
duration INTEGER NULL,
recording IMAGE NULL,
flag VARCHAR(30) NULL,
category VARCHAR(30) NULL,
mailboxuser VARCHAR(30) NULL,
mailboxcontext VARCHAR(30) NULL,
msg_id VARCHAR(40) NULL
);
GO
ALTER TABLE voicemail_messages ADD CONSTRAINT voicemail_messages_dir_msgnum PRIMARY KEY (dir, msgnum);
GO
CREATE INDEX voicemail_messages_dir ON voicemail_messages (dir);
GO
INSERT INTO alembic_version (version_num) VALUES ('a2e9769475e');
GO
-- Running upgrade a2e9769475e -> 39428242f7f5
ALTER TABLE voicemail_messages ALTER COLUMN recording IMAGE;
GO
UPDATE alembic_version SET version_num='39428242f7f5' WHERE alembic_version.version_num = 'a2e9769475e';
GO
COMMIT;
GO

View File

@@ -0,0 +1,32 @@
CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL
);
-- Running upgrade -> 210693f3123d
CREATE TABLE cdr (
accountcode VARCHAR(20),
src VARCHAR(80),
dst VARCHAR(80),
dcontext VARCHAR(80),
clid VARCHAR(80),
channel VARCHAR(80),
dstchannel VARCHAR(80),
lastapp VARCHAR(80),
lastdata VARCHAR(80),
start DATETIME,
answer DATETIME,
end DATETIME,
duration INTEGER,
billsec INTEGER,
disposition VARCHAR(45),
amaflags VARCHAR(45),
userfield VARCHAR(256),
uniqueid VARCHAR(150),
linkedid VARCHAR(150),
peeraccount VARCHAR(20),
sequence INTEGER
);
INSERT INTO alembic_version (version_num) VALUES ('210693f3123d');

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL
);
-- Running upgrade -> a2e9769475e
CREATE TABLE voicemail_messages (
dir VARCHAR(255) NOT NULL,
msgnum INTEGER NOT NULL,
context VARCHAR(80),
macrocontext VARCHAR(80),
callerid VARCHAR(80),
origtime INTEGER,
duration INTEGER,
recording BLOB,
flag VARCHAR(30),
category VARCHAR(30),
mailboxuser VARCHAR(30),
mailboxcontext VARCHAR(30),
msg_id VARCHAR(40)
);
ALTER TABLE voicemail_messages ADD CONSTRAINT voicemail_messages_dir_msgnum PRIMARY KEY (dir, msgnum);
CREATE INDEX voicemail_messages_dir ON voicemail_messages (dir);
INSERT INTO alembic_version (version_num) VALUES ('a2e9769475e');
-- Running upgrade a2e9769475e -> 39428242f7f5
ALTER TABLE voicemail_messages MODIFY recording BLOB(4294967295) NULL;
UPDATE alembic_version SET version_num='39428242f7f5' WHERE alembic_version.version_num = 'a2e9769475e';

View File

@@ -0,0 +1,38 @@
CREATE TABLE alembic_version (
version_num VARCHAR2(32 CHAR) NOT NULL
)
/
-- Running upgrade -> 210693f3123d
CREATE TABLE cdr (
accountcode VARCHAR2(20 CHAR),
src VARCHAR2(80 CHAR),
dst VARCHAR2(80 CHAR),
dcontext VARCHAR2(80 CHAR),
clid VARCHAR2(80 CHAR),
channel VARCHAR2(80 CHAR),
dstchannel VARCHAR2(80 CHAR),
lastapp VARCHAR2(80 CHAR),
lastdata VARCHAR2(80 CHAR),
"start" DATE,
answer DATE,
end DATE,
duration INTEGER,
billsec INTEGER,
disposition VARCHAR2(45 CHAR),
amaflags VARCHAR2(45 CHAR),
userfield VARCHAR2(256 CHAR),
uniqueid VARCHAR2(150 CHAR),
linkedid VARCHAR2(150 CHAR),
peeraccount VARCHAR2(20 CHAR),
sequence INTEGER
)
/
INSERT INTO alembic_version (version_num) VALUES ('210693f3123d')
/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
CREATE TABLE alembic_version (
version_num VARCHAR2(32 CHAR) NOT NULL
)
/
-- Running upgrade -> a2e9769475e
CREATE TABLE voicemail_messages (
dir VARCHAR2(255 CHAR) NOT NULL,
msgnum INTEGER NOT NULL,
context VARCHAR2(80 CHAR),
macrocontext VARCHAR2(80 CHAR),
callerid VARCHAR2(80 CHAR),
origtime INTEGER,
duration INTEGER,
recording BLOB,
flag VARCHAR2(30 CHAR),
category VARCHAR2(30 CHAR),
mailboxuser VARCHAR2(30 CHAR),
mailboxcontext VARCHAR2(30 CHAR),
msg_id VARCHAR2(40 CHAR)
)
/
ALTER TABLE voicemail_messages ADD CONSTRAINT voicemail_messages_dir_msgnum PRIMARY KEY (dir, msgnum)
/
CREATE INDEX voicemail_messages_dir ON voicemail_messages (dir)
/
INSERT INTO alembic_version (version_num) VALUES ('a2e9769475e')
/
-- Running upgrade a2e9769475e -> 39428242f7f5
ALTER TABLE voicemail_messages MODIFY recording BLOB
/
UPDATE alembic_version SET version_num='39428242f7f5' WHERE alembic_version.version_num = 'a2e9769475e'
/

View File

@@ -0,0 +1,36 @@
BEGIN;
CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL
);
-- Running upgrade -> 210693f3123d
CREATE TABLE cdr (
accountcode VARCHAR(20),
src VARCHAR(80),
dst VARCHAR(80),
dcontext VARCHAR(80),
clid VARCHAR(80),
channel VARCHAR(80),
dstchannel VARCHAR(80),
lastapp VARCHAR(80),
lastdata VARCHAR(80),
start TIMESTAMP WITHOUT TIME ZONE,
answer TIMESTAMP WITHOUT TIME ZONE,
"end" TIMESTAMP WITHOUT TIME ZONE,
duration INTEGER,
billsec INTEGER,
disposition VARCHAR(45),
amaflags VARCHAR(45),
userfield VARCHAR(256),
uniqueid VARCHAR(150),
linkedid VARCHAR(150),
peeraccount VARCHAR(20),
sequence INTEGER
);
INSERT INTO alembic_version (version_num) VALUES ('210693f3123d');
COMMIT;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
BEGIN;
CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL
);
-- Running upgrade -> a2e9769475e
CREATE TABLE voicemail_messages (
dir VARCHAR(255) NOT NULL,
msgnum INTEGER NOT NULL,
context VARCHAR(80),
macrocontext VARCHAR(80),
callerid VARCHAR(80),
origtime INTEGER,
duration INTEGER,
recording BYTEA,
flag VARCHAR(30),
category VARCHAR(30),
mailboxuser VARCHAR(30),
mailboxcontext VARCHAR(30),
msg_id VARCHAR(40)
);
ALTER TABLE voicemail_messages ADD CONSTRAINT voicemail_messages_dir_msgnum PRIMARY KEY (dir, msgnum);
CREATE INDEX voicemail_messages_dir ON voicemail_messages (dir);
INSERT INTO alembic_version (version_num) VALUES ('a2e9769475e');
-- Running upgrade a2e9769475e -> 39428242f7f5
ALTER TABLE voicemail_messages ALTER COLUMN recording TYPE BYTEA;
UPDATE alembic_version SET version_num='39428242f7f5' WHERE alembic_version.version_num = 'a2e9769475e';
COMMIT;

View File

@@ -84,6 +84,11 @@ static int shell_helper(struct ast_channel *chan, const char *cmd, char *data,
<syntax>
<parameter name="command" required="true">
<para>The command that the shell should execute.</para>
<warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
or <variable>CALLERID(name)</variable> as part of the command parameters. You
risk a command injection attack executing arbitrary commands if the untrusted
strings aren't filtered to remove dangerous characters. See function
<variable>FILTER()</variable>.</para></warning>
</parameter>
</syntax>
<description>

View File

@@ -871,9 +871,34 @@ int ast_vm_test_destroy_user(const char *context, const char *mailbox);
int ast_vm_test_create_user(const char *context, const char *mailbox);
#endif
/*! \brief Safely spawn an external program while closing file descriptors
\note This replaces the \b system call in all Asterisk modules
*/
/*!
* \brief Safely spawn an external program while closing file descriptors
*
* \note This replaces the \b execvp call in all Asterisk modules
*
* \param dualfork Non-zero to simulate running the program in the
* background by forking twice. The option provides similar
* functionality to the '&' in the OS shell command "cmd &". The
* option allows Asterisk to run a reaper loop to watch the first fork
* which immediately exits after spaning the second fork. The actual
* program is run in the second fork.
* \param file execvp(file, argv) file parameter
* \param argv execvp(file, argv) argv parameter
*/
int ast_safe_execvp(int dualfork, const char *file, char *const argv[]);
/*!
* \brief Safely spawn an OS shell command while closing file descriptors
*
* \note This replaces the \b system call in all Asterisk modules
*
* \param s - OS shell command string to execute.
*
* \warning Command injection can happen using this call if the passed
* in string is created using untrusted data from an external source.
* It is best not to use untrusted data. However, the caller could
* filter out dangerous characters to avoid command injection.
*/
int ast_safe_system(const char *s);
/*!

View File

@@ -1283,11 +1283,10 @@ void ast_unreplace_sigchld(void)
ast_mutex_unlock(&safe_system_lock);
}
int ast_safe_system(const char *s)
/*! \brief fork and perform other preparations for spawning applications */
static pid_t safe_exec_prep(int dualfork)
{
pid_t pid;
int res;
int status;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
ast_replace_sigchld();
@@ -1309,35 +1308,101 @@ int ast_safe_system(const char *s)
cap_free(cap);
#endif
#ifdef HAVE_WORKING_FORK
if (ast_opt_high_priority)
if (ast_opt_high_priority) {
ast_set_priority(0);
}
/* Close file descriptors and launch system command */
ast_close_fds_above_n(STDERR_FILENO);
#endif
execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
_exit(1);
} else if (pid > 0) {
if (dualfork) {
#ifdef HAVE_WORKING_FORK
pid = fork();
#else
pid = vfork();
#endif
if (pid < 0) {
/* Second fork failed. */
/* No logger available. */
_exit(1);
}
if (pid > 0) {
/* This is the first fork, exit so the reaper finishes right away. */
_exit(0);
}
/* This is the second fork. The first fork will exit immediately so
* Asterisk doesn't have to wait for completion.
* ast_safe_system("cmd &") would run in the background, but the '&'
* cannot be added with ast_safe_execvp, so we have to double fork.
*/
}
}
if (pid < 0) {
ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
}
#else
ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(ENOTSUP));
pid = -1;
#endif
return pid;
}
/*! \brief wait for spawned application to complete and unreplace sigchld */
static int safe_exec_wait(pid_t pid)
{
int res = -1;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
if (pid > 0) {
for (;;) {
int status;
res = waitpid(pid, &status, 0);
if (res > -1) {
res = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
break;
} else if (errno != EINTR)
}
if (errno != EINTR) {
break;
}
}
} else {
ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
res = -1;
}
ast_unreplace_sigchld();
#else /* !defined(HAVE_WORKING_FORK) && !defined(HAVE_WORKING_VFORK) */
res = -1;
#endif
return res;
}
int ast_safe_execvp(int dualfork, const char *file, char *const argv[])
{
pid_t pid = safe_exec_prep(dualfork);
if (pid == 0) {
execvp(file, argv);
_exit(1);
/* noreturn from _exit */
}
return safe_exec_wait(pid);
}
int ast_safe_system(const char *s)
{
pid_t pid = safe_exec_prep(0);
if (pid == 0) {
execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
_exit(1);
/* noreturn from _exit */
}
return safe_exec_wait(pid);
}
/*!
* \brief enable or disable a logging level to a specified console
*/

View File

@@ -62,17 +62,17 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="file_format" argsep=":">
<argument name="file_format" required="true">
<para>optional, if not set, defaults to <literal>wav</literal></para>
<para>Optional. If not set, defaults to <literal>wav</literal></para>
</argument>
<argument name="urlbase" />
</parameter>
<parameter name="fname_base">
<para>if set, changes the filename used to the one specified.</para>
<para>If set, changes the filename used to the one specified.</para>
</parameter>
<parameter name="options">
<optionlist>
<option name="m">
<para>when the recording ends mix the two leg files into one and
<para>When the recording ends mix the two leg files into one and
delete the two leg files. If the variable <variable>MONITOR_EXEC</variable>
is set, the application referenced in it will be executed instead of
soxmix/sox and the raw leg files will NOT be deleted automatically.
@@ -83,6 +83,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
will be passed on as additional arguments to <variable>MONITOR_EXEC</variable>.
Both <variable>MONITOR_EXEC</variable> and the Mix flag can be set from the
administrator interface.</para>
<warning><para>Do not use untrusted strings such as
<variable>CALLERID(num)</variable> or <variable>CALLERID(name)</variable>
as part of <variable>MONITOR_EXEC</variable> or
<variable>MONITOR_EXEC_ARGS</variable>. You risk a command injection
attack executing arbitrary commands if the untrusted strings aren't
filtered to remove dangerous characters. See function
<variable>FILTER()</variable>.</para></warning>
</option>
<option name="b">
<para>Don't begin recording unless a call is bridged to another channel.</para>

View File

@@ -153,7 +153,16 @@ static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp)
return 0;
}
static void sanitize_tdata(pjsip_tx_data *tdata)
#define is_sip_uri(uri) \
(PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri))
#ifdef AST_DEVMODE
#define FUNC_ATTRS __attribute__ ((noinline))
#else
#define FUNC_ATTRS
#endif
static void FUNC_ATTRS sanitize_tdata(pjsip_tx_data *tdata)
{
static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN };
pjsip_param *x_transport;
@@ -161,29 +170,50 @@ static void sanitize_tdata(pjsip_tx_data *tdata)
pjsip_fromto_hdr *fromto;
pjsip_contact_hdr *contact;
pjsip_hdr *hdr;
#ifdef AST_DEVMODE
char hdrbuf[512];
int hdrbuf_len;
#endif
if (tdata->msg->type == PJSIP_REQUEST_MSG) {
uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
x_transport = pjsip_param_find(&uri->other_param, &x_name);
if (x_transport) {
pj_list_erase(x_transport);
if (is_sip_uri(tdata->msg->line.req.uri)) {
uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
#ifdef AST_DEVMODE
hdrbuf_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, hdrbuf, 512);
ast_debug(2, "Sanitizing Request: %s\n", hdrbuf);
#endif
while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
pj_list_erase(x_transport);
}
}
}
for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
if (hdr->type == PJSIP_H_TO || hdr->type == PJSIP_H_FROM) {
fromto = (pjsip_fromto_hdr *) hdr;
uri = pjsip_uri_get_uri(fromto->uri);
x_transport = pjsip_param_find(&uri->other_param, &x_name);
if (x_transport) {
pj_list_erase(x_transport);
if (is_sip_uri(fromto->uri)) {
uri = pjsip_uri_get_uri(fromto->uri);
#ifdef AST_DEVMODE
hdrbuf_len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, uri, hdrbuf, 512);
hdrbuf[hdrbuf_len] = '\0';
ast_debug(2, "Sanitizing From/To: %s\n", hdrbuf);
#endif
while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
pj_list_erase(x_transport);
}
}
} else if (hdr->type == PJSIP_H_CONTACT) {
contact = (pjsip_contact_hdr *) hdr;
uri = pjsip_uri_get_uri(contact->uri);
x_transport = pjsip_param_find(&uri->other_param, &x_name);
if (x_transport) {
pj_list_erase(x_transport);
if (is_sip_uri(contact->uri)) {
uri = pjsip_uri_get_uri(contact->uri);
#ifdef AST_DEVMODE
hdrbuf_len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, uri, hdrbuf, 512);
hdrbuf[hdrbuf_len] = '\0';
ast_debug(2, "Sanitizing Contact: %s\n", hdrbuf);
#endif
while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
pj_list_erase(x_transport);
}
}
}
}

View File

@@ -117,7 +117,9 @@ enum strict_rtp_state {
STRICT_RTP_CLOSED, /*! Drop all RTP packets not coming from source that was learned */
};
#define DEFAULT_STRICT_RTP STRICT_RTP_CLOSED
#define STRICT_RTP_LEARN_TIMEOUT 1500 /*!< milliseconds */
#define DEFAULT_STRICT_RTP -1 /*!< Enabled */
#define DEFAULT_ICESUPPORT 1
extern struct ast_srtp_res *res_srtp;
@@ -218,6 +220,9 @@ static AST_RWLIST_HEAD_STATIC(host_candidates, ast_ice_host_candidate);
/*! \brief RTP learning mode tracking information */
struct rtp_learning_info {
struct ast_sockaddr proposed_address; /*!< Proposed remote address for strict RTP */
struct timeval start; /*!< The time learning mode was started */
struct timeval received; /*!< The time of the last received packet */
int max_seq; /*!< The highest sequence number received */
int packets; /*!< The number of remaining packets before the source is accepted */
};
@@ -248,7 +253,7 @@ struct ast_rtp {
unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
unsigned int ssrc; /*!< Synchronization source, RFC 3550, page 10. */
unsigned int themssrc; /*!< Their SSRC */
unsigned int rxssrc;
unsigned int themssrc_valid; /*!< True if their SSRC is available. */
unsigned int lastts;
unsigned int lastrxts;
unsigned int lastividtimestamp;
@@ -311,7 +316,6 @@ struct ast_rtp {
* but these are in place to keep learning mode sequence values sealed from their normal counterparts.
*/
struct rtp_learning_info rtp_source_learn; /* Learning mode track for the expected RTP source */
struct rtp_learning_info alt_source_learn; /* Learning mode tracking for a new RTP source after one has been chosen */
struct rtp_red *red;
@@ -1940,7 +1944,7 @@ static void dtls_perform_handshake(struct ast_rtp_instance *instance, struct dtl
#endif
#ifdef HAVE_PJPROJECT
static void rtp_learning_seq_init(struct rtp_learning_info *info, uint16_t seq);
static void rtp_learning_start(struct ast_rtp *rtp);
/* PJPROJECT ICE callback */
static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
@@ -1979,8 +1983,8 @@ static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
return;
}
rtp->strict_rtp_state = STRICT_RTP_LEARN;
rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno);
ast_verb(4, "%p -- Strict RTP learning after ICE completion\n", rtp);
rtp_learning_start(rtp);
ao2_unlock(instance);
}
@@ -2704,8 +2708,9 @@ static int create_new_socket(const char *type, int af)
*/
static void rtp_learning_seq_init(struct rtp_learning_info *info, uint16_t seq)
{
info->max_seq = seq - 1;
info->max_seq = seq;
info->packets = learning_min_sequential;
memset(&info->received, 0, sizeof(info->received));
}
/*!
@@ -2720,7 +2725,17 @@ static void rtp_learning_seq_init(struct rtp_learning_info *info, uint16_t seq)
*/
static int rtp_learning_rtp_seq_update(struct rtp_learning_info *info, uint16_t seq)
{
if (seq == info->max_seq + 1) {
/*
* During the learning mode the minimum amount of media we'll accept is
* 10ms so give a reasonable 5ms buffer just in case we get it sporadically.
*/
if (!ast_tvzero(info->received) && ast_tvdiff_ms(ast_tvnow(), info->received) < 5) {
/*
* Reject a flood of packets as acceptable for learning.
* Reset the needed packets.
*/
info->packets = learning_min_sequential - 1;
} else if (seq == (uint16_t) (info->max_seq + 1)) {
/* packet is in sequence */
info->packets--;
} else {
@@ -2728,8 +2743,25 @@ static int rtp_learning_rtp_seq_update(struct rtp_learning_info *info, uint16_t
info->packets = learning_min_sequential - 1;
}
info->max_seq = seq;
info->received = ast_tvnow();
return (info->packets == 0);
return info->packets;
}
/*!
* \brief Start the strictrtp learning mode.
*
* \param rtp RTP session description
*
* \return Nothing
*/
static void rtp_learning_start(struct ast_rtp *rtp)
{
rtp->strict_rtp_state = STRICT_RTP_LEARN;
memset(&rtp->rtp_source_learn.proposed_address, 0,
sizeof(rtp->rtp_source_learn.proposed_address));
rtp->rtp_source_learn.start = ast_tvnow();
rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t) rtp->lastrxseqno);
}
#ifdef HAVE_PJPROJECT
@@ -3002,11 +3034,7 @@ static int ast_rtp_new(struct ast_rtp_instance *instance,
/* Set default parameters on the newly created RTP structure */
rtp->ssrc = ast_random();
rtp->seqno = ast_random() & 0x7fff;
rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN);
if (strictrtp) {
rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno);
rtp_learning_seq_init(&rtp->alt_source_learn, (uint16_t)rtp->seqno);
}
rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_CLOSED : STRICT_RTP_OPEN);
/* Create a new socket for us to listen on and use */
if ((rtp->s =
@@ -3580,7 +3608,7 @@ static int ast_rtcp_write_report(struct ast_rtp_instance *instance, int sr)
struct ast_sockaddr remote_address = { { 0, } };
struct ast_rtp_rtcp_report_block *report_block = NULL;
RAII_VAR(struct ast_rtp_rtcp_report *, rtcp_report,
ast_rtp_rtcp_report_alloc(rtp->themssrc ? 1 : 0),
ast_rtp_rtcp_report_alloc(rtp->themssrc_valid ? 1 : 0),
ao2_cleanup);
if (!rtp || !rtp->rtcp) {
@@ -3600,7 +3628,7 @@ static int ast_rtcp_write_report(struct ast_rtp_instance *instance, int sr)
calculate_lost_packet_statistics(rtp, &lost_packets, &fraction_lost);
gettimeofday(&now, NULL);
rtcp_report->reception_report_count = rtp->themssrc ? 1 : 0;
rtcp_report->reception_report_count = rtp->themssrc_valid ? 1 : 0;
rtcp_report->ssrc = rtp->ssrc;
rtcp_report->type = sr ? RTCP_PT_SR : RTCP_PT_RR;
if (sr) {
@@ -3610,7 +3638,7 @@ static int ast_rtcp_write_report(struct ast_rtp_instance *instance, int sr)
rtcp_report->sender_information.octet_count = rtp->txoctetcount;
}
if (rtp->themssrc) {
if (rtp->themssrc_valid) {
report_block = ast_calloc(1, sizeof(*report_block));
if (!report_block) {
return 1;
@@ -3955,6 +3983,10 @@ static int ast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *fr
*/
return 0;
}
if (!rtp->themssrc_valid) {
/* We don't know their SSRC value so we don't know who to update. */
return 0;
}
/* Prepare RTCP FIR (PT=206, FMT=4) */
rtp->rtcp->firseq++;
@@ -4535,67 +4567,265 @@ static void update_lost_stats(struct ast_rtp *rtp, unsigned int lost_packets)
rtp->rtcp->reported_normdev_lost = reported_normdev_lost_current;
}
static const char *rtcp_payload_type2str(unsigned int pt)
{
const char *str;
switch (pt) {
case RTCP_PT_SR:
str = "Sender Report";
break;
case RTCP_PT_RR:
str = "Receiver Report";
break;
case RTCP_PT_FUR:
/* Full INTRA-frame Request / Fast Update Request */
str = "H.261 FUR";
break;
case RTCP_PT_PSFB:
/* Payload Specific Feed Back */
str = "PSFB";
break;
case RTCP_PT_SDES:
str = "Source Description";
break;
case RTCP_PT_BYE:
str = "BYE";
break;
default:
str = "Unknown";
break;
}
return str;
}
/*
* Unshifted RTCP header bit field masks
*/
#define RTCP_LENGTH_MASK 0xFFFF
#define RTCP_PAYLOAD_TYPE_MASK 0xFF
#define RTCP_REPORT_COUNT_MASK 0x1F
#define RTCP_PADDING_MASK 0x01
#define RTCP_VERSION_MASK 0x03
/*
* RTCP header bit field shift offsets
*/
#define RTCP_LENGTH_SHIFT 0
#define RTCP_PAYLOAD_TYPE_SHIFT 16
#define RTCP_REPORT_COUNT_SHIFT 24
#define RTCP_PADDING_SHIFT 29
#define RTCP_VERSION_SHIFT 30
#define RTCP_VERSION 2U
#define RTCP_VERSION_SHIFTED (RTCP_VERSION << RTCP_VERSION_SHIFT)
#define RTCP_VERSION_MASK_SHIFTED (RTCP_VERSION_MASK << RTCP_VERSION_SHIFT)
/*
* RTCP first packet record validity header mask and value.
*
* RFC3550 intentionally defines the encoding of RTCP_PT_SR and RTCP_PT_RR
* such that they differ in the least significant bit. Either of these two
* payload types MUST be the first RTCP packet record in a compound packet.
*
* RFC3550 checks the padding bit in the algorithm they use to check the
* RTCP packet for validity. However, we aren't masking the padding bit
* to check since we don't know if it is a compound RTCP packet or not.
*/
#define RTCP_VALID_MASK (RTCP_VERSION_MASK_SHIFTED | (((RTCP_PAYLOAD_TYPE_MASK & ~0x1)) << RTCP_PAYLOAD_TYPE_SHIFT))
#define RTCP_VALID_VALUE (RTCP_VERSION_SHIFTED | (RTCP_PT_SR << RTCP_PAYLOAD_TYPE_SHIFT))
#define RTCP_SR_BLOCK_WORD_LENGTH 5
#define RTCP_RR_BLOCK_WORD_LENGTH 6
#define RTCP_HEADER_SSRC_LENGTH 2
static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, const unsigned char *rtcpdata, size_t size, struct ast_sockaddr *addr)
{
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
unsigned int *rtcpheader = (unsigned int *)(rtcpdata);
int packetwords, position = 0;
unsigned int packetwords;
unsigned int position;
unsigned int first_word;
/*! True if we have seen an acceptable SSRC to learn the remote RTCP address */
unsigned int ssrc_seen;
int report_counter = 0;
struct ast_rtp_rtcp_report_block *report_block;
struct ast_frame *f = &ast_null_frame;
packetwords = size / 4;
if (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
/* Send to whoever sent to us */
if (ast_sockaddr_cmp(&rtp->rtcp->them, addr)) {
ast_sockaddr_copy(&rtp->rtcp->them, addr);
if (rtpdebug) {
ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
ast_sockaddr_stringify(&rtp->rtcp->them));
}
ast_debug(1, "Got RTCP report of %zu bytes from %s\n",
size, ast_sockaddr_stringify(addr));
/*
* Validate the RTCP packet according to an adapted and slightly
* modified RFC3550 validation algorithm.
*/
if (packetwords < RTCP_HEADER_SSRC_LENGTH) {
ast_debug(1, "%p -- RTCP from %s: Frame size (%u words) is too short\n",
rtp, ast_sockaddr_stringify(addr), packetwords);
return &ast_null_frame;
}
position = 0;
first_word = ntohl(rtcpheader[position]);
if ((first_word & RTCP_VALID_MASK) != RTCP_VALID_VALUE) {
ast_debug(1, "%p -- RTCP from %s: Failed first packet validity check\n",
rtp, ast_sockaddr_stringify(addr));
return &ast_null_frame;
}
do {
position += ((first_word >> RTCP_LENGTH_SHIFT) & RTCP_LENGTH_MASK) + 1;
if (packetwords <= position) {
break;
}
first_word = ntohl(rtcpheader[position]);
} while ((first_word & RTCP_VERSION_MASK_SHIFTED) == RTCP_VERSION_SHIFTED);
if (position != packetwords) {
ast_debug(1, "%p -- RTCP from %s: Failed packet version or length check\n",
rtp, ast_sockaddr_stringify(addr));
return &ast_null_frame;
}
ast_debug(1, "Got RTCP report of %zu bytes\n", size);
/*
* Note: RFC3605 points out that true NAT (vs NAPT) can cause RTCP
* to have a different IP address and port than RTP. Otherwise, when
* strictrtp is enabled we could reject RTCP packets not coming from
* the learned RTP IP address if it is available.
*/
/*
* strictrtp safety needs SSRC to match before we use the
* sender's address for symmetrical RTP to send our RTCP
* reports.
*
* If strictrtp is not enabled then claim to have already seen
* a matching SSRC so we'll accept this packet's address for
* symmetrical RTP.
*/
ssrc_seen = rtp->strict_rtp_state == STRICT_RTP_OPEN;
position = 0;
while (position < packetwords) {
int i, pt, rc;
unsigned int i;
unsigned int pt;
unsigned int rc;
unsigned int ssrc;
/*! True if the ssrc value we have is valid and not garbage because it doesn't exist. */
unsigned int ssrc_valid;
unsigned int length;
unsigned int min_length;
struct ast_json *message_blob;
RAII_VAR(struct ast_rtp_rtcp_report *, rtcp_report, NULL, ao2_cleanup);
i = position;
length = ntohl(rtcpheader[i]);
pt = (length & 0xff0000) >> 16;
rc = (length & 0x1f000000) >> 24;
length &= 0xffff;
first_word = ntohl(rtcpheader[i]);
pt = (first_word >> RTCP_PAYLOAD_TYPE_SHIFT) & RTCP_PAYLOAD_TYPE_MASK;
rc = (first_word >> RTCP_REPORT_COUNT_SHIFT) & RTCP_REPORT_COUNT_MASK;
/* RFC3550 says 'length' is the number of words in the packet - 1 */
length = ((first_word >> RTCP_LENGTH_SHIFT) & RTCP_LENGTH_MASK) + 1;
rtcp_report = ast_rtp_rtcp_report_alloc(rc);
if (!rtcp_report) {
/* Check expected RTCP packet record length */
min_length = RTCP_HEADER_SSRC_LENGTH;
switch (pt) {
case RTCP_PT_SR:
min_length += RTCP_SR_BLOCK_WORD_LENGTH;
/* fall through */
case RTCP_PT_RR:
min_length += (rc * RTCP_RR_BLOCK_WORD_LENGTH);
break;
case RTCP_PT_FUR:
case RTCP_PT_PSFB:
break;
case RTCP_PT_SDES:
case RTCP_PT_BYE:
/*
* There may not be a SSRC/CSRC present. The packet is
* useless but still valid if it isn't present.
*
* We don't know what min_length should be so disable the check
*/
min_length = length;
break;
default:
ast_debug(1, "%p -- RTCP from %s: %u(%s) skipping record\n",
rtp, ast_sockaddr_stringify(addr), pt, rtcp_payload_type2str(pt));
if (rtcp_debug_test_addr(addr)) {
ast_verbose("\n");
ast_verbose("RTCP from %s: %u(%s) skipping record\n",
ast_sockaddr_stringify(addr), pt, rtcp_payload_type2str(pt));
}
position += length;
continue;
}
if (length < min_length) {
ast_debug(1, "%p -- RTCP from %s: %u(%s) length field less than expected minimum. Min:%u Got:%u\n",
rtp, ast_sockaddr_stringify(addr), pt, rtcp_payload_type2str(pt),
min_length - 1, length - 1);
return &ast_null_frame;
}
rtcp_report->reception_report_count = rc;
rtcp_report->ssrc = ntohl(rtcpheader[i + 1]);
if ((i + length) > packetwords) {
if (rtpdebug) {
ast_debug(1, "RTCP Read too short\n");
/* Get the RTCP record SSRC if defined for the record */
ssrc_valid = 1;
switch (pt) {
case RTCP_PT_SR:
case RTCP_PT_RR:
rtcp_report = ast_rtp_rtcp_report_alloc(rc);
if (!rtcp_report) {
return &ast_null_frame;
}
return &ast_null_frame;
rtcp_report->reception_report_count = rc;
ssrc = ntohl(rtcpheader[i + 1]);
rtcp_report->ssrc = ssrc;
break;
case RTCP_PT_FUR:
case RTCP_PT_PSFB:
ssrc = ntohl(rtcpheader[i + 1]);
break;
case RTCP_PT_SDES:
case RTCP_PT_BYE:
default:
ssrc = 0;
ssrc_valid = 0;
break;
}
if (rtcp_debug_test_addr(addr)) {
ast_verbose("\n\nGot RTCP from %s\n",
ast_sockaddr_stringify(addr));
ast_verbose("PT: %d(%s)\n", pt, (pt == RTCP_PT_SR) ? "Sender Report" :
(pt == RTCP_PT_RR) ? "Receiver Report" :
(pt == RTCP_PT_FUR) ? "H.261 FUR" : "Unknown");
ast_verbose("Reception reports: %d\n", rc);
ast_verbose("SSRC of sender: %u\n", rtcp_report->ssrc);
ast_verbose("\n");
ast_verbose("RTCP from %s\n", ast_sockaddr_stringify(addr));
ast_verbose("PT: %u(%s)\n", pt, rtcp_payload_type2str(pt));
ast_verbose("Reception reports: %u\n", rc);
ast_verbose("SSRC of sender: %u\n", ssrc);
}
i += 2; /* Advance past header and ssrc */
if (ssrc_valid && rtp->themssrc_valid) {
if (ssrc != rtp->themssrc) {
/*
* Skip over this RTCP record as it does not contain the
* correct SSRC. We should not act upon RTCP records
* for a different stream.
*/
position += length;
ast_debug(1, "%p -- RTCP from %s: Skipping record, received SSRC '%u' != expected '%u'\n",
rtp, ast_sockaddr_stringify(addr), ssrc, rtp->themssrc);
continue;
}
ssrc_seen = 1;
}
if (ssrc_seen && ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
/* Send to whoever sent to us */
if (ast_sockaddr_cmp(&rtp->rtcp->them, addr)) {
ast_sockaddr_copy(&rtp->rtcp->them, addr);
if (rtpdebug) {
ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
ast_sockaddr_stringify(addr));
}
}
}
i += RTCP_HEADER_SSRC_LENGTH; /* Advance past header and ssrc */
switch (pt) {
case RTCP_PT_SR:
gettimeofday(&rtp->rtcp->rxlsr, NULL);
@@ -4619,7 +4849,7 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
rtcp_report->sender_information.packet_count,
rtcp_report->sender_information.octet_count);
}
i += 5;
i += RTCP_SR_BLOCK_WORD_LENGTH;
/* Intentional fall through */
case RTCP_PT_RR:
if (rtcp_report->type != RTCP_PT_SR) {
@@ -4676,9 +4906,9 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
*/
message_blob = ast_json_pack("{s: s, s: s, s: f}",
"from", ast_sockaddr_stringify(&rtp->rtcp->them),
"to", rtp->rtcp->local_addr_str,
"rtt", rtp->rtcp->rtt);
"from", ast_sockaddr_stringify(addr),
"to", rtp->rtcp->local_addr_str,
"rtt", rtp->rtcp->rtt);
ast_rtp_publish_rtcp_message(instance, ast_rtp_rtcp_received_type(),
rtcp_report,
message_blob);
@@ -4701,26 +4931,23 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
case RTCP_PT_SDES:
if (rtcp_debug_test_addr(addr)) {
ast_verbose("Received an SDES from %s\n",
ast_sockaddr_stringify(&rtp->rtcp->them));
ast_sockaddr_stringify(addr));
}
break;
case RTCP_PT_BYE:
if (rtcp_debug_test_addr(addr)) {
ast_verbose("Received a BYE from %s\n",
ast_sockaddr_stringify(&rtp->rtcp->them));
ast_sockaddr_stringify(addr));
}
break;
default:
ast_debug(1, "Unknown RTCP packet (pt=%d) received from %s\n",
pt, ast_sockaddr_stringify(&rtp->rtcp->them));
break;
}
position += (length + 1);
position += length;
}
rtp->rtcp->rtcp_info = 1;
return f;
}
/*! \pre instance is locked */
@@ -4991,39 +5218,139 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
return &ast_null_frame;
}
/* If strict RTP protection is enabled see if we need to learn the remote address or if we need to drop the packet */
if (rtp->strict_rtp_state == STRICT_RTP_LEARN) {
ast_debug(1, "%p -- Probation learning mode pass with source address %s\n", rtp, ast_sockaddr_stringify(&addr));
/* For now, we always copy the address. */
ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
/* If the version is not what we expected by this point then just drop the packet */
if (version != 2) {
return &ast_null_frame;
}
/* Send the rtp and the seqno from header to rtp_learning_rtp_seq_update to see whether we can exit or not*/
if (rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
ast_debug(1, "%p -- Probation at seq %d with %d to go; discarding frame\n",
rtp, rtp->rtp_source_learn.max_seq, rtp->rtp_source_learn.packets);
/* If strict RTP protection is enabled see if we need to learn the remote address or if we need to drop the packet */
switch (rtp->strict_rtp_state) {
case STRICT_RTP_LEARN:
/*
* Scenario setup:
* PartyA -- Ast1 -- Ast2 -- PartyB
*
* The learning timeout is necessary for Ast1 to handle the above
* setup where PartyA calls PartyB and Ast2 initiates direct media
* between Ast1 and PartyB. Ast1 may lock onto the Ast2 stream and
* never learn the PartyB stream when it starts. The timeout makes
* Ast1 stay in the learning state long enough to see and learn the
* RTP stream from PartyB.
*
* To mitigate against attack, the learning state cannot switch
* streams while there are competing streams. The competing streams
* interfere with each other's qualification. Once we accept a
* stream and reach the timeout, an attacker cannot interfere
* anymore.
*
* Here are a few scenarios and each one assumes that the streams
* are continuous:
*
* 1) We already have a known stream source address and the known
* stream wants to change to a new source address. An attacking
* stream will block learning the new stream source. After the
* timeout we re-lock onto the original stream source address which
* likely went away. The result is one way audio.
*
* 2) We already have a known stream source address and the known
* stream doesn't want to change source addresses. An attacking
* stream will not be able to replace the known stream. After the
* timeout we re-lock onto the known stream. The call is not
* affected.
*
* 3) We don't have a known stream source address. This presumably
* is the start of a call. Competing streams will result in staying
* in learning mode until a stream becomes the victor and we reach
* the timeout. We cannot exit learning if we have no known stream
* to lock onto. The result is one way audio until there is a victor.
*
* If we learn a stream source address before the timeout we will be
* in scenario 1) or 2) when a competing stream starts.
*/
if (!ast_sockaddr_isnull(&rtp->strict_rtp_address)
&& STRICT_RTP_LEARN_TIMEOUT < ast_tvdiff_ms(ast_tvnow(), rtp->rtp_source_learn.start)) {
ast_verb(4, "%p -- Strict RTP learning complete - Locking on source address %s\n",
rtp, ast_sockaddr_stringify(&rtp->strict_rtp_address));
rtp->strict_rtp_state = STRICT_RTP_CLOSED;
} else {
struct ast_sockaddr target_address;
if (!ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
/*
* We are open to learning a new address but have received
* traffic from the current address, accept it and reset
* the learning counts for a new source. When no more
* current source packets arrive a new source can take over
* once sufficient traffic is received.
*/
rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
break;
}
/*
* We give preferential treatment to the requested target address
* (negotiated SDP address) where we are to send our RTP. However,
* the other end has no obligation to send from that address even
* though it is practically a requirement when NAT is involved.
*/
ast_rtp_instance_get_requested_target_address(instance, &target_address);
if (!ast_sockaddr_cmp(&target_address, &addr)) {
/* Accept the negotiated target RTP stream as the source */
ast_verb(4, "%p -- Strict RTP switching to RTP target address %s as source\n",
rtp, ast_sockaddr_stringify(&addr));
ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
break;
}
/*
* Trying to learn a new address. If we pass a probationary period
* with it, that means we've stopped getting RTP from the original
* source and we should switch to it.
*/
if (!ast_sockaddr_cmp(&rtp->rtp_source_learn.proposed_address, &addr)) {
if (!rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
/* Accept the new RTP stream */
ast_verb(4, "%p -- Strict RTP switching source address to %s\n",
rtp, ast_sockaddr_stringify(&addr));
ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
break;
}
/* Not ready to accept the RTP stream candidate */
ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Will switch to it in %d packets.\n",
rtp, ast_sockaddr_stringify(&addr), rtp->rtp_source_learn.packets);
} else {
/*
* This is either an attacking stream or
* the start of the expected new stream.
*/
ast_sockaddr_copy(&rtp->rtp_source_learn.proposed_address, &addr);
rtp_learning_seq_init(&rtp->rtp_source_learn, seqno);
ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Qualifying new stream.\n",
rtp, ast_sockaddr_stringify(&addr));
}
return &ast_null_frame;
}
ast_verb(4, "%p -- Probation passed - setting RTP source address to %s\n", rtp, ast_sockaddr_stringify(&addr));
rtp->strict_rtp_state = STRICT_RTP_CLOSED;
}
if (rtp->strict_rtp_state == STRICT_RTP_CLOSED) {
/* Fall through */
case STRICT_RTP_CLOSED:
/*
* We should not allow a stream address change if the SSRC matches
* once strictrtp learning is closed. Any kind of address change
* like this should have happened while we were in the learning
* state. We do not want to allow the possibility of an attacker
* interfering with the RTP stream after the learning period.
* An attacker could manage to get an RTCP packet redirected to
* them which can contain the SSRC value.
*/
if (!ast_sockaddr_cmp(&rtp->strict_rtp_address, &addr)) {
/* Always reset the alternate learning source */
rtp_learning_seq_init(&rtp->alt_source_learn, seqno);
} else {
/* Start trying to learn from the new address. If we pass a probationary period with
* it, that means we've stopped getting RTP from the original source and we should
* switch to it.
*/
if (rtp_learning_rtp_seq_update(&rtp->alt_source_learn, seqno)) {
ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection. Will switch to it in %d packets\n",
rtp, ast_sockaddr_stringify(&addr), rtp->alt_source_learn.packets);
return &ast_null_frame;
}
ast_verb(4, "%p -- Switching RTP source address to %s\n", rtp, ast_sockaddr_stringify(&addr));
ast_sockaddr_copy(&rtp->strict_rtp_address, &addr);
break;
}
ast_debug(1, "%p -- Received RTP packet from %s, dropping due to strict RTP protection.\n",
rtp, ast_sockaddr_stringify(&addr));
return &ast_null_frame;
case STRICT_RTP_OPEN:
break;
}
/* If symmetric RTP is enabled see if the remote side is not what we expected and change where we are sending audio */
@@ -5051,11 +5378,6 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
return &ast_null_frame;
}
/* If the version is not what we expected by this point then just drop the packet */
if (version != 2) {
return &ast_null_frame;
}
/* Pull out the various other fields we will need */
payloadtype = (seqno & 0x7f0000) >> 16;
padding = seqno & (1 << 29);
@@ -5068,7 +5390,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
AST_LIST_HEAD_INIT_NOLOCK(&frames);
/* Force a marker bit and change SSRC if the SSRC changes */
if (rtp->rxssrc && rtp->rxssrc != ssrc) {
if (rtp->themssrc_valid && rtp->themssrc != ssrc) {
struct ast_frame *f, srcupdate = {
AST_FRAME_CONTROL,
.subclass.integer = AST_CONTROL_SRCCHANGE,
@@ -5096,8 +5418,8 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
rtp->rtcp->received_prior = 0;
}
}
rtp->rxssrc = ssrc;
rtp->themssrc = ssrc; /* Record their SSRC to put in future RR */
rtp->themssrc_valid = 1;
/* Remove any padding bytes that may be present */
if (padding) {
@@ -5151,10 +5473,6 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
prev_seqno = rtp->lastrxseqno;
rtp->lastrxseqno = seqno;
if (!rtp->themssrc) {
rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */
}
if (rtp_debug_test_addr(&addr)) {
ast_verbose("Got RTP packet from %s (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6d)\n",
ast_sockaddr_stringify(&addr),
@@ -5529,9 +5847,14 @@ static void ast_rtp_remote_address_set(struct ast_rtp_instance *instance, struct
rtp->rxseqno = 0;
if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN) {
rtp->strict_rtp_state = STRICT_RTP_LEARN;
rtp_learning_seq_init(&rtp->rtp_source_learn, rtp->seqno);
if (strictrtp && rtp->strict_rtp_state != STRICT_RTP_OPEN
&& !ast_sockaddr_isnull(addr) && ast_sockaddr_cmp(addr, &rtp->strict_rtp_address)) {
/* We only need to learn a new strict source address if we've been told the source is
* changing to something different.
*/
ast_verb(4, "%p -- Strict RTP learning after remote address set to: %s\n",
rtp, ast_sockaddr_stringify(addr));
rtp_learning_start(rtp);
}
}