iRule Optimization w/ Certificates?

The iRule below functions and performs as it should. I have been told that what I have below may not be efficient or optimized. I am looking to see if anyone can make some suggestions on how to better optimize. I would also like to know if session persistence and timeout are being maintained as they should. This iRule performs client side cert authentication only when a certain URI is sent. Upon successfull login, header information from the cert is passed to the receiving application. The code below was pieced together from other iRules on DevCentral.

when CLIENTSSL_CLIENTCERT {

set cert [SSL::cert 0]

HTTP::release

if { [SSL::cert count] < 1 } {

reject

}

}

when HTTP_REQUEST {

set v1 [URI::query [HTTP::uri] “p”]

if { ($v1 contains “ESAT”) || ($v1 contains “311”) } then {

if { [SSL::cert count] <= 0 } {

HTTP::collect

SSL::session invalidate

SSL::authenticate always

SSL::authenticate depth 9

SSL::cert mode request

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 “SSL_CLIENT_S_DN”[X509::subject [SSL::cert 0]]

HTTP::header insert “SSL_CLIENT_I_DN”[X509::issuer [SSL::cert 0]]

}

}

}

Hi Scot,

That iRule would request a client cert any time the URI checks are true, even if the client has already presented a cert on the same TCP connection or on another TCP connection trying to re-use the same SSL session ID. Also note that you’re checking the cert validity against the client SSL trusted cert bundle using SSL::verify_result, but you’re not doing anything if the cert is invalid. I assume the application is checking the headers and handling invalid certs?

You could make this more efficient by storing the cert details in the session table and then checking when a restricted URI is requested to see if the SSL session ID has a corresponding session table entry. If so, you could insert the cert details in the headers without invalidating the session and requesting a client cert again.

You can add/retrieve key-value pairs to the session table using the session command:

http://devcentral.f5.com/wiki/default.aspx/iRules/session

