Commit Graph

6824 Commits

Author SHA1 Message Date
George Joseph 628f8d7a43 Stir/Shaken Refactor
Why do we need a refactor?

The original stir/shaken implementation was started over 3 years ago
when little was understood about practical implementation.  The
result was an implementation that wouldn't actually interoperate
with any other stir-shaken implementations.

There were also a number of stir-shaken features and RFC
requirements that were never implemented such as TNAuthList
certificate validation, sending Reason headers in SIP responses
when verification failed but we wished to continue the call, and
the ability to send Media Key(mky) grants in the Identity header
when the call involved DTLS.

Finally, there were some performance concerns around outgoing
calls and selection of the correct certificate and private key.
The configuration was keyed by an arbitrary name which meant that
for every outgoing call, we had to scan the entire list of
configured TNs to find the correct cert to use.  With only a few
TNs configured, this wasn't an issue but if you have a thousand,
it could be.

What's changed?

* Configuration objects have been refactored to be clearer about
  their uses and to fix issues.
    * The "general" object was renamed to "verification" since it
      contains parameters specific to the incoming verification
      process.  It also never handled ca_path and crl_path
      correctly.
    * A new "attestation" object was added that controls the
      outgoing attestation process.  It sets default certificates,
      keys, etc.
    * The "certificate" object was renamed to "tn" and had it's key
      change to telephone number since outgoing call attestation
      needs to look up certificates by telephone number.
    * The "profile" object had more parameters added to it that can
      override default parameters specified in the "attestation"
      and "verification" objects.
    * The "store" object was removed altogther as it was never
      implemented.

* We now use libjwt to create outgoing Identity headers and to
  parse and validate signatures on incoming Identiy headers.  Our
  previous custom implementation was much of the source of the
  interoperability issues.

* General code cleanup and refactor.
    * Moved things to better places.
    * Separated some of the complex functions to smaller ones.
    * Using context objects rather than passing tons of parameters
      in function calls.
    * Removed some complexity and unneeded encapsuation from the
      config objects.

Resolves: #351
Resolves: #46

UserNote: Asterisk's stir-shaken feature has been refactored to
correct interoperability, RFC compliance, and performance issues.
See https://docs.asterisk.org/Deployment/STIR-SHAKEN for more
information.

UpgradeNote: The stir-shaken refactor is a breaking change but since
it's not working now we don't think it matters. The
stir_shaken.conf file has changed significantly which means that
existing ones WILL need to be changed.  The stir_shaken.conf.sample
file in configs/samples/ has quite a bit more information.  This is
also an ABI breaking change since some of the existing objects
needed to be changed or removed, and new ones added.  Additionally,
if res_stir_shaken is enabled in menuselect, you'll need to either
have the development package for libjwt v1.15.3 installed or use
the --with-libjwt-bundled option with ./configure.
2024-02-28 18:39:03 +00:00
Sebastian Jennen ea8ead4e13 translate.c: implement new direct comp table mode
The new mode lists for each codec translation the actual real cost in cpu microseconds per second translated audio.
This allows to compare the real cpu usage of translations and helps in evaluation of codec implementation changes regarding performance (regression testing).

- add new table mode
- hide the 999999 comp values, as these only indicate an issue with transcoding
- hide the 0 values, as these also do not contain any information (only indicate a multistep transcoding)

Resolves: #601
2024-02-28 13:03:26 +00:00
Naveen Albert 526a6e0ce4 dsp.c: Fix and improve potentially inaccurate log message.
If ast_dsp_process is called with a codec besides slin, ulaw,
or alaw, a warning is logged that in-band DTMF is not supported,
but this message is not always appropriate or correct, because
ast_dsp_process is much more generic than just DTMF detection.

This logs a more generic message in those cases, and also improves
codec-mismatch logging throughout dsp.c by ensuring incompatible
codecs are printed out.

Resolves: #595
2024-02-14 13:19:13 +00:00
George Joseph 29a273618d pjsip show channelstats: Prevent possible segfault when faxing
Under rare circumstances, it's possible for the original audio
session in the active_media_state default_session to be corrupted
instead of removed when switching to the t38/image media session
during fax negotiation.  This can cause a segfault when a "pjsip
show channelstats" attempts to print that audio media session's
rtp statistics.  In these cases, the active_media_state
topology is correctly showing only a single t38/image stream
so we now check that there's an audio stream in the topology
before attempting to use the audio media session to get the rtp
statistics.

