# SSL cert verify TCL error?

**URL:** <https://community.f5.com/t/ssl-cert-verify-tcl-error/43719>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [April 6, 2005, 12:18am UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719 "2005-04-06T00:18:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TIm\_Maestas](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@TIm\_Maestas](https://community.f5.com/u/TIm_Maestas)\
**Post date:** [April 6, 2005, 12:18am UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719/1 "2005-04-06T00:18:20Z")

</div>

I have the following iRule:

when CLIENTSSL\_HANDSHAKE {

set cert [SSL::cert 0]

}

when HTTP\_REQUEST {

set stuff [X509::subject $cert]

if { [matchclass $stuff contains $::merlin] } {

use pool test-sun }

else { reject }

}

The merlin class contains things like [CN=validhost.company.com](http://CN=validhost.company.com). When a host comes in presenting a client certificate with a valid CN everything works fine. When a host comes in without a matching CN in the merlin class, they get a page cannot be displayed error in IE, which is also fine. However, when a client comes in by typing the IP in their browser, which results in a pop-up window because the IP doesn’t match the common name of the certificate, I get the following error logged to /var/log/ltm:

tmm tmm[5569]: 01220001:3: TCL error: Rule test - while executing "X509::subject $cert "

While this isn’t necessarily a bad thing (because they should be coming in via the correct URL and not get any pop-up errors) it makes me think I’ve writte my rule incorrectly or should have done this differently. Is there a better way to do what I’m doing?

---

<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:** [April 6, 2005, 12:28am UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719/2 "2005-04-06T00:28:11Z")

</div>

You may want to try adding this:

```tcl
when HTTP_REQUEST { 
    if { [info exists cert] } { 
       ... your existing rule stuff... 
    } else { 
       log "No Cert presented" 
       reject 
    } 
 }

```

Basically, you have to remember there is no guarantee the client presented a certificate before sending an HTTP request.

The “info exists” command is Tcl’s way of determining whether a variable has been previously set.

---

<div class="post-metadata">

**Author:** ![TIm\_Maestas](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@TIm\_Maestas](https://community.f5.com/u/TIm_Maestas)\
**Post date:** [April 6, 2005, 4:25am UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719/3 "2005-04-06T04:25:25Z")

</div>

That didn’t seem to work. My rule now looks like

when CLIENTSSL\_HANDSHAKE {

set cert [SSL::cert 0]

}

when HTTP\_REQUEST {

if { [info exists cert] } {

log local0. “cert variable is $cert”

set stuff [X509::subject $cert]

if { [matchclass $stuff contains $::merlin] } {

use pool test-sun }

else {

log local0. “Invalid Cert from [IP::client\_addr]”

reject

}

} else {

log local0. “No Cert Presented from [IP::client\_addr]”

reject

}

}

But I’m still getting the error when a client comes in via IP address (or any other way that requires them to click yes to the SSL warning pop-up dialogue). The log message seems to indicate that indeed the $cert variable is not being populated, but if that is the case why is that block of the rule getting executed at all?

Apr 5 21:19:25 tmm tmm[5569]: Rule test : cert variable is

Apr 5 21:19:25 tmm tmm[5569]: 01220001:3: TCL error: Rule test - while executing "X509::subject $cert "

Thanks.

---

<div class="post-metadata">

**Author:** ![bl0ndie\_127134](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@bl0ndie\_127134](https://community.f5.com/u/bl0ndie_127134)\
**Post date:** [April 6, 2005, 7:12am UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719/4 "2005-04-06T07:12:11Z")

</div>

How about something like this …

```tcl
when HTTP_REQUEST {   
       if {[SSL::cert count] == 0} {       
           reject   
       } else {   
           set subject [X509::subject [SSL::cert 0]]   
           if { [matchclass $subject contains $::merlin] } {   
              use pool test-sun    
           }   
       }   
   }

```

Alternatively you could modify your CLIENTSSL\_HANDSHAKE to look like this …

```tcl
when CLIENTSSL_HANDSHAKE {    
       if {[SSL::cert count] > 0} {       
           set cert [SSL::cert 0]   
       }    
   }

```

I am still a little baffled as to why “info exists” failed. I will do some testing tomorrow to try and find out why.

---

<div class="post-metadata">

**Author:** ![TIm\_Maestas](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@TIm\_Maestas](https://community.f5.com/u/TIm_Maestas)\
**Post date:** [April 6, 2005, 7:10pm UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719/5 "2005-04-06T19:10:43Z")

</div>

Ok so I realized my plan was flawed in that, as was pointed out to me above, a client will not present a cert on each and every http request. So, I began going down the road of tracking whether we have validated a cert using the session table. However, I seem to be doing something wrong just adding the session entry. The rule:

```tcl
when CLIENTSSL_CLIENTCERT { 
   set id [SSL::sessionid] 
   session add ssl $id [X509::verify_cert_error_string [SSL::verify_result]] 180 
 } 
 when HTTP_REQUEST {  
      if {[SSL::cert count] == 0} {      
          reject 
      } else { 
          set subject [X509::subject [SSL::cert 0]]  
          if { [matchclass $subject contains $::merlin] } {  
             use pool test-sun   
          }  
      }  
  }

```

..Generates the error:

Apr 6 12:01:39 tmm tmm[5569]: 01220001:3: TCL error: Rule test - Prerequisite operation not in progress (line 1) invoked from within “session add ssl $id [X509::verify\_cert\_error\_string [SSL::verify\_result]] 180”

..what is the prerequisite operation that is not in progress?

---

<div class="post-metadata">

**Author:** ![efftee\_26336](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@efftee\_26336](https://community.f5.com/u/efftee_26336)\
**Post date:** [May 25, 2006, 5:36pm UTC](https://community.f5.com/t/ssl-cert-verify-tcl-error/43719/6 "2006-05-25T17:36:28Z")

</div>

Hi there,

does anybody has a solution for this. I have the same problem.
