Greetings! I have a request from a developer (below). I was hoping one of you could please help me come up with a solution?
---------------
The F5 needs to generate an SHA1 thumbprint of the incoming SSL certificate and add the output hexadecimal encoded string as a new HTTP header to be passed along to the application. The generated thumbprint is a standard SHA1 thumbprint for identification purposes.
Nice work as always Nitass. You might want to also remove any pre-existing SSLClientCertSubject and ClientCert-Thumbprint headers before inserting the new values to prevent a malicious user from injecting their own headers.
So the devs said that Nitass’s iRule didn’t look familiar to them. Familiar? I asked what they were expecting and they said there might be an existing iRule on one of the F5’s. So I dug around and found the one below. They said that this is the one they needed. So what exactly is the difference?
Hoolio, the devs just asked about your concern about “preventing a malicious user from injecting their own headers”. Could someone please post the complete iRule that will 1) insert the cert subject 2) insert the thumbprint and 3) remove pre-existing headers? I’m starting to understand iRules now but not sure the order in which to plug things in. Thanks!
HTTP::header replace will only affect the last header instance so an attacker could still inject a header by setting more than one. I put in a feature request to create an ‘HTTP::header replace-all $name $value’ command which would replace all existing $name headers with one new value.
For now, if you want to guarantee that no client set headers are included in the proxied request to the server, you can do this:
X509::hash will return the md5 hash of the binary cert. sha1 will return the sha1 hash.
Also, a client can resume an existing SSL session and not present the client cert in a new handshake for every TCP connection or HTTP request. TMM automatically stores the cert for the life of the SSL session and makes it accessible using [SSL::cert 0]. So it’s better to get the value on each HTTP request instead of storing it in a local variable which is specific to that one TCP connection.
Long story short…the last example I posted should work for your scenario.
Hoolio, I ran your iRule accross the dev guys one last time to confirm they were good with it. They came back with the following question:
So long as “binary scan [sha1 [SSL::cert 0]] H* cert_hex” gives us the thumbprint out of the certificate and not a SHA1 hash generated across the bytes of the presented certificate…then yes.
Just wanted to post an update. Hoolio’s iRule made it through test, QA, and is now in production. It takes the SHA1 thumbprint of the incoming SSL cert, converts it to hex, and inserts it into the header. It also takes the cert subject of the incoming SSL cert and inserts it into the header. Lastly, it scrubs any pre-existing headers before inserting the new ones as an extra measure of security. Thanks again Hoolio, and thanks to everyone else who pitched in. Here is the iRule again in final form:
Actually, you might want to remove the cert headers regardless of whether the client presented a cert for the SSL session to prevent a client from injecting their own headers.