Resolves: #592
2024-02-14 13:17:40 +00:00
George Joseph 6871d1cdfc Reduce startup/shutdown verbose logging
When started with a verbose level of 3, asterisk can emit over 1500
verbose message that serve no real purpose other than to fill up
logs. When asterisk shuts down, it emits another 1100 that are of
even less use. Since the testsuite runs asterisk with a verbose
level of 3, and asterisk starts and stops for every one of the 700+
tests, the number of log messages is staggering.  Besides taking up
resources, it also makes it hard to debug failing tests.

This commit changes the log level for those verbose messages to 5
instead of 3 which reduces the number of log messages to only a
handful. Of course, NOTICE, WARNING and ERROR message are
unaffected.

There's also one other minor change...
ast_context_remove_extension_callerid2() logs a DEBUG message
instead of an ERROR if the extension you're deleting doesn't exist.
The pjsip_config_wizard calls that function to clean up the config
and has been triggering that annoying error message for years.

Resolves: #582
2024-02-12 18:46:32 +00:00
Joshua C. Colp edf54951be utils: Make behavior of ast_strsep* match strsep.
Given the scenario of passing an empty string to the
ast_strsep functions the functions would return NULL
instead of an empty string. This is counter to how
strsep itself works.

This change alters the behavior of the functions to
match that of strsep.

Fixes: #565
2024-02-06 18:55:52 +00:00
Brad Smith b0992fb771 main/utils: Simplify the FreeBSD ast_get_tid() handling
FreeBSD has had kernel threads for 20+ years.
2024-01-30 19:00:10 +00:00
Sean Bright f2ac526172 rtp_engine.c: Correct sample rate typo for L16/44100.
Fixes #555
2024-01-30 18:58:08 +00:00
Naveen Albert f1a9ec4703 manager.c: Fix erroneous reloads in UpdateConfig.
Currently, a reload will always occur if the
Reload header is provided for the UpdateConfig
action. However, we should not be doing a reload
if the header value has a falsy value, per the
documentation, so this makes the reload behavior
consistent with the existing documentation.

Resolves: #551
2024-01-30 18:57:21 +00:00
Naveen Albert ac71e40042 logger: Fix linking regression.
Commit 008731b0a4
caused a regression by resulting in logger.xml
being compiled and linked into the asterisk
binary in lieu of logger.c on certain platforms
if Asterisk was compiled in dev mode.

To fix this, we ensure the file has a unique
name without the extension. Most existing .xml
files have been named differently from any
.c files in the same directory or did not
pose this issue.

channels/pjsip/dialplan_functions.xml does not
pose this issue but is also being renamed
to adhere to this policy.

Resolves: #539
2024-01-17 15:01:07 +00:00
Naveen Albert 5cf75f9b2c func_frame_trace: Add CLI command to dump frame queue.
This adds a simple CLI command that can be used for
analyzing all frames currently queued to a channel.

A couple log messages are also adjusted to be more
useful in tracing bridging problems.

Resolves: #533
2024-01-17 14:11:30 +00:00
George Joseph 09052bfa51 Revert "core & res_pjsip: Improve topology change handling."
This reverts commit 315eb551db.

Over the past year, we've had several reports of "topology storms"
occurring where 2 external facing channels connected by one or more
local channels and bridges will get themselves in a state where
they continually send each other topology change requests.  This
usually manifests itself in no-audio calls and a flood of
"Exceptionally long queue length" messages.  It appears that this
commit is the cause so we're reverting it for now until we can
determine a more appropriate solution.

Resolves: #530
2024-01-12 15:42:53 +00:00
Naveen Albert fa3922a4d2 manager.c: Fix regression due to using wrong free function.
Commit 424be34563 introduced
a regression by calling ast_free on memory allocated by
realpath. This causes Asterisk to abort when executing this
function. Since the memory is allocated by glibc, it should
be freed using ast_std_free.

