<p></p>
<p dir="auto">In my use case I use HS256 so its a shared secret normally using a string with environment variable or something, not a key file. The jwt mod expects a file to load up the secret/key. So I just create a file with the secret inside the file, but I keep getting.</p>
<pre class="notranslate"><code class="notranslate">failed to decode jwt value
</code></pre>
<p dir="auto">After digging into the source and trying to debug. It looks like when it's handing secret in a file the kdata.len is off by one.</p>
<p dir="auto">This is the dirty fix for me.</p>
<pre class="notranslate"><code class="notranslate">diff --git a/src/modules/jwt/jwt_mod.c b/src/modules/jwt/jwt_mod.c
index 233a0709..a67d0b89 100644
--- a/src/modules/jwt/jwt_mod.c
+++ b/src/modules/jwt/jwt_mod.c
@@ -509,7 +509,7 @@ static int ki_jwt_verify(sip_msg_t* msg, str *key, str *alg, str *claims,
}
}
- ret = jwt_decode(&jwt, jwtval->s, (unsigned char*)kdata.s, (size_t)kdata.len);
+ ret = jwt_decode(&jwt, jwtval->s, (unsigned char*)kdata.s, (size_t)kdata.len-1);
if (ret!=0 || jwt==NULL) {
LM_ERR("failed to decode jwt value\n");
goto error;
</code></pre>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/3282">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZKHJFOHONKRKHG7KLDWI3ZOVANCNFSM6AAAAAASEBO2VU">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/ABO7UZPYYETM5PVBVIZFTBTWI3ZOVA5CNFSM6AAAAAASEBO2VWWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFNL74GY.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><kamailio/kamailio/issues/3282</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/3282",
"url": "https://github.com/kamailio/kamailio/issues/3282",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>