Browse code

tls: get local/remote issuer line via $tls(key)

- new keys: m_issuer_line, p_issuer_line

Daniel-Constantin Mierla authored on 25/11/2021 08:55:31
Showing 1 changed files
... ...
@@ -1263,6 +1263,13 @@ int pv_parse_tls_name(pv_spec_p sp, str *in)
1263 1263
 		return -1;
1264 1264
 
1265 1265
 	switch(in->len) {
1266
+		case 13:
1267
+			if(strncmp(in->s, "m_issuer_line", 13)==0)
1268
+				sp->pvp.pvn.u.isname.name.n = 1001;
1269
+			else if(strncmp(in->s, "p_issuer_line", 13)==0)
1270
+				sp->pvp.pvn.u.isname.name.n = 5001;
1271
+			else goto error;
1272
+		break;
1266 1273
 		case 14:
1267 1274
 			if(strncmp(in->s, "m_subject_line", 14)==0)
1268 1275
 				sp->pvp.pvn.u.isname.name.n = 1000;
... ...
@@ -1309,9 +1316,9 @@ int pv_get_tls(struct sip_msg *msg, pv_param_t *param,
1309 1316
 					: SSL_get_peer_certificate(ssl);
1310 1317
 	if (cert == NULL) {
1311 1318
 		if (param->pvn.u.isname.name.n < 5000) {
1312
-			LM_ERR("Unable to retrieve my TLS certificate from SSL structure\n");
1319
+			LM_ERR("failed to retrieve my TLS certificate from SSL structure\n");
1313 1320
 		} else {
1314
-			LM_ERR("Unable to retrieve peer TLS certificate from SSL structure\n");
1321
+			LM_ERR("failed to retrieve peer TLS certificate from SSL structure\n");
1315 1322
 		}
1316 1323
 		goto error;
1317 1324
 	}
... ...
@@ -1325,8 +1332,21 @@ int pv_get_tls(struct sip_msg *msg, pv_param_t *param,
1325 1332
 			if(X509_NAME_oneline(X509_get_subject_name(cert), sv.s, sv.len)==NULL) {
1326 1333
 				goto error;
1327 1334
 			}
1335
+			tcpconn_put(c);
1336
+			return pv_get_strzval(msg, param, res, sv.s);
1337
+		break;
1338
+
1339
+		case 1001:
1340
+		case 5001:
1341
+			sv.s = pv_get_buffer();
1342
+			sv.len = pv_get_buffer_size() - 1;
1343
+			if(X509_NAME_oneline(X509_get_issuer_name(cert), sv.s, sv.len)==NULL) {
1344
+				goto error;
1345
+			}
1346
+			tcpconn_put(c);
1328 1347
 			return pv_get_strzval(msg, param, res, sv.s);
1329 1348
 		break;
1349
+
1330 1350
 		default:
1331 1351
 			goto error;
1332 1352
 	}