Resolves: #513
2024-01-02 12:07:05 +00:00
Ben Ford 424be34563 manager.c: Prevent path traversal with GetConfig.
When using AMI GetConfig, it was possible to access files outside of the
Asterisk configuration directory by using filenames with ".." and "./"
even while live_dangerously was not enabled. This change resolves the
full path and ensures we are still in the configuration directory before
attempting to access the file.
2023-12-14 18:47:36 +00:00
Naveen Albert 183954bed3 config_options.c: Fix truncation of option descriptions.
This increases the format width of option descriptions
to avoid needless truncation for longer descriptions.

Resolves: #428
2023-12-12 14:40:22 +00:00
Naveen Albert ce1f4b3018 manager.c: Improve clarity of "manager show connected".
Improve the "manager show connected" CLI command
to clarify that the last two columns are permissions
related, not counts, and use sufficient widths
to consistently display these values.

ASTERISK-30143 #close
Resolves: #482
2023-12-11 17:34:28 +00:00
Naveen Albert d1fb397cfc general: Fix broken links.
This fixes a number of broken links throughout the
tree, mostly caused by wiki.asterisk.org being replaced
with docs.asterisk.org, which should eliminate the
need for sporadic fixes as in f28047db36.

Resolves: #430
2023-12-08 13:11:54 +00:00
Sean Bright 008731b0a4 logger.c: Move LOG_GROUP documentation to dedicated XML file.
The `get_documentation` awk script will only extract the first
DOCUMENTATION block that it finds in a given file. This is by design
(9bc2127) to prevent AMI event documentation from being pulled in to
the core.xml documentation file.

Because of this, the `LOG_GROUP` documentation added in 89709e2 was
not being properly extracted and was missing fom the resulting XML
documentation file. This commit moves the `LOG_GROUP` documentation to
a separate `logger.xml` file.
2023-12-06 21:23:54 +00:00
Sean Bright 8c3ebf9747 config.c: Log #exec include failures.
If the script referenced by `#exec` does not exist, writes anything to
stderr, or exits abnormally or with a non-zero exit status, we log
that to Asterisk's error logging channel.

Additionally, write out a warning if the script produces no output.

Fixes #259
2023-12-06 14:48:24 +00:00
Sean Bright ca931c9436 app.c: Allow ampersands in playback lists to be escaped.
Any function or application that accepts a `&`-separated list of
filenames can now include a literal `&` in a filename by wrapping the
entire filename in single quotes, e.g.:

```
exten = _X.,n,Playback('https://example.com/sound.cgi?a=b&c=d'&hello-world)
```

Fixes #172

UpgradeNote: Ampersands in URLs passed to the `Playback()`,
`Background()`, `SpeechBackground()`, `Read()`, `Authenticate()`, or
`Queue()` applications as filename arguments can now be escaped by
single quoting the filename. Additionally, this is also possible when
using the `CONFBRIDGE` dialplan function, or configuring various
features in `confbridge.conf` and `queues.conf`.
2023-11-28 19:52:03 +00:00
Sean Bright 31c44d0634 uri.c: Simplify ast_uri_make_host_with_port() 2023-11-14 20:51:40 +00:00
Sean Bright 611010d67d res_http_websocket.c: Set hostname on client for certificate validation.
Additionally add a `assert()` to in the TLS client setup code to
ensure that hostname is set when it is supposed to be.

Fixes #433
2023-11-14 17:56:24 +00:00
Matthew Fredrickson 21412fddcb app_followme.c: Grab reference on nativeformats before using it
Fixes a crash due to a lack of proper reference on the nativeformats
object before passing it into ast_request().  Also found potentially
similar use case bugs in app_chanisavail.c, bridge.c, and bridge_basic.c

Fixes: #388
2023-11-09 18:24:36 +00:00
Naveen Albert 89709e2583 logger: Add channel-based filtering.
This adds the ability to filter console
logging by channel or groups of channels.
This can be useful on busy systems where
an administrator would like to analyze certain
calls in detail. A dialplan function is also
included for the purpose of assigning a channel
to a group (e.g. by tenant, or some other metric).

ASTERISK-30483 #close

Resolves: #242

UserNote: The console log can now be filtered by
channels or groups of channels, using the
logger filter CLI commands.
2023-11-09 12:35:25 +00:00
George Joseph f309ffad3d chan_pjsip: Add PJSIPHangup dialplan app and manager action
See UserNote below.

