Browse code

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

Daniel-Constantin Mierla authored on 23/11/2022 09:35:55
Showing 1 changed files
... ...
@@ -46,6 +46,8 @@ static int w_jwt_generate_4(sip_msg_t* msg, char* pkey, char* palg, char* pclaim
46 46
 static int w_jwt_generate_3(sip_msg_t* msg, char* pkey, char* palg, char* pclaims);
47 47
 static int w_jwt_verify(sip_msg_t* msg, char* pkeypath, char* palg, char* pclaims,
48 48
 		char *pjwtval);
49
+static int w_jwt_verify_key(sip_msg_t* msg, char* pkey, char* palg, char* pclaims,
50
+		char *pjwtval);
49 51
 
50 52
 static int _jwt_key_mode = 0;
51 53
 
... ...
@@ -67,6 +69,8 @@ static cmd_export_t cmds[]={
67 69
 		fixup_spve_all, 0, ANY_ROUTE},
68 70
 	{"jwt_verify", (cmd_function)w_jwt_verify, 4,
69 71
 		fixup_spve_all, 0, ANY_ROUTE},
72
+	{"jwt_verify_key", (cmd_function)w_jwt_verify_key, 4,
73
+		fixup_spve_all, 0, ANY_ROUTE},
70 74
 	{0, 0, 0, 0, 0, 0}
71 75
 };
72 76
 
... ...
@@ -596,6 +600,37 @@ static int w_jwt_verify(sip_msg_t* msg, char* pkeypath, char* palg, char* pclaim
596 600
 	return ki_jwt_verify(msg, &skeypath, &salg, &sclaims, &sjwtval);
597 601
 }
598 602
 
603
+/**
604
+ *
605
+ */
606
+static int w_jwt_verify_key(sip_msg_t* msg, char* pkey, char* palg, char* pclaims,
607
+		char *pjwtval)
608
+{
609
+	str skey = STR_NULL;
610
+	str salg = STR_NULL;
611
+	str sclaims = STR_NULL;
612
+	str sjwtval = STR_NULL;
613
+
614
+	if (fixup_get_svalue(msg, (gparam_t*)pkey, &skey) != 0) {
615
+		LM_ERR("cannot get the key value\n");
616
+		return -1;
617
+	}
618
+	if (fixup_get_svalue(msg, (gparam_t*)palg, &salg) != 0) {
619
+		LM_ERR("cannot get algorithm value\n");
620
+		return -1;
621
+	}
622
+	if (fixup_get_svalue(msg, (gparam_t*)pclaims, &sclaims) != 0) {
623
+		LM_ERR("cannot get claims value\n");
624
+		return -1;
625
+	}
626
+	if (fixup_get_svalue(msg, (gparam_t*)pjwtval, &sjwtval) != 0) {
627
+		LM_ERR("cannot get jwt value\n");
628
+		return -1;
629
+	}
630
+
631
+	return ki_jwt_verify(msg, &skey, &salg, &sclaims, &sjwtval);
632
+}
633
+
599 634
 /**
600 635
  *
601 636
  */
... ...
@@ -650,6 +685,11 @@ static sr_kemi_t sr_kemi_jwt_exports[] = {
650 685
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
651 686
 			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
652 687
 	},
688
+	{ str_init("jwt"), str_init("jwt_verify_key"),
689
+		SR_KEMIP_INT, ki_jwt_verify_key,
690
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
691
+			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
692
+	},
653 693
 
654 694
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
655 695
 };