Forum Discussion
iRule for client certificate verification and inserting CN
Hi dears,
I am trying to write an irule for the below conditions
Need to verify the client certificate available and valid otherwise 401 response for unauthorized clients, because this does not show 401 or any relevant messages on the browser for failed authentication.
Also need to add the CN from the client certificate as http header to backend server.
when CLIENTSSL_CLIENTCERT {
# Check if the client certificate was provided and valid
if { [SSL::cert count] == 0 || [SSL::verify_result] != 0 } {
# Set a flag to trigger the redirect for a failed certificate
set client_cert_failed 1
} else {
# Extract the Common Name (CN) from the client certificate
set client_cert_cn [X509::subject [SSL::cert 0]]
# Clear the flag as the certificate is valid
unset client_cert_failed
}
}
when HTTP_REQUEST {
# Check if the client certificate validation failed
if { [info exists client_cert_failed] && $client_cert_failed == 1 } {
# Send a 401 Unauthorized response
HTTP::respond 401 content "Unauthorized: Client Certificate Required" Content-Type "text/plain"
return
}
# Add the CN from the client certificate as a header if it exists
if { [info exists client_cert_cn] } {
HTTP::header insert X-Client-Cert-CN $client_cert_cn
}
}
But this does not have any hits when I apply to VS, any suggestion or how you overcome this requirement will be helpful.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com