when CLIENTSSL_CLIENTCERT {
set subject_dn 0
Check if client provided a cert
if { [SSL::cert count] > 0 } {
set subject_dn [X509::subject [SSL::cert 0]]
}
}
when HTTP_REQUEST {
set user_in_path [string trim [HTTP::uri] "/"]
if { ! ($subject_dn contains "cn=$user_in_path") } {
reject
}
}
Only the leaf cert, [SSL::cert 0] is used for client SSL checking. This should also work;-
when HTTP_REQUEST {
set cn [class match -value [HTTP::path] starts_with dg_path_common_name_mapping]
if {$cn ne ""} {
Client certificate is required for this path
if {![SSL::cert count]} {
HTTP::respond 403 content "Client certificate required" noserver
return
} elseif {!([X509::subject [SSL::cert 0]] contains $cn)} {
Client cert doesn't match required Common Name
HTTP::respond 403 content "Client certificate does not match required name $cn" noserver
return
}
}
}
when CLIENTSSL_HANDSHAKE {
if {![info exists username]} {set username ""}
}
when CLIENTSSL_CLIENTCERT {
Check if client provided a cert
if { [SSL::cert count] > 0 } {
set username [regsub -all ".*CN=(.\[^,\]*),.*$" [X509::subject [SSL::cert 0]] {\1}]
}
}
when HTTP_REQUEST {
if {[HTTP::uri] equals /} {
HTTP::redirect "/$username"
}elseif { !([HTTP::uri] starts_with "/$username") } {
HTTP::respond 403 content {
Not authorized
You are not autorized to access this website
} noserver
}
}