From sergio.charrua@voip.pt Fri May 10 09:25:10 2024 From: Sergio Charrua To: sr-users@lists.kamailio.org Subject: [SR-Users] Re: base64 decoding issue Date: Fri, 10 May 2024 11:24:27 +0200 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1661236756==" --===============1661236756== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi all! Solved the issue by using s.decode.base64t instead of s.decode.base64 ... Thanks anyway! *S=C3=A9rgio Charrua* On Fri, May 10, 2024 at 9:40=E2=80=AFAM Sergio Charrua wrote: > Hi all! > > I have been dealing with STIR/SHAKEN for a few weeks now, and while doing > some tests I have found an issue which I can't find the reason for. > > The script has the following route logic: > > route[HANDLE_STIRSHAKEN] > { > > xlog("L_INFO", "HANDLE_STIRSHAKEN - STIR/SHAKEN Logic"); > > if ($hdrc(Identity) =3D=3D 0 ){ > xlog("L_INFO", "HANDLE_STIRSHAKEN - No Identity Header -> Skipping > this logic"); > return; > } > > #Verify Call Identity > xlog("L_INFO", "HANDLE_STIRSHAKEN - Identity Header: $hdr(Identity)"); > $var(header_1)=3D $(hdr(Identity){s.select,0,.}); > $var(header_2)=3D $(hdr(Identity){s.select,1,.}); > xlog("L_INFO", "HANDLE_STIRSHAKEN - Encoded Header 1: $var(header_1)"); > xlog("L_INFO", "HANDLE_STIRSHAKEN - Encoded Header 2: $var(header_2)"); > xlog("L_INFO", "HANDLE_STIRSHAKEN - Decoded Header 1: > $(var(header_1){s.decode.base64})"); > xlog("L_INFO", "HANDLE_STIRSHAKEN - Decoded Header 2: > $(var(header_2){s.decode.base64})"); > > xlog("L_INFO", "HANDLE_STIRSHAKEN - Parsing!"); > $var(hdr_1_json_payload) =3D $(var(header_1){s.decode.base64}); # Header > 1 > xlog("L_INFO", "HANDLE_STIRSHAKEN - Parsed!"); > > xlog("L_INFO", "HANDLE_STIRSHAKEN - Header 1 payload =3D > $var(hdr_1_json_payload) "); > > $var(hdr_2_json_payload) =3D $(var(header_2){s.decode.base64}); # Header > 2 > jansson_get_field($var(hdr_2_json_payload), "attest", > "$var(attest_value)"); > jansson_get_field($var(hdr_2_json_payload), "ppt", "$var(ppt_value)"); > jansson_get_field($var(hdr_2_json_payload), "typ", "$var(typ_value)"); > jansson_get_field($var(hdr_2_json_payload), "x5u", "$var(x5u_value)"); > > xlog("L_INFO", "HANDLE_STIRSHAKEN - $var(attest_value) $var(ppt_value) > $var(typ_value) $var(x5u_value) "); > > } > > > All it does is parse the Identity header received on the initial INVITE, > decodes it (it is encoded in base64) and writes some JSON values on log. > Nothing serious.... > > As the Identity header is divided into multiple parts, separated by a ".", > I get the first 2 parts in 2 private variables, as per lines: > > $var(header_1)=3D $(hdr(Identity){s.select,0,.}); > $var(header_2)=3D $(hdr(Identity){s.select,1,.}); > > Logs show correctly that both variables are populated: > > May 10 09:09:42 kamailio1 kamailio[153201]: INFO: {1 10 INVITE > 1-1966540(a)10.20.0.1}