[sr-dev] git:master:f264b374: jwt: added function to verify with key value given as parameter

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 23 10:39:46 CET 2022


Module: kamailio
Branch: master
Commit: f264b3745a2e666f9bb617cb1d5cf9ac0e1a439e
URL: https://github.com/kamailio/kamailio/commit/f264b3745a2e666f9bb617cb1d5cf9ac0e1a439e

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-11-23T10:35:55+01:00

jwt: added function to verify with key value given as parameter

---

Modified: src/modules/jwt/jwt_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f264b3745a2e666f9bb617cb1d5cf9ac0e1a439e.diff
Patch: https://github.com/kamailio/kamailio/commit/f264b3745a2e666f9bb617cb1d5cf9ac0e1a439e.patch

---

diff --git a/src/modules/jwt/jwt_mod.c b/src/modules/jwt/jwt_mod.c
index 0afedd237c..adda8d3845 100644
--- a/src/modules/jwt/jwt_mod.c
+++ b/src/modules/jwt/jwt_mod.c
@@ -46,6 +46,8 @@ static int w_jwt_generate_4(sip_msg_t* msg, char* pkey, char* palg, char* pclaim
 static int w_jwt_generate_3(sip_msg_t* msg, char* pkey, char* palg, char* pclaims);
 static int w_jwt_verify(sip_msg_t* msg, char* pkeypath, char* palg, char* pclaims,
 		char *pjwtval);
+static int w_jwt_verify_key(sip_msg_t* msg, char* pkey, char* palg, char* pclaims,
+		char *pjwtval);
 
 static int _jwt_key_mode = 0;
 
@@ -67,6 +69,8 @@ static cmd_export_t cmds[]={
 		fixup_spve_all, 0, ANY_ROUTE},
 	{"jwt_verify", (cmd_function)w_jwt_verify, 4,
 		fixup_spve_all, 0, ANY_ROUTE},
+	{"jwt_verify_key", (cmd_function)w_jwt_verify_key, 4,
+		fixup_spve_all, 0, ANY_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -596,6 +600,37 @@ static int w_jwt_verify(sip_msg_t* msg, char* pkeypath, char* palg, char* pclaim
 	return ki_jwt_verify(msg, &skeypath, &salg, &sclaims, &sjwtval);
 }
 
+/**
+ *
+ */
+static int w_jwt_verify_key(sip_msg_t* msg, char* pkey, char* palg, char* pclaims,
+		char *pjwtval)
+{
+	str skey = STR_NULL;
+	str salg = STR_NULL;
+	str sclaims = STR_NULL;
+	str sjwtval = STR_NULL;
+
+	if (fixup_get_svalue(msg, (gparam_t*)pkey, &skey) != 0) {
+		LM_ERR("cannot get the key value\n");
+		return -1;
+	}
+	if (fixup_get_svalue(msg, (gparam_t*)palg, &salg) != 0) {
+		LM_ERR("cannot get algorithm value\n");
+		return -1;
+	}
+	if (fixup_get_svalue(msg, (gparam_t*)pclaims, &sclaims) != 0) {
+		LM_ERR("cannot get claims value\n");
+		return -1;
+	}
+	if (fixup_get_svalue(msg, (gparam_t*)pjwtval, &sjwtval) != 0) {
+		LM_ERR("cannot get jwt value\n");
+		return -1;
+	}
+
+	return ki_jwt_verify(msg, &skey, &salg, &sclaims, &sjwtval);
+}
+
 /**
  *
  */
@@ -650,6 +685,11 @@ static sr_kemi_t sr_kemi_jwt_exports[] = {
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
 			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("jwt"), str_init("jwt_verify_key"),
+		SR_KEMIP_INT, ki_jwt_verify_key,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };




More information about the sr-dev mailing list