]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_stir_shaken: Check for disabled before param validation
authorGeorge Joseph <gjoseph@sangoma.com>
Wed, 11 Sep 2024 16:19:23 +0000 (10:19 -0600)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 12 Sep 2024 18:46:27 +0000 (18:46 +0000)
For both attestation and verification, we now check whether they've
been disabled either globally or by the profile before validating
things like callerid, orig_tn, dest_tn, etc.  This prevents useless
error messages.

Resolves: #879
(cherry picked from commit 77733275462b4a878ddbc25a4b1b43a8037cd457)

res/res_stir_shaken/attestation.c
res/res_stir_shaken/verification.c

index 91e688d16d293daa64bacd7062388a96952ac642..8d4d75650d9dc7bf40b40ea426b09adda83d77eb 100644 (file)
@@ -75,37 +75,18 @@ enum ast_stir_shaken_as_response_code
        RAII_VAR(char *, canon_dest_tn , canonicalize_tn_alloc(dest_tn), ast_free);
        RAII_VAR(char *, canon_orig_tn , canonicalize_tn_alloc(orig_tn), ast_free);
 
-       SCOPE_ENTER(3, "%s: Enter\n", tag);
+       const char *t = S_OR(tag, S_COR(chan, ast_channel_name(chan), ""));
+       SCOPE_ENTER(3, "%s: Enter\n", t);
 
-       if (!canon_orig_tn) {
-               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
-                       LOG_ERROR, "%s: Must provide caller_id/orig_tn\n", tag);
-       }
-
-       if (!canon_dest_tn) {
-               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
-                       LOG_ERROR, "%s: Must provide dest_tn\n", tag);
-       }
-
-       if (ast_strlen_zero(tag)) {
-               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
-                       LOG_ERROR, "%s: Must provide tag\n", tag);
-       }
-
-       if (!ctxout) {
-               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
-                       LOG_ERROR, "%s: Must provide ctxout\n", tag);
-       }
-
-       if (ast_strlen_zero(profile_name)) {
+       as_cfg = as_get_cfg();
+       if (as_cfg->global_disable) {
                SCOPE_EXIT_RTN_VALUE(AST_STIR_SHAKEN_AS_DISABLED,
-                       "%s: Disabled due to missing profile name\n", tag);
+                       "%s: Globally disabled\n", t);
        }
 
-       as_cfg = as_get_cfg();
-       if (as_cfg->global_disable) {
+       if (ast_strlen_zero(profile_name)) {
                SCOPE_EXIT_RTN_VALUE(AST_STIR_SHAKEN_AS_DISABLED,
-                       "%s: Globally disabled\n", tag);
+                       "%s: Disabled due to missing profile name\n", t);
        }
 
        eprofile = eprofile_get_cfg(profile_name);
@@ -117,7 +98,27 @@ enum ast_stir_shaken_as_response_code
 
        if (!PROFILE_ALLOW_ATTEST(eprofile)) {
                SCOPE_EXIT_RTN_VALUE(AST_STIR_SHAKEN_AS_DISABLED,
-                       "%s: Disabled by profile\n", tag);
+                       "%s: Disabled by profile '%s'\n", t, profile_name);
+       }
+
+       if (ast_strlen_zero(tag)) {
+               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
+                       LOG_ERROR, "%s: Must provide tag\n", t);
+       }
+
+       if (!canon_orig_tn) {
+               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
+                       LOG_ERROR, "%s: Must provide caller_id/orig_tn\n", tag);
+       }
+
+       if (!canon_dest_tn) {
+               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
+                       LOG_ERROR, "%s: Must provide dest_tn\n", tag);
+       }
+
+       if (!ctxout) {
+               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS,
+                       LOG_ERROR, "%s: Must provide ctxout\n", tag);
        }
 
        etn = tn_get_etn(canon_orig_tn, eprofile);
index 4be93a097556995f730ea1d70848de85a5dc5a2f..566815660aa16bcdd83a7f88cdabaf980fe40ec8 100644 (file)
@@ -660,14 +660,10 @@ enum ast_stir_shaken_vs_response_code
        const char *t = S_OR(tag, S_COR(chan, ast_channel_name(chan), ""));
        SCOPE_ENTER(3, "%s: Enter\n", t);
 
-       if (ast_strlen_zero(tag)) {
-               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_VS_INVALID_ARGUMENTS,
-                       LOG_ERROR, "%s: Must provide tag\n", t);
-       }
-
-       if (ast_strlen_zero(canon_caller_id)) {
-               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_VS_INVALID_ARGUMENTS,
-               LOG_ERROR, "%s: Must provide caller_id\n", t);
+       vs = vs_get_cfg();
+       if (vs->global_disable) {
+               SCOPE_EXIT_RTN_VALUE(AST_STIR_SHAKEN_VS_DISABLED,
+                       "%s: Globally disabled\n", t);
        }
 
        if (ast_strlen_zero(profile_name)) {
@@ -675,12 +671,6 @@ enum ast_stir_shaken_vs_response_code
                        "%s: Disabled due to missing profile name\n", t);
        }
 
-       vs = vs_get_cfg();
-       if (vs->global_disable) {
-               SCOPE_EXIT_RTN_VALUE(AST_STIR_SHAKEN_VS_DISABLED,
-                       "%s: Globally disabled\n", t);
-       }
-
        profile = eprofile_get_cfg(profile_name);
        if (!profile) {
                SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_VS_DISABLED,
@@ -690,7 +680,17 @@ enum ast_stir_shaken_vs_response_code
 
        if (!PROFILE_ALLOW_VERIFY(profile)) {
                SCOPE_EXIT_RTN_VALUE(AST_STIR_SHAKEN_VS_DISABLED,
-                       "%s: Disabled by profile\n", t);
+                       "%s: Disabled by profile '%s'\n", t, profile_name);
+       }
+
+       if (ast_strlen_zero(tag)) {
+               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_VS_INVALID_ARGUMENTS,
+                       LOG_ERROR, "%s: Must provide tag\n", t);
+       }
+
+       if (ast_strlen_zero(canon_caller_id)) {
+               SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_VS_INVALID_ARGUMENTS,
+               LOG_ERROR, "%s: Must provide caller_id\n", t);
        }
 
        ctx = ao2_alloc_options(sizeof(*ctx), ctx_destructor,