Browse code

secsipid: added secsipid_sign(headers, payload, keypath)

- store the result in $secsipid(val)

Daniel-Constantin Mierla authored on 20/06/2021 09:28:37
Showing 1 changed files
... ...
@@ -58,6 +58,7 @@ static int w_secsipid_add_identity(sip_msg_t *msg, char *porigtn, char *pdesttn,
58 58
 			char *pattest, char *porigid, char *px5u, char *pkeypath);
59 59
 static int w_secsipid_build_identity(sip_msg_t *msg, char *porigtn, char *pdesttn,
60 60
 			char *pattest, char *porigid, char *px5u, char *pkeypath);
61
+static int w_secsipid_sign(sip_msg_t *msg, char *phdrs, char *ppayload, char *pkeypath);
61 62
 static int w_secsipid_get_url(sip_msg_t *msg, char *purl, char *pout);
62 63
 
63 64
 static int secsipid_libopt_param(modparam_t type, void *val);
... ...
@@ -89,6 +90,8 @@ static cmd_export_t cmds[]={
89 90
 		fixup_spve_all, fixup_free_spve_all, ANY_ROUTE},
90 91
 	{"secsipid_build_identity", (cmd_function)w_secsipid_build_identity, 6,
91 92
 		fixup_spve_all, fixup_free_spve_all, ANY_ROUTE},
93
+	{"secsipid_sign", (cmd_function)w_secsipid_sign, 3,
94
+		fixup_spve_all, fixup_free_spve_all, ANY_ROUTE},
92 95
 	{"secsipid_get_url", (cmd_function)w_secsipid_get_url, 2,
93 96
 		fixup_spve_pvar, fixup_free_spve_pvar, ANY_ROUTE},
94 97
 	{0, 0, 0, 0, 0, 0}
... ...
@@ -379,6 +382,7 @@ static int w_secsipid_check(sip_msg_t *msg, char *pidentity, char *pkeypath)
379 382
 	return ki_secsipid_check(msg, &sidentity, &keypath);
380 383
 }
381 384
 
385
+
382 386
 /**
383 387
  *
384 388
  */
... ...
@@ -573,6 +577,75 @@ static int w_secsipid_build_identity(sip_msg_t *msg, char *porigtn, char *pdestt
573 577
 			&attest, &origid, &x5u, &keypath, 1);
574 578
 }
575 579
 
580
+/**
581
+ *
582
+ */
583
+static int ki_secsipid_sign(sip_msg_t *msg, str *sheaders, str *spayload,
584
+		str *keypath)
585
+{
586
+	str ibody = STR_NULL;
587
+
588
+	if(secsipid_libopt_list_used==0) {
589
+		str_list_t *sit;
590
+		for(sit=secsipid_libopt_list; sit!=NULL; sit=sit->next) {
591
+			_secsipid_papi.SecSIPIDOptSetV(sit->s.s);
592
+		}
593
+		secsipid_libopt_list_used = 1;
594
+	}
595
+
596
+	ibody.len = _secsipid_papi.SecSIPIDSignJSONHP(sheaders->s, spayload->s,
597
+			keypath->s, &ibody.s);
598
+
599
+	_secsipid_data.ret = ibody.len;
600
+
601
+	if(ibody.len<=0) {
602
+		LM_ERR("failed to get identity value (%d)\n", ibody.len);
603
+		goto error;
604
+	}
605
+
606
+	LM_DBG("identity value: %.*s\n", ibody.len, ibody.s);
607
+
608
+	if(_secsipid_data.value.s) {
609
+		free(_secsipid_data.value.s);
610
+	}
611
+	_secsipid_data.value = ibody;
612
+
613
+	return 1;
614
+
615
+error:
616
+	if(ibody.s) {
617
+		free(ibody.s);
618
+	}
619
+	return -1;
620
+}
621
+
622
+/**
623
+ *
624
+ */
625
+static int w_secsipid_sign(sip_msg_t *msg, char *phdrs, char *ppayload, char *pkeypath)
626
+{
627
+	str shdrs = STR_NULL;
628
+	str spayload = STR_NULL;
629
+	str keypath = STR_NULL;
630
+
631
+	if(fixup_get_svalue(msg, (gparam_t*)phdrs, &shdrs)<0) {
632
+		LM_ERR("failed to get JSON headers parameter\n");
633
+		return -1;
634
+	}
635
+
636
+	if(fixup_get_svalue(msg, (gparam_t*)ppayload, &spayload)<0) {
637
+		LM_ERR("failed to get JSON payload parameter\n");
638
+		return -1;
639
+	}
640
+
641
+	if(fixup_get_svalue(msg, (gparam_t*)pkeypath, &keypath)<0) {
642
+		LM_ERR("failed to get keypath parameter\n");
643
+		return -1;
644
+	}
645
+
646
+	return ki_secsipid_sign(msg, &shdrs, &spayload, &keypath);
647
+}
648
+
576 649
 /**
577 650
  *
578 651
  */