Exposed the existing Hangup AMI action in manager.c so we can use
all of it's channel search and AMI protocol handling without
duplicating that code in dialplan_functions.c.

Added a lookup function to res_pjsip.c that takes in the
string represenation of the pjsip_status_code enum and returns
the actual status code.  I.E.  ast_sip_str2rc("DECLINE") returns
603.  This allows the caller to specify PJSIPHangup(decline) in
the dialplan, just like Hangup(call_rejected).

Also extracted the XML documentation to its own file since it was
almost as large as the code itself.

UserNote: A new dialplan app PJSIPHangup and AMI action allows you
to hang up an unanswered incoming PJSIP call with a specific SIP
response code in the 400 -> 699 range.
2023-11-07 16:32:22 +00:00
Holger Hans Peter Freyther 69cf329681 stasis: Update the snapshot after setting the redirect
The previous commit added the caller_rdnis attribute. Make it
avialble during a possible ChanngelHangupRequest.
2023-11-07 14:27:15 +00:00
Holger Hans Peter Freyther 69590ba33e ari: Provide the caller ID RDNIS for the channels
Provide the caller ID RDNIS when available. This will allow an
application to follow the redirect.
2023-11-07 14:27:15 +00:00
Brad Smith 5c22cfccd9 main/utils: Implement ast_get_tid() for OpenBSD
Implement the ast_get_tid() function for OpenBSD. OpenBSD supports
getting the TID via getthrid().
2023-11-07 12:56:26 +00:00
Naveen Albert 82086545cc core_local: Fix local channel parsing with slashes.
Currently, trying to call a Local channel with a slash
in the extension will fail due to the parsing of characters
after such a slash as being dial modifiers. Additionally,
core_local is inconsistent and incomplete with
its parsing of Local dial strings in that sometimes it
uses the first slash and at other times it uses the last.

For instance, something like DAHDI/5 or PJSIP/device
is a perfectly usable extension in the dialplan, but Local
channels in particular prevent these from being called.

This creates inconsistent behavior for users, since using
a slash in an extension is perfectly acceptable, and using
a Goto to accomplish this works fine, but if specified
through a Local channel, the parsing prevents this.

This fixes this by explicitly parsing options from the
last slash in the extension, rather than the first one,
which doesn't cause an issue for extensions with slashes.

ASTERISK-30013 #close

Resolves: #248
2023-11-02 21:38:13 +00:00
Bastian Triller 8536ce8c38 func_json: Fix crashes for some types
This commit fixes crashes in JSON_DECODE() for types null, true, false
and real numbers.

In addition it ensures that a path is not deeper than 32 levels.

Also allow root object to be an array.

Add unit tests for above cases.
2023-10-05 14:38:05 +00:00
Eduardo 91e368c485 codec_builtin: Use multiples of 20 for maximum_ms
Some providers require a multiple of 20 for the maxptime or fail to complete calls,
e.g. Vivo in Brazil. To increase compatibility, only multiples of 20 are now used.

Resolves: #260
2023-09-22 16:10:11 +00:00
George Joseph 13ccbc1d08 lock.c: Separate DETECT_DEADLOCKS from DEBUG_THREADS
Previously, DETECT_DEADLOCKS depended on DEBUG_THREADS.
Unfortunately, DEBUG_THREADS adds a lot of lock tracking overhead
to all of the lock lifecycle calls whereas DETECT_DEADLOCKS just
causes the lock calls to loop over trylock in 200us intervals until
the lock is obtained and spits out log messages if it takes more
than 5 seconds.  From a code perspective, the only reason they were
tied together was for logging.  So... The ifdefs in lock.c were
refactored to allow DETECT_DEADLOCKS to be enabled without
also enabling DEBUG_THREADS.

Resolves: #321

UserNote: You no longer need to select DEBUG_THREADS to use
DETECT_DEADLOCKS.  This removes a significant amount of overhead
if you just want to detect possible deadlocks vs needing full
lock tracing.
2023-09-22 14:34:46 +00:00
George Joseph 95313d4727 asterisk.c: Use the euid's home directory to read/write cli history
The CLI .asterisk_history file is read from/written to the directory
specified by the HOME environment variable. If the root user starts
asterisk with the -U/-G options, or with runuser/rungroup set in
asterisk.conf, the asterisk process is started as root but then it
calls setuid/setgid to set the new user/group. This does NOT reset
the HOME environment variable to the new user's home directory
though so it's still left as "/root". In this case, the new user
will almost certainly NOT have access to read from or write to the
history file.

