Forum Discussion
Jason_Witt_4207
Oct 24, 2005Historic F5 Account
iRule to require SSL Client Certs for a URI
Working on developing a Rule based on the SSL Client Cert for URI in Docs and Tips. We first tried the rule verbatim with the exception of changing the URI to match what they wanted to protect. This works fine for the non protected URIs but the protected URI just hangs.
rule stock_ssl_req {
when CLIENT_ACCEPTED {
set needcert 0
set gotcert 0
}
when HTTP_REQUEST {
if { $gotcert == 0 and [HTTP::uri] starts_with "/sas/controller" } {
log LOCAL0.warn "Requiring certificate..."
HTTP::collect
SSL::cert mode require
SSL::renegotiate
set needcert 1
}
else {
log LOCAL0.warn "No cert needed."
}
}
when CLIENTSSL_HANDSHAKE {
log LOCAL0.warn "cert count=[SSL::cert count] result=[SSL::verify_result]"
if { [SSL::cert count] == 0 or [SSL::verify_result] != 0 } {
log LOCAL0.warn "Bad cert!"
if { $needcert == 1 } {
reject
}
}
else {
log LOCAL0.warn "Good cert! ($needcert)"
set gotcert 1
if { $needcert == 1 } {
HTTP::release
}
}
}
}
This is on version 9.2. Haven't tried it on any previous versions yet, but given 9.2 is require for use of the ASM as well, it doesn't matter on any other version.
- Jason_Witt_4207Historic F5 AccountI tried a bit more on this rule and I get varying results depending on which peer cert mode I start with in the clientssl profile.
- James_Yang_9981
Altostratus
it seems that this post have leaved here about half year. is there any result of this issue? I also meet a customer that require this feature. - James_Yang_9981
Altostratus
I have tested this rule. it seems that start with profile cert ignore, then changing the cert mode to require, client will prompt for a certificate. but after apply the certificate. the connection will be rejected. - James_Yang_9981
Altostratus
At Last, I got the rules below that can working.when CLIENTSSL_HANDSHAKE { log LOCAL0.warn "cert count=[SSL::cert count]" if { [SSL::cert count] ==0 } { log LOCAL0.warn "when client handshake,ssl cert count is 0,pass" } else { log LOCAL0.warn "when clent handshake , two way cert founded and the cert count is [SSL::cert count] " HTTP::release } } when HTTP_REQUEST { if {[HTTP::uri] starts_with "/manual/" } { log "Requiring certificate...and tht request uri is :[HTTP::uri]" if {[SSL::cert count] == 0} { log local0. "when http request,ssl cert count is 0,now http collect" HTTP::collect SSL::authenticate always SSL::authenticate depth 9 SSL::cert mode require log local0. "when http request,now renegotiating" SSL::renegotiate } } else { log LOCAL0.warn "No cert needed,to server directly.And the uri is [HTTP::uri]" } }
- Steve_Brockman_
Nimbostratus
Hi, - Garrett_Skjelst
Nimbostratus
This is actually something that looks very interesting, and I'm curious to know why people were having a difficult time running thi on 9.4.x? (I'll get to try with 10.x and 9.4.x)
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects