@@ -2845,7 +2845,7 @@ static ocsp_status_t ocsp_check(REQUEST *request, X509_STORE *store, X509 *issue
28452845/*
28462846 * For creating certificate attributes.
28472847 */
2848- static char const * cert_attr_names [11 ][2 ] = {
2848+ static char const * cert_attr_names [13 ][2 ] = {
28492849 { "TLS-Client-Cert-Serial" , "TLS-Cert-Serial" },
28502850 { "TLS-Client-Cert-Expiration" , "TLS-Cert-Expiration" },
28512851 { "TLS-Client-Cert-Subject" , "TLS-Cert-Subject" },
@@ -2857,6 +2857,8 @@ static char const *cert_attr_names[11][2] = {
28572857 { "TLS-Client-Cert-Valid-Since" , "TLS-Cert-Valid-Since" },
28582858 { "TLS-Client-Cert-Subject-Alt-Name-Uri" , "TLS-Cert-Subject-Alt-Name-Uri" },
28592859 { "TLS-Client-Cert-CRL-Distribution-Points" , "TLS-Cert-CRL-Distribution-Points" },
2860+ { "TLS-Client-Cert-Subject-Alt-Name-Directory-Name" , "TLS-Cert-Subject-Alt-Name-Directory-Name" },
2861+ { "TLS-Client-Cert-Subject-Alt-Name-Directory-Name-Common-Name" , "TLS-Cert-Subject-Alt-Name-Directory-Name-Common-Name" },
28602862};
28612863
28622864#define FR_TLS_SERIAL (0)
@@ -2870,6 +2872,9 @@ static char const *cert_attr_names[11][2] = {
28702872#define FR_TLS_VALID_SINCE (8)
28712873#define FR_TLS_SAN_URI (9)
28722874#define FR_TLS_CDP (10)
2875+ #define FR_TLS_SAN_DIRNAME (11)
2876+ #define FR_TLS_SAN_DIRNAME_CN (12)
2877+
28732878
28742879/*
28752880 * Extract Certification Distribution point URL from the certificate
@@ -2899,7 +2904,6 @@ static const char *get_cdp_url(DIST_POINT *dp)
28992904 return NULL ;
29002905}
29012906
2902-
29032907/*
29042908 * Before trusting a certificate, you must make sure that the
29052909 * certificate is 'valid'. There are several steps that your
@@ -2934,6 +2938,8 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
29342938 char common_name [1024 ];
29352939 char cn_str [1024 ];
29362940 char buf [64 ];
2941+ char dirname [1024 ]; /* Used for the san:dirname */
2942+ char dirname_common_name [1024 ];
29372943 X509 * client_cert ;
29382944#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER )
29392945 const STACK_OF (X509_EXTENSION ) * ext_list ;
@@ -3176,6 +3182,35 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
31763182 rdebug_pair (L_DBG_LVL_2 , request , vp , NULL );
31773183 break ;
31783184#endif /* GEN_URI */
3185+ #ifdef GEN_DIRNAME
3186+ case GEN_DIRNAME :
3187+ dirname [0 ] = '\0' ;
3188+
3189+ X509_NAME_oneline (name -> d .directoryName , dirname ,
3190+ sizeof (dirname ));
3191+ dirname [sizeof (dirname ) - 1 ] = '\0' ;
3192+ if (!dirname [0 ]) {
3193+ RWARN ("Invalid Directory Name in Subject Alt Name" );
3194+ break ;
3195+ }
3196+
3197+ vp = fr_pair_make (talloc_ctx , certs , cert_attr_names [FR_TLS_SAN_DIRNAME ][lookup ],
3198+ dirname , T_OP_SET );
3199+ rdebug_pair (L_DBG_LVL_2 , request , vp , NULL );
3200+
3201+ dirname_common_name [0 ] = '\0' ;
3202+ X509_NAME_get_text_by_NID (name -> d .directoryName ,
3203+ NID_commonName , dirname_common_name , sizeof (dirname_common_name ));
3204+ dirname_common_name [sizeof (dirname_common_name ) - 1 ] = '\0' ;
3205+
3206+ if (dirname_common_name [0 ]) {
3207+ vp = fr_pair_make (talloc_ctx , certs , cert_attr_names [FR_TLS_SAN_DIRNAME_CN ][lookup ],
3208+ dirname_common_name , T_OP_SET );
3209+ rdebug_pair (L_DBG_LVL_2 , request , vp , NULL );
3210+ }
3211+
3212+ break ;
3213+ #endif /* GEN_DIRNAME */
31793214 default :
31803215 /* XXX TODO handle other SAN types */
31813216 break ;
0 commit comments