res_pjsip_stir_shaken: Fix JSON field ordering and disallowed TN characters.

The current STIR/SHAKEN signing process is inconsistent with the
RFCs in a couple ways that can cause interoperability issues.

RFC8225 specifies that the keys must be ordered lexicographically, but
currently the fields are simply ordered according to the order
in which they were added to the JSON object, which is not
compliant with the RFC and can cause issues with some carriers.

To fix this, we now leverage libjansson's ability to dump a JSON
object sorted by key value, yielding the correct field ordering.

Additionally, telephone numbers must have any leading + prefix removed
and must not contain characters outside of 0-9, *, and # in order
to comply with the RFCs. Numbers are now properly formatted as such.

ASTERISK-30407 #close

Change-Id: Iab76d39447c4b8cf133de85657dba02fda07f9a2
This commit is contained in:
Naveen Albert
2023-02-17 13:45:16 +00:00
committed by Friendly Automation
parent e234531f5a
commit 1bbcb98558
5 changed files with 51 additions and 12 deletions

View File

@@ -777,6 +777,8 @@ enum ast_json_encoding_format
AST_JSON_COMPACT,
/*! Formatted for human readability */
AST_JSON_PRETTY,
/*! Keys sorted alphabetically */
AST_JSON_SORTED,
};
/*!
@@ -804,6 +806,17 @@ enum ast_json_encoding_format
*/
char *ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format);
/*!
* \brief Encode a JSON value to a string, with its keys sorted.
*
* Returned string must be freed by calling ast_json_free().
*
* \param root JSON value.
* \return String encoding of \a root.
* \retval NULL on error.
*/
#define ast_json_dump_string_sorted(root) ast_json_dump_string_format(root, AST_JSON_SORTED)
#define ast_json_dump_str(root, dst) ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)
/*!