Forum Discussion
Ron_Kim_110696
Jan 11, 2007Nimbostratus
iRule example to extract specific X509 information: SOL5171
I can't get this iRule to work.
The variable $sn in the HTTP_REQUEST section does not have a value.
It is working in the CLIENTSSL_CLIENTCERT section.
Variables do not seem to pass from the CLIENTSSL_CLIENTCERT to the HTTP_REQUEST sections.
================
iRule example to extract specific X509 information: SOL5171
In the following example, a variable value is set using an SSL command to identify the X509 certificate. Once the X509 certificate is identified, another variable value is set using an X509 command to extract the certificate serial number. The client certificate's serial number is then inserted into an HTTP header with the name Serial.
when CLIENTSSL_CLIENTCERT {
set cert [SSL::cert 0]
set sn [X509::serial_number $cert]
}
when HTTP_REQUEST {
if { [info exists sn] } {
HTTP::header insert Serial $sn
}
}
- Colin_Walker_12Historic F5 AccountWhen you say that the $sn variable doesn't have a value, are you saying that because the "Serial" header being inserted is blank? Is the Serial header even being inserted?
when CLIENTSSL_CLIENTCERT { set cert [SSL::cert 0] set sn [X509::serial_number $cert] log local0. "cert is $cert" log local0. "sn is $sn" } when HTTP_REQUEST { if { [info exists $sn] } { HTTP::header insert Serial $sn log local0. "sn is $sn" } }
- Ron_Kim_110696NimbostratusThank you.
- Deb_Allen_18Historic F5 AccountI talked to one of my co-workers who encountered this difficulty, and he worked around it by saving the value in the session table in CLIENTSSL_CLIENTCERT with a key of ssl-id, then pulled it out of the session table in HTTP_REQUEST as in this codeshare example:
- Ron_Kim_110696NimbostratusThanks.
- Colin_Walker_12Historic F5 AccountIf it were me, I would create a class of URIs (assuming you have more than 10-15 or so, otherwise an if/else chain or switch is more efficient), and check to see if the incoming URI is in that class. On success, I'd force the cert mode to require.
when HTTP_REQUEST { if { [matchclass [HTTP::uri] starts_with $::certURIs] } { SSL::authenticate always SSL::authenticate depth 9 SSL::cert mode require SSL::renegotiate } }
- Ron_Kim_110696NimbostratusThanks Colin.
- Ron_Kim_110696NimbostratusHigh Level Goals of the iRule for a virtual server with HTTPS are:
- kolejarzNimbostratusThere is a sample irule from F5 support:
when CLIENTSSL_CLIENTCERT { HTTP::release if { [SSL::cert count] < 1 } { reject } } when HTTP_REQUEST { if { [matchclass [HTTP::uri] starts_with $::requires_client_cert] } { if { [SSL::cert count] <= 0 } { HTTP::collect SSL::authenticate always SSL::authenticate depth 9 SSL::cert mode require SSL::renegotiate } } } when HTTP_REQUEST_SEND { clientside { if { [SSL::cert count] > 0 } { HTTP::header insert "X-SSL-Session-ID" [SSL::sessionid] HTTP::header insert "X-SSL-Client-Cert-Status" [X509::verify_cert_error_string [SSL::verify_result]] HTTP::header insert "X-SSL-Client-Cert-Subject" [X509::subject [SSL::cert 0]] HTTP::header insert "X-SSL-Client-Cert-Issuer" [X509::issuer [SSL::cert 0]] } } }
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