Browse code

tls: add support for unique identifier PVs and select (GH #1843)

- add support for unique identifier PVs and select, related to issue GH #1843
- new PVs: $tls_peer_subject_uid and $tls_my_subject_uid
- new selects: uid, uniqueIdentifier and unique_identifier

Henning Westerholt authored on 10/02/2019 13:30:45
Showing 1 changed files
... ...
@@ -68,6 +68,7 @@ enum {
68 68
 	COMP_URI,         /* URI from subject/alternative */
69 69
 	COMP_E,           /* Email address */
70 70
 	COMP_IP,          /* IP from subject/alternative */
71
+	COMP_UI,          /* Unique identifier */
71 72
 	TLSEXT_SN         /* Server name of the peer */
72 73
 };
73 74
 
... ...
@@ -96,8 +97,9 @@ enum {
96 97
 	PV_COMP_URI  = 1<<17,        /* URI from subject/alternative */
97 98
 	PV_COMP_E    = 1<<18,        /* Email address */
98 99
 	PV_COMP_IP   = 1<<19,        /* IP from subject/alternative */
100
+	PV_COMP_UI   = 1<<20,        /* Unique identifier */
99 101
 
100
-	PV_TLSEXT_SNI = 1<<20,       /* Peer's server name (TLS extension) */
102
+	PV_TLSEXT_SNI = 1<<21,       /* Peer's server name (TLS extension) */
101 103
 };
102 104
 
103 105
 
... ...
@@ -712,6 +714,7 @@ static int get_comp(str* res, int local, int issuer, int nid, sip_msg_t* msg)
712 714
 		case NID_countryName:            elem = "CountryName";             break;
713 715
 		case NID_stateOrProvinceName:    elem = "StateOrProvinceName";     break;
714 716
 		case NID_localityName:           elem = "LocalityName";            break;
717
+		case NID_x500UniqueIdentifier:   elem = "UniqueIdentifier";        break;
715 718
 		default:                         elem = "Unknown";                 break;
716 719
 		}
717 720
 		DBG("Element %s not found in certificate subject/issuer\n", elem);
... ...
@@ -759,6 +762,7 @@ static int sel_comp(str* res, select_t* s, sip_msg_t* msg)
759 762
 		case COMP_C:       nid = NID_countryName;            break;
760 763
 		case COMP_ST:      nid = NID_stateOrProvinceName;    break;
761 764
 		case COMP_L:       nid = NID_localityName;           break;
765
+		case COMP_UI:      nid = NID_x500UniqueIdentifier;   break;
762 766
 		default:
763 767
 			BUG("Bug in sel_comp: %d\n", s->params[s->n - 1].v.i);
764 768
 			return -1;
... ...
@@ -806,6 +810,7 @@ static int pv_comp(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
806 810
 		case PV_COMP_C:  nid = NID_countryName;            break;
807 811
 		case PV_COMP_ST: nid = NID_stateOrProvinceName;    break;
808 812
 		case PV_COMP_L:  nid = NID_localityName;           break;
813
+		case PV_COMP_UI: nid = NID_x500UniqueIdentifier;   break;
809 814
 		default:      nid = NID_undef;
810 815
 	}
811 816
 
... ...
@@ -1132,6 +1137,10 @@ select_row_t tls_sel[] = {
1132 1137
 	{ sel_name, SEL_PARAM_STR, STR_STATIC_INIT("organizational_unit_name"), sel_comp, DIVERSION | COMP_OU},
1133 1138
 	{ sel_name, SEL_PARAM_STR, STR_STATIC_INIT("unit"),                     sel_comp, DIVERSION | COMP_OU},
1134 1139
 
1140
+	{ sel_name, SEL_PARAM_STR, STR_STATIC_INIT("uid"),               sel_comp, DIVERSION | COMP_UI},
1141
+	{ sel_name, SEL_PARAM_STR, STR_STATIC_INIT("uniqueIdentifier"),  sel_comp, DIVERSION | COMP_UI},
1142
+	{ sel_name, SEL_PARAM_STR, STR_STATIC_INIT("unique_identifier"), sel_comp, DIVERSION | COMP_UI},
1143
+
1135 1144
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
1136 1145
 };
1137 1146
 
... ...
@@ -1251,6 +1260,13 @@ pv_export_t tls_pv[] = {
1251 1260
 	{{"tls_my_issuer_unit", sizeof("tls_my_issuer_unit")-1},
1252 1261
 		PVT_OTHER, pv_comp, 0,
1253 1262
 		0, 0, pv_init_iname, PV_CERT_LOCAL | PV_CERT_ISSUER  | PV_COMP_OU },
1263
+	/* unique identifier for peer and local */
1264
+	{{"tls_peer_subject_uid", sizeof("tls_peer_subject_uid")-1},
1265
+		PVT_OTHER, pv_comp, 0,
1266
+		0, 0, pv_init_iname, PV_CERT_PEER | PV_CERT_SUBJECT | PV_COMP_UI },
1267
+	{{"tls_my_subject_uid", sizeof("tls_my_subject_uid")-1},
1268
+		PVT_OTHER, pv_comp, 0,
1269
+		0, 0, pv_init_iname, PV_CERT_LOCAL | PV_CERT_SUBJECT | PV_COMP_UI },
1254 1270
 	/* subject alternative name parameters for peer and local */	
1255 1271
 	{{"tls_peer_san_email", sizeof("tls_peer_san_email")-1},
1256 1272
 		PVT_OTHER, pv_alt, 0,