* Added function process_histfile() which calls
  getpwuid(geteuid()) and uses pw->dir as the home directory
  instead of the HOME environment variable.
* ast_el_read_default_histfile() and ast_el_write_default_histfile()
  have been modified to use the new process_histfile()
  function.

Resolves: #337
2023-09-22 13:34:21 +00:00
Mike Bradeen e06448353d cel: add publish user event helper
Add a wrapper function around ast_cel_publish_event that
packs event and extras into a blob before publishing

Resolves:#330
2023-09-21 14:47:21 +00:00
George Joseph 67fd66e2fe file.c: Add ability to search custom dir for sounds
To better co-exist with sounds files that may be managed by
packages, custom sound files may now be placed in
AST_DATA_DIR/sounds/custom instead of the standard
AST_DATA_DIR/sounds/<lang> directory.  If the new
"sounds_search_custom_dir" option in asterisk.conf is set
to "true", asterisk will search the custom directory for sounds
files before searching the standard directory.  For performance
reasons, the "sounds_search_custom_dir" defaults to "false".

Resolves: #315

UserNote: A new option "sounds_search_custom_dir" has been added to
asterisk.conf that allows asterisk to search
AST_DATA_DIR/sounds/custom for sounds files before searching the
standard AST_DATA_DIR/sounds/<lang> directory.
2023-09-20 19:15:07 +00:00
George Joseph fde0e19658 make_buildopts_h, et. al. Allow adding all cflags to buildopts.h
The previous behavior of make_buildopts_h was to not add the
non-ABI-breaking MENUSELECT_CFLAGS like DETECT_DEADLOCKS,
REF_DEBUG, etc. to the buildopts.h file because "it caused
ccache to invalidate files and extended compile times". They're
only defined by passing them on the gcc command line with '-D'
options.   In practice, including them in the include file rarely
causes any impact because the only time ccache cares is if you
actually change an option so the hit occurrs only once after
you change it.

OK so why would we want to include them?  Many IDEs follow the
include files to resolve defines and if the options aren't in an
include file, it can cause the IDE to mark blocks of "ifdeffed"
code as unused when they're really not.

So...

* Added a new menuselect compile option ADD_CFLAGS_TO_BUILDOPTS_H
  which tells make_buildopts_h to include the non-ABI-breaking
  flags in buildopts.h as well as the ABI-breaking ones. The default
  is disabled to preserve current behavior.  As before though,
  only the ABI-breaking flags appear in AST_BUILDOPTS and only
  those are used to calculate AST_BUILDOPT_SUM.
  A new AST_BUILDOPT_ALL define was created to capture all of the
  flags.

* make_version_c was streamlined to use buildopts.h and also to
  create asterisk_build_opts_all[] and ast_get_build_opts_all(void)

* "core show settings" now shows both AST_BUILDOPTS and
  AST_BUILDOPTS_ALL.

UserNote: The "Build Options" entry in the "core show settings"
CLI command has been renamed to "ABI related Build Options" and
a new entry named "All Build Options" has been added that shows
both breaking and non-breaking options.
2023-09-14 17:58:24 +00:00
Naveen Albert e899a02465 pbx.c: Fix gcc 12 compiler warning.
Resolves: #277
2023-08-28 13:38:07 +00:00
Maximilian Fridrich fb234abd84 main/refer.c: Fix double free in refer_data_destructor + potential leak
Resolves: #267
2023-08-22 13:31:01 +00:00
Joshua C. Colp be3d8266da manager: Tolerate stasis messages with no channel snapshot.
In some cases I have yet to determine some stasis messages may
be created without a channel snapshot. This change adds some
tolerance to this scenario, preventing a crash from occurring.
2023-08-11 13:29:06 +00:00
Maximilian Fridrich 51a7b18038 core/ari/pjsip: Add refer mechanism
This change adds support for refers that are not session based. It
includes a refer implementation for the PJSIP technology which results
in out-of-dialog REFERs being sent to a PJSIP endpoint. These can be
triggered using the new ARI endpoint `/endpoints/refer`.

