Skip to content

Commit

Permalink
stir_shaken: Add the e164_max_length parameter (interop fix)
Browse files Browse the repository at this point in the history
This parameter allows the 15-digit number length restriction of the E.164
format to be bypassed.  Especially useful in scenarios where various
telephony number prefixes are in use, causing some numbers to exceed
the standard maximum length.

Credits to @Integration-IT for watching over the core issue and helping
work towards the current solution!

Fixes #3202
Fixes #3182
Fixes #3181

(cherry picked from commit 2e66235)
  • Loading branch information
liviuchircu committed Sep 27, 2023
1 parent 24d8179 commit b37734b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
26 changes: 23 additions & 3 deletions modules/stir_shaken/doc/stir_shaken_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ modparam("stir_shaken", "crl_dir", "/stir_certs/crls")
<section id="param_e164_strict_mode" xreflabel="e164_strict_mode">
<title><varname>e164_strict_mode</varname> (integer)</title>
<para>
Strictly check if the originating/destination identity derived from the
SIP message is an E.164 telephone number. Also require the URI to either
be a <emphasis>tel</emphasis> URI or a <emphasis>sip</emphasis> /
Require a leading <emphasis>"+"</emphasis> to be present in
the originating/destination SHAKEN identity, on top of mandating an E.164
telephone number by default. Additionally, require the URI to be either
a <emphasis>tel</emphasis> URI or a <emphasis>sip</emphasis> /
<emphasis>sips</emphasis> URI with the <emphasis>user=phone</emphasis>
parameter.
</para>
Expand All @@ -181,6 +182,25 @@ modparam("stir_shaken", "e164_strict_mode", 1)
</example>
</section>

<section id="param_e164_max_length" xreflabel="e164_max_length">
<title><varname>e164_max_length</varname> (integer)</title>
<para>
This parameter allows the 15-digit number length restriction of the E.164
format to be bypassed. Especially useful in scenarios where various
telephony number prefixes are in use, causing some numbers to exceed
the standard maximum length.
</para>
<para>The default value is <emphasis>15</emphasis>.</para>
<example>
<title>Set <varname>e164_max_length</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("stir_shaken", "e164_max_length", 16)
...
</programlisting>
</example>
</section>

<section id="param_require_date_hdr" xreflabel="require_date_hdr">
<title><varname>require_date_hdr</varname> (integer)</title>
<para>
Expand Down
4 changes: 3 additions & 1 deletion modules/stir_shaken/stir_shaken.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static char *crl_list;
static char *crl_dir;

static int e164_strict_mode;
static int e164_max_length = 15;

static int require_date_hdr = 1;

Expand All @@ -121,6 +122,7 @@ static param_export_t params[] = {
{"crl_list", STR_PARAM, &crl_list},
{"crl_dir", STR_PARAM, &crl_dir},
{"e164_strict_mode", INT_PARAM, &e164_strict_mode},
{"e164_max_length", INT_PARAM, &e164_max_length},
{"require_date_hdr", INT_PARAM, &require_date_hdr},
{0, 0, 0}
};
Expand Down Expand Up @@ -940,7 +942,7 @@ static int check_passport_phonenum(str *num, int log_lev)
num->len--;
}

if (_is_e164(num, e164_strict_mode) == -1) {
if (_is_e164(num, e164_strict_mode, e164_max_length) == -1) {
LM_GEN(log_lev, "number is not in E.164 format: %.*s\n", num->len, num->s);
return -1;
}
Expand Down
22 changes: 11 additions & 11 deletions test/test_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ void test_ut(void)
ok(is_e164(_str("+1234567890123456")) == -1, "test-e164-7");
ok(is_e164(_str("+123456789x12345")) == -1, "test-e164-8");

ok(_is_e164(_str(""), 0) == -1, "test-e164-9");
ok(_is_e164(_str("+"), 0) == -1, "test-e164-10");
ok(_is_e164(_str("+1"), 0) == -1, "test-e164-11");
ok(_is_e164(_str("12"), 0) == 1, "test-e164-12");
ok(_is_e164(_str("+12"), 0) == 1, "test-e164-13");
ok(_is_e164(_str("123"), 0) == 1, "test-e164-14");
ok(_is_e164(_str("123456789012345"), 0) == 1, "test-e164-15");
ok(_is_e164(_str("1234567890123456"), 0) == -1, "test-e164-16");
ok(_is_e164(_str("+123456789012345"), 0) == 1, "test-e164-17");
ok(_is_e164(_str("+1234567890123456"), 0) == -1, "test-e164-18");
ok(_is_e164(_str("123456789x12345"), 0) == -1, "test-e164-19");
ok(_is_e164(_str(""), 0, 15) == -1, "test-e164-9");
ok(_is_e164(_str("+"), 0, 15) == -1, "test-e164-10");
ok(_is_e164(_str("+1"), 0, 15) == -1, "test-e164-11");
ok(_is_e164(_str("12"), 0, 15) == 1, "test-e164-12");
ok(_is_e164(_str("+12"), 0, 15) == 1, "test-e164-13");
ok(_is_e164(_str("123"), 0, 15) == 1, "test-e164-14");
ok(_is_e164(_str("123456789012345"), 0, 15) == 1, "test-e164-15");
ok(_is_e164(_str("1234567890123456"), 0, 15) == -1, "test-e164-16");
ok(_is_e164(_str("+123456789012345"), 0, 15) == 1, "test-e164-17");
ok(_is_e164(_str("+1234567890123456"), 0, 15) == -1, "test-e164-18");
ok(_is_e164(_str("123456789x12345"), 0, 15) == -1, "test-e164-19");
}
7 changes: 4 additions & 3 deletions ut.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ static inline void unescape_crlf(str *in_out)
}
}

static inline int _is_e164(const str* _user, int require_plus)
/* @max_digits should be just 15, but there are exceptions to this rule! */
static inline int _is_e164(const str* _user, int require_plus, int max_digits)
{
char *d, *start, *end;

Expand All @@ -614,7 +615,7 @@ static inline int _is_e164(const str* _user, int require_plus)
}

end = _user->s + _user->len;
if (end - start < 2 || end - start > 15)
if (end - start < 2 || end - start > max_digits)
return -1;

for (d = start; d < end; d++)
Expand All @@ -623,7 +624,7 @@ static inline int _is_e164(const str* _user, int require_plus)

return 1;
}
#define is_e164(_user) _is_e164(_user, 1)
#define is_e164(_user) _is_e164(_user, 1, 15)

/*
* Convert a string to lower case
Expand Down

0 comments on commit b37734b

Please sign in to comment.