Browse code

tls: fix raw vs urlencoded behavior in sel_ssl_cert()

Armen Babikyan authored on 18/04/2020 21:18:40 • Henning Westerholt committed on 19/04/2020 10:36:56
Showing 1 changed files
... ...
@@ -756,16 +756,18 @@ static int get_ssl_cert(str* res, int local, int urlencoded, sip_msg_t* msg)
756 756
 
757 757
 static int sel_ssl_cert(str* res, select_t* s, sip_msg_t* msg)
758 758
 {
759
-	int local=0, urlencoded=0;
759
+	int i, local = 0, urlencoded = 0;
760 760
 
761
-	switch(s->params[s->n - 2].v.i) {
762
-	case CERT_PEER: local = 0; break;
763
-	case CERT_LOCAL: local = 1; break;
764
-	case CERT_RAW: urlencoded = 0; break;
765
-	case CERT_URLENCODED: urlencoded = 1; break;
766
-	default:
767
-		BUG("Bug in call to sel_ssl_cert\n");
768
-		return -1;
761
+	for(i = 1; i <= s->n - 1; i++) {
762
+		switch(s->params[i].v.i) {
763
+		case CERT_PEER:       local = 0; break;
764
+		case CERT_LOCAL:      local = 1; break;
765
+		case CERT_RAW:        urlencoded = 0; break;
766
+		case CERT_URLENCODED: urlencoded = 1; break;
767
+		default:
768
+			BUG("Bug in call to sel_ssl_cert\n");
769
+			return -1;
770
+		}
769 771
 	}
770 772
 
771 773
 	return get_ssl_cert(res, local, urlencoded, msg);
... ...
@@ -1201,10 +1203,10 @@ select_row_t tls_sel[] = {
1201 1203
 
1202 1204
 	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("version"), sel_cert_version, 0},
1203 1205
 
1204
-	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("rawCert"), sel_ssl_cert, CERT_RAW},
1205
-	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("raw_cert"), sel_ssl_cert, CERT_RAW},
1206
-	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("URLEncodedCert"), sel_ssl_cert, CERT_URLENCODED},
1207
-	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("urlencoded_cert"), sel_ssl_cert, CERT_URLENCODED},
1206
+	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("rawCert"), sel_ssl_cert, DIVERSION | CERT_RAW},
1207
+	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("raw_cert"), sel_ssl_cert, DIVERSION | CERT_RAW},
1208
+	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("URLEncodedCert"), sel_ssl_cert, DIVERSION | CERT_URLENCODED},
1209
+	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("urlencoded_cert"), sel_ssl_cert, DIVERSION | CERT_URLENCODED},
1208 1210
 
1209 1211
 	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("sn"),            sel_sn, 0},
1210 1212
 	{ sel_cert, SEL_PARAM_STR, STR_STATIC_INIT("serialNumber"),  sel_sn, 0},