If you’re inserting the verification string, subject and issuer into the HTTP headers, it would make sense to parse these values once per SSL session and then insert them into the session table using the SSL session ID as the key. You’d also want to check that the SSL session isn’t 64 zeroes (Click here as this is what SSL::sessionid will return if the client’s SSL session ID isn’t in LTM’s SSL cache.

I’ll try to give an example later this week if I have time to test one. Can you confirm which LTM version you’re running? You could also try updating your rule to use the session table and reply here if you get stuck.

Also, your iRule isn’t doing anything with pool selection or persistence. So it would be up to the VIP’s persistence profile to handle persistence and the persistence timeout.

Aaron

Aaron,

Thank you for all the great information. I will be adding in the OCSP checking of the cert once we get that process working (AUTH_ERROR, AUTH_FAIL, etc). As for the session table, I understand what you are saying, but am pretty clueless on how to implement. I have noticed the issues you are speaking about. I have seen a lot of code out on DevCentral about this, but have been unable to weave it in to my scenario. Lets just say, I am extremely junior with the F5 (LTM1500 - 9.4.6). Any help would be greatly appreciated.

-Scot

If you’re going to do OCSP checking of the client cert, I’ll add a rule I’ve been working on which does this to the iRule Codeshare. I’ll try to do this by Friday. You’ll need to upgrade to 9.4.8HF3 in order to use it.

Aaron

I’ve done a quick job of anonymizing the iRule and added it to the Codeshare. I didn’t do any testing of the iRule or sample config after removing the customer-specific options. If you’re able to upgrade to v9.4.8 and install hotfix 3, can you test this and let me know if you have any problems. Please do make sure to do thorough testing before using in a production environment.

http://devcentral.f5.com/wiki/default.aspx/iRules/client\_cert\_request\_by\_uri\_with\_ocsp\_checking.html

Thanks,

Aaron

Aaron,

Thank you.

I have taken my orginal iRule I posted and think I have added in session gathering/persistence correctly. Currently, I am working w/ F5 to get my OCSP responders to work. Once that happens, i will move on to checking those results. I hope what I have done closes some of my previous mistakes/holes.

when CLIENTSSL_CLIENTCERT {

set time to maintain session data (in seconds)

set session_timeout 1800

set ssl_cert [SSL::cert 0]

set ssl_errstr [X509::verify_cert_error_string [SSL::verify_result]]

set ssl_subject [X509::subject [SSL::cert 0]]

set ssl_issuer [X509::issuer [SSL::cert 0]]

set ssl_stuff [list $ssl_cert $ssl_errstr $ssl_subject $ssl_issuer]

session add ssl [SSL::sessionid] $ssl_stuff $session_timeout

HTTP::release

if { [SSL::cert count] < 1 } {

reject

}

}

when HTTP_REQUEST {

set v1 [URI::query [HTTP::uri] “p”]

if { ($v1 contains “ESAT”) || ($v1 contains “311”) } then {

if { [SSL::cert count] <= 0 } {

HTTP::collect

SSL::session invalidate

SSL::authenticate always

SSL::authenticate depth 9

SSL::cert mode request

SSL::renegotiate

}

}

}

when HTTP_REQUEST_SEND {

clientside {

if { [SSL::cert count] > 0 } {

set ssl_stuff2 [session lookup ssl [SSL::sessionid]]

set ssl_cert2 [lindex $ssl_stuff2 0]

set ssl_errstr2 [lindex $ssl_stuff2 1]

set ssl_subject2 [lindex $ssl_stuff2 2]

set ssl_issuer2 [lindex $ssl_stuff2 3]

if { $ssl_errstr2 eq “ok” } {

HTTP::header insert SSLClientCertStatus $ssl_errstr2

HTTP::header insert SSLClientCertSN [X509::serial_number $ssl_cert2]

HTTP::header insert “SSL_CLIENT_S_DN” $ssl_subject2

HTTP::header insert “SSL_CLIENT_I_DN” $ssl_issuer2

} else {

send HTTP 302 redirect to an error page

HTTP::redirect “http://images.mhf.dod.mil/error.html”

}

}

}

}

The issue with that approach is that you cannot send an HTTP response from the HTTP_REQUEST_SEND event. When I ran into that issue, F5 development created a hotfix to allow sending an HTTP response from the CLIENTSSL_HANDSHAKE event:

CR125264 - HTTP::respond should be allowed in CLIENTSSL_HANDSHAKE (fix ncluded in 9.4.8HF3)

Also, you’re resetting the connection in CLIENTSSL_CLIENTCERT if the client doesn’t present a cert. To handle this more gracefully and send an HTTP response in that case, you need another fix included in 9.4.8HF3:

CR111646: Connections are no longer rejected when clients fail to send a certificate to a virtual server with a clientssl profile configured to “request” one.

Aaron

Aaron, Due to a slew of issues/conflicts with my iRULE and the default ocsp iRULE provided by F5, I have started working w/ the iRULE you provided. In my case, I have multiple responders. Is there a way for me to check the status of each responders results?

Hi Scot,

I think it’s more reasonable to replace the default OCSP auth rule on the auth profile with a custom rule versus trying to use a separate custom rule on the VIP along with the default auth rule on the auth profile.

Do you want to load balance the OCSP servers? If so, you can follow the sample configuration in the Codeshare example which shows how to configure an “internal” virtual server pointing to a pool of OCSP servers. If that’s not what you’re trying to do, can you rephrase the question?

Also, I wouldn’t bother trying to test the Codeshare iRule unless you’ve been able to upgrade to 9.4.8HF3. I think you’ll get iRule validation errors in previous versions of 9.4.x.

Thanks,

Aaron

Aaron,

I upgraded both of my F5’s to the reccommended levels last night. It seems that the OCSP Responder settings produce different results. I set up my DoD responder with the same options as you provided and IT WORKS. My Verisign ECA responder is not working at all. I wonder if there are specific settings for it?

My question was, is there a way for the iRULE to tell me the success or failer of each responder as I have 2. I am having trouble with the Verisign responder. But I am now batting .500. Not bad for being clueless.

500 is not a bad start! Can you explain why you’re trying to check the client cert against a DOD and Verisign OCSP server? Are there two different sets of CA’s issuing the client certs?

The idea with the VIP for the OCSP servers is that you can eventually configure an external monitor which replicates a client OCSP request. If the OCSP server fails to respond to the monitor requests, it would be marked down in the pool and not used.

To troubleshoot the responder failure, I’d start with a command line request from LTM direct to the server to see if the TCP connection works and if so whether you get an HTTP response. If that works, then try making the same request to the OCSP VIP with only the Verisign server enabled in the pool. If you get an HTTP response from the VIP, then try the client cert VIP again with only the Verisign server enabled in the pool. If the OCSP auth fails, I’d try loosening the validation of the OCSP server(s) in the OCSP responder config.

Aaron

Aaron,

In our environment, we deal w/ 2 sets of certificates. DoD CAC and Verisign ECA. As a result, I have 2 responders.

I dont understand what you mean by “command line request from LTM direct to the server to see if the TCP connection works and if so whether you get an HTTP response”. I can telnet over port 80 to the host address from an LTM ssh session. But that is just telling me that there is a path. I am not seeing any traffic using TCPDUMP for that host. Its very frustrating!

Aaron,

My testing seems to show that the Verisign responder only works if it is the only responder in the configuration. The DoD responder seems to work regardless of whether one or both are added to the configuration. What I am finding is that the Verisign responder does not work when the DoD responder is in the configuration. Any idea why this might be? http://eca-client-ocsp.verisign.com

Any idea on maybe how to work around this?

There are a few options, but I’m not sure which is best. Let me do some preliminary testing and get back to you.

Aaron

Aaron,

I dont know if this helps but the ECA OCSP responder has the following attributes:

Verisign

URL of OCSP Service http://eca-client-ocsp.verisign.com

Port for OCSP Service- 80

Model of Operation- Delegated Trust

Supported CAs- Verisign Client External Certification Authority, original and version G2

Would being a Delegated trust have anything to do with these type issues?

Aaron,

I have added in more debug (add in AUTH::subscribe along with AUTH::response_data). The following is now being displayed for the ECA Responder:

Feb 24 15:04:54 tmm tmm[1710]: Rule client_cert_request_by_uri_with_ocsp_checking : client IP:port=192.168.1.152:2671; VIP=test_vs: [AUTH::response_data]: ocsp:response:status unknown;

AUTH::status = 1;l

Aaron,

I think we has an issue/bug. It appears as though the second responder is not being checked (based on status returned). What is happening is that the ECA cert is being tried on the DoD responder (apparently the responders are choosen in alpha order). It is making a successful connection but returned an error of unknown certificate. As a result, ECA responder is not being tried.

Is there a way for me to test the cert being presented and then denote which responder to send it too?

Is there a way, if a status of unknown is returned, to initiate the second responder? somehow change the status as if the first was not reachable?

It appears to me as though the multiple responder concept is for multiple IP’s of the same type cert.

You seem to be the top resource for this type of stuff. Any ideas?

Aaron,

Last post for the evening. When the first responder cannot be reached, the second responder is not tried.

Feb 24 23:00:18 tmm tmm[1710]: Rule client_cert_request_by_uri_with_ocsp_checking : client IP:port=192.168.1.154:56480; VIP=test_vs: [AUTH::response_data]: ocsp:response:status {Error (Could not connect to server)} ocsp:response:status unauthorized;

Is there a way to have the iRule always check the second responder unless the first returns a 0 or success.

I’d guess that the DoD client certs need to be checked against the OCSP server and the Verisign client certs need to be checked against the Verisign OCSP server. There are two options I can think of for handling this:

1. On the OCSP servers VIP, add an iRule which checks the request and selects the OCSP pool member based on the request. I think this is probably the simplest and most efficient option. But I’d need to set this up and test to see how easily it would be to determine which CA’s client cert is being checked based on the OCSP request.

You can check RFC2560 sections 2.1 and 4.1.1 and/or capture tcpdumps of the OCSP requests to see what in the requests could be used to differentiate the DoD and Verisign requests.

2. Configure two separate auth profiles--one for each OCSP responder. As you don’t know which client cert the client will present until the SSL handshake is done, I think you’d need to use three iRules for this: one to handle the cert requesting and then another each to handle the auth depending on which client cert is provided. I think this would be complicated with three rules.

3. On the OCSP servers VIP, add an iRule which tries each OCSP server until a successful response is received or there are no more OCSP servers to make the request to. Doing this would be inefficient as you’d potentially be making two side band requests to a remote server for each authentication attempt.

Note, the default action for load balancing (if you’re testing with the OCSP servers VIP and pool) is to select one pool member for each connection. By default LTM doesn’t try multiple pool members for one client request. Or are you testing with multiple responders configured and not a single VIP pointing to the responders? If so, LTM will use the responders in alphabetical order. This is described in SOL7746. I’m not sure what criteria LTM uses to determine when to check another responder. It might just be if a TCP connection can’t be established to the prior responder.

SOL7746: Ordering Online Certificate Status Protocol (OCSP) responders in the SSL OCSP profile

I am a bit swamped this week, so I don’t think I’m going to have time to test this. I can try later next week though. Else, if you try any of these options and run into issues, let me know.

Thanks,

Aaron

Aaron, you are correct. When a DoD cert is presented, I want to use the DoD Reponder. When a Verisign ECA is presented, I want to use the ECA responder.

I am using one VIP (one virtual server) with multiple responders in an OCSP configuration. Just like your test scenario.

Option 1 is what I am trying to figure out but am getting no where. I do believe we have the knowledge on this end to figure out which cert is incoming. I would just need to know how to control which responder is called. It sounds to me like we are now breaking the responders out into there own configs and calling them from a different place. if you can place some breadcrumbs, I might be able to follow.