<p>Benjamin Keith Ford has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14574">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_stir_shaken: Improve dialplan function and add test conditions.<br><br>Previously the dialplan function was not trimming the whitespace from<br>the parameters it recieved. Now it does.<br><br>Also added a conditional that, when TEST_FRAMEWORK is enabled, the<br>timestamp in the identity header will be overlooked. This is just for<br>testing, since the testsuite will rely on a SIPp scenario with a preset<br>identity header to trigger the MISMATCH result.<br><br>Change-Id: I43d67f1489b8c1c5729ed3ca8d71e35ddf438df1<br>---<br>M res/res_pjsip_stir_shaken.c<br>M res/res_stir_shaken.c<br>2 files changed, 31 insertions(+), 12 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/14574/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_stir_shaken.c b/res/res_pjsip_stir_shaken.c</span><br><span>index 3620579..e40f3d1 100644</span><br><span>--- a/res/res_pjsip_stir_shaken.c</span><br><span>+++ b/res/res_pjsip_stir_shaken.c</span><br><span>@@ -95,6 +95,11 @@</span><br><span>        long int timestamp;</span><br><span>  struct timeval now = ast_tvnow();</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef TEST_FRAMEWORK</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_debug(3, "Ignoring STIR/SHAKEN timestamp\n");</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  json = ast_json_load_string(json_str, NULL);</span><br><span>         timestamp = ast_json_integer_get(ast_json_object_get(json, "iat"));</span><br><span> </span><br><span>diff --git a/res/res_stir_shaken.c b/res/res_stir_shaken.c</span><br><span>index 632fd1b..2ad082b 100644</span><br><span>--- a/res/res_stir_shaken.c</span><br><span>+++ b/res/res_stir_shaken.c</span><br><span>@@ -153,6 +153,11 @@</span><br><span> /* The maximum length for path storage */</span><br><span> #define MAX_PATH_LEN 256</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* The amount of time (in seconds) to add if no cache data is found for</span><br><span style="color: hsl(120, 100%, 40%);">+ * certificate expiration</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define EXPIRATION_BUFFER 15</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_stir_shaken_payload {</span><br><span>  /*! The JWT header */</span><br><span>        struct ast_json *header;</span><br><span>@@ -381,6 +386,10 @@</span><br><span>              }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(value)) {</span><br><span style="color: hsl(120, 100%, 40%);">+         actual_expires.tv_sec += EXPIRATION_BUFFER;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  snprintf(time_buf, sizeof(time_buf), "%30lu", actual_expires.tv_sec);</span><br><span> </span><br><span>  ast_db_put(hash, "expiration", time_buf);</span><br><span>@@ -1133,6 +1142,8 @@</span><br><span>  struct stir_shaken_datastore *ss_datastore;</span><br><span>  struct ast_datastore *datastore;</span><br><span>     char *parse;</span><br><span style="color: hsl(120, 100%, 40%);">+  char *first;</span><br><span style="color: hsl(120, 100%, 40%);">+  char *second;</span><br><span>        unsigned int target_index, current_index = 0;</span><br><span>        AST_DECLARE_APP_ARGS(args,</span><br><span>           AST_APP_ARG(first_param);</span><br><span>@@ -1153,17 +1164,20 @@</span><br><span> </span><br><span>      AST_STANDARD_APP_ARGS(args, parse);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_strlen_zero(args.first_param)) {</span><br><span style="color: hsl(120, 100%, 40%);">+      first = ast_strip(args.first_param);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (ast_strlen_zero(first)) {</span><br><span>                ast_log(LOG_ERROR, "An argument must be passed to %s\n", function);</span><br><span>                return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ second = ast_strip(args.second_param);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     /* Check if we are only looking for the number of STIR/SHAKEN verification results */</span><br><span style="color: hsl(0, 100%, 40%);">-   if (!strcasecmp(args.first_param, "count")) {</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!strcasecmp(first, "count")) {</span><br><span> </span><br><span>             size_t count = 0;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           if (!ast_strlen_zero(args.second_param)) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (!ast_strlen_zero(second)) {</span><br><span>                      ast_log(LOG_ERROR, "%s only takes 1 paramater for 'count'\n", function);</span><br><span>                   return -1;</span><br><span>           }</span><br><span>@@ -1184,15 +1198,15 @@</span><br><span>  /* If we aren't doing a count, then there should be two parameters. The field</span><br><span>     * we are searching for will be the second parameter. The index is the first.</span><br><span>         */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (ast_strlen_zero(args.second_param)) {</span><br><span style="color: hsl(120, 100%, 40%);">+     if (ast_strlen_zero(second)) {</span><br><span>               ast_log(LOG_ERROR, "Retrieving a value using %s requires two paramaters (index, value) "</span><br><span style="color: hsl(0, 100%, 40%);">-                      "- only index was given (%s)\n", function, args.second_param);</span><br><span style="color: hsl(120, 100%, 40%);">+                      "- only index was given (%s)\n", function, second);</span><br><span>                return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ast_str_to_uint(args.first_param, &target_index)) {</span><br><span style="color: hsl(120, 100%, 40%);">+   if (ast_str_to_uint(first, &target_index)) {</span><br><span>             ast_log(LOG_ERROR, "Failed to convert index %s to integer for function %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                 args.first_param, function);</span><br><span style="color: hsl(120, 100%, 40%);">+                  first, function);</span><br><span>            return -1;</span><br><span>   }</span><br><span> </span><br><span>@@ -1211,19 +1225,19 @@</span><br><span>      }</span><br><span>    ast_channel_unlock(chan);</span><br><span>    if (current_index != target_index || !datastore) {</span><br><span style="color: hsl(0, 100%, 40%);">-              ast_log(LOG_WARNING, "No STIR/SHAKEN results for index '%s'\n", args.first_param);</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_log(LOG_WARNING, "No STIR/SHAKEN results for index '%s'\n", first);</span><br><span>            return -1;</span><br><span>   }</span><br><span>    ss_datastore = datastore->data;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  if (!strcasecmp(args.second_param, "identity")) {</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!strcasecmp(second, "identity")) {</span><br><span>             ast_copy_string(buf, ss_datastore->identity, len);</span><br><span style="color: hsl(0, 100%, 40%);">-   } else if (!strcasecmp(args.second_param, "attestation")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcasecmp(second, "attestation")) {</span><br><span>           ast_copy_string(buf, ss_datastore->attestation, len);</span><br><span style="color: hsl(0, 100%, 40%);">-        } else if (!strcasecmp(args.second_param, "verify_result")) {</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (!strcasecmp(second, "verify_result")) {</span><br><span>                 ast_copy_string(buf, stir_shaken_verification_result_to_string(ss_datastore->verify_result), len);</span><br><span>        } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                ast_log(LOG_ERROR, "No such value '%s' for %s\n", args.second_param, function);</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_log(LOG_ERROR, "No such value '%s' for %s\n", second, function);</span><br><span>               return -1;</span><br><span>   }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14574">change 14574</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14574"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I43d67f1489b8c1c5729ed3ca8d71e35ddf438df1 </div>
<div style="display:none"> Gerrit-Change-Number: 14574 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>