Resolves: #71

UserNote: There is a new ARI endpoint `/endpoints/refer` for referring
an endpoint to some URI or endpoint.
2023-08-09 15:10:46 +00:00
Joshua C. Colp 806515597e audiohook: Unlock channel in mute if no audiohooks present.
In the case where mute was called on a channel that had no
audiohooks the code was not unlocking the channel, resulting
in a deadlock.

Resolves: #233
2023-08-09 14:50:07 +00:00
Mike Bradeen a55fd5e471 utils: add lock timestamps for DEBUG_THREADS
Adds last locked and unlocked timestamps as well as a
counter for the number of times the lock has been
attempted (vs locked/unlocked) to debug output printed
using the DEBUG_THREADS option.

Resolves: #110
2023-06-29 15:13:55 +00:00
Jaco Kroon 73326fb4e0 tcptls: when disabling a server port, we should set the accept_fd to -1.
If we don't set this to -1 if the structure can be potentially re-used
later then it's possible that we'll issue a close() on an unrelated file
descriptor, breaking asterisk in other interesting ways.

I believe this to be an unlikely scenario, but it costs nothing to be
safe.

Signed-off-by: Jaco Kroon <jaco@uls.co.za>
2023-06-12 14:07:32 +00:00
George Joseph 6b4f49c0df build: Fix a few gcc 13 issues
* gcc 13 is now catching when a function is declared as returning
  an enum but defined as returning an int or vice versa.  Fixed
  a few in app.h, loader.c, stasis_message.c.

* gcc 13 is also now (incorrectly) complaining of dangling pointers
  when assigning a pointer to a local char array to a char *. Had
  to change that to an ast_alloca.

Resolves: #155
2023-06-09 18:19:53 +00:00
Ben Ford cfde21c0c7 AMI: Add CoreShowChannelMap action.
Adds a new AMI action (CoreShowChannelMap) that takes in a channel name
and provides a list of all channels that are connected to that channel,
following local channel connections as well.

Resolves: #104

UserNote: New AMI action CoreShowChannelMap has been added.
2023-06-05 12:29:35 -06:00
Mike Bradeen 1f337f6034 indications: logging changes
Increase verbosity to indicate failure due to missing country
and to specify default on CLI dump

Resolves: #89
2023-06-05 07:30:51 -06:00
Naveen Albert 8b864b12cf callerid: Allow specifying timezone for date/time.
The Caller ID generation routine currently is hardcoded
to always use the system time zone. This makes it possible
to optionally specify any TZ-format time zone.

Resolves: #98
ASTERISK-30330
2023-05-25 10:46:40 -06:00
InterLinked1 ad6ff4cbf2
asterisk.c: Fix option warning for remote console. (#103)
Commit 09e989f972
categorized the T option as not being compatible
with remote consoles, but they do affect verbose
messages with remote console. This fixes this.

Resolves: #102
2023-05-22 12:59:56 -06:00
Sean Bright d59a8ef59e
xml.c: Process XML Inclusions recursively. (#69)
If processing an XInclude results in new <xi:include> elements, we
need to run XInclude processing again. This continues until no
replacement occurs or an error is encountered.

There is a separate issue with dynamic strings (ast_str) that will be
addressed separately.

Resolves: #65
2023-05-11 13:03:33 -06:00
Mike Bradeen cd48733353
cel: add local optimization begin event (#54)
The current AST_CEL_LOCAL_OPTIMIZE event is and has been
triggered on a local optimization end to serve as a flag
indicating the event occurred.  This change adds a second
AST_CEL_LOCAL_OPTIMIZE_BEGIN event for further detail.

Resolves: #52

UpgradeNote: The existing AST_CEL_LOCAL_OPTIMIZE can continue
to be used as-is and the AST_CEL_LOCAL_OPTIMIZE_BEGIN event
can be ignored if desired.

UserNote: The new AST_CEL_LOCAL_OPTIMIZE_BEGIN can be used
by itself or in conert with the existing
AST_CEL_LOCAL_OPTIMIZE to book-end local channel optimizaion.
2023-05-04 08:51:55 -06:00