# insert ssl client cert info to HTTP header

**URL:** <https://community.f5.com/t/insert-ssl-client-cert-info-to-http-header/3444>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [June 15, 2005, 6:00am UTC](https://community.f5.com/t/insert-ssl-client-cert-info-to-http-header/3444 "2005-06-15T06:00:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Billy\_chuang\_16](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Billy\_chuang\_16](https://community.f5.com/u/Billy_chuang_16)\
**Post date:** [June 15, 2005, 6:00am UTC](https://community.f5.com/t/insert-ssl-client-cert-info-to-http-header/3444/1 "2005-06-15T06:00:48Z")

</div>

Hi,

in version 4.5, there is a easy to way to insert Client Cert info to HTTP header, how should the iRule write to achieve this features ? I checked the example in devcentral that confuse me how the SSL and x509 command work together.

Thanks

Billy

---

<div class="post-metadata">

**Author:** ![Billy\_chuang\_16](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Billy\_chuang\_16](https://community.f5.com/u/Billy_chuang_16)\
**Post date:** [June 20, 2005, 10:43am UTC](https://community.f5.com/t/insert-ssl-client-cert-info-to-http-header/3444/2 "2005-06-20T10:43:34Z")

</div>

any one can help ?

Billy

---

<div class="post-metadata">

**Author:** ![unRuleY\_95363](https://avatars.discourse-cdn.com/v4/letter/u/58f4c7/32.png) [@unRuleY\_95363](https://community.f5.com/u/unRuleY_95363)\
**Post date:** [June 21, 2005, 12:06am UTC](https://community.f5.com/t/insert-ssl-client-cert-info-to-http-header/3444/3 "2005-06-21T00:06:44Z")

</div>

The following rule might work depending on how you have ssl configured:

```tcl
when CLIENTSSL_CLIENTCERT { 
    set cert [X509::verify_cert_error_string [SSL::verify_result]] 
 } 
 when HTTP_REQUEST { 
    if { [info exists cert] } { 
       HTTP::header insert ClientCert $cert 
    } 
 }

```

However, we have noticed that some browsers (MSIE) only send the cert on one of the connections and open several sessions and thus the cert is not available on all the connections. The following rule handles that case by using an encrypted cookie to pass the cert header.

```tcl
when RULE_INIT { 
    set ::key [AES::key 128] 
 } 
  
 when CLIENTSSL_CLIENTCERT { 
    session add ssl [SSL::sessionid] [X509::verify_cert_error_string [SSL::verify_result]] 180 
 } 
  
 when HTTP_REQUEST { 
    set id [SSL::sessionid] 
    set y [session lookup ssl $id] 
    if { $y ne "" } { 
       set z [b64encode [AES::encrypt $::key $y]] 
       session delete ssl $id 
    } elseif { [HTTP::cookie exists ClientZ] } { 
       HTTP::header insert ClientCert [AES::decrypt $::key [b64decode [HTTP::cookie ClientZ]]] 
    } else { 
       set z [b64encode [AES::encrypt $::key none]] 
    } 
 } 
  
 when HTTP_RESPONSE { 
    if { [info exists z] } { 
      HTTP::header insert "Set-Cookie ClientZ=$z" 
    } 
 }

```
