# SSL client certificate LDAP authenticate before authorizing

**URL:** <https://community.f5.com/t/ssl-client-certificate-ldap-authenticate-before-authorizing/63407>\
**Category:** Community CodeShare\
**Tags:** irules, devops, security, application-delivery\
**Created:** [March 18, 2015, 10:45pm UTC](https://community.f5.com/t/ssl-client-certificate-ldap-authenticate-before-authorizing/63407 "2015-03-18T22:45:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Earnhar](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Earnhar](https://community.f5.com/u/Michael_Earnhar)\
**Post date:** [March 18, 2015, 10:45pm UTC](https://community.f5.com/t/ssl-client-certificate-ldap-authenticate-before-authorizing/63407/1 "2015-03-18T22:45:14Z")

</div>

**Problem this snippet solves:**

This iRule is a modification to the system F5 supported sys\_auth\_ssl\_cc\_ldap rule to serialize the process of SSL CC authentication followed by LDAP authorization. The F5 supported iRule performs the LDAP query in parallel with the client certificate verification resulting in some unneeded LDAP queries. This edit simply moves the LDAP authorization to the [CLIENTSSL\_HANDSHAKE](https://devcentral.f5.com/Wiki/iRules.CLIENTSSL_HANDSHAKE.ashx) event.

## Dependencies

This iRule depends upon a licensed feature (Client Authentication) and specifically the SSL Client Certificate LDAP Authentication.

**Code :**

```auto
rule ssl_cc_ldap_authenticate_before_authorize {
   when CLIENT_ACCEPTED {
        set tmm_auth_ssl_cc_ldap_sid 0
        set tmm_auth_ssl_cc_ldap_done 0
    }
    when CLIENTSSL_HANDSHAKE {
        if {$tmm_auth_ssl_cc_ldap_sid == 0} {
            set tmm_auth_ssl_cc_ldap_sid [AUTH::start pam default_ssl_cc_ldap]
            if {[info exists tmm_auth_subscription]} {
                AUTH::subscribe $tmm_auth_ssl_cc_ldap_sid
            }
        }
        AUTH::cert_credential $tmm_auth_ssl_cc_ldap_sid [SSL::cert 0]
        AUTH::authenticate $tmm_auth_ssl_cc_ldap_sid
    }
    when AUTH_RESULT {
        if {[info exists tmm_auth_ssl_cc_ldap_sid] and ($tmm_auth_ssl_cc_ldap_sid == [AUTH::last_event_session_id])} {
            set tmm_auth_status [AUTH::status]
            if {$tmm_auth_status == 0} {
                set tmm_auth_ssl_cc_ldap_done 1
                SSL::handshake resume
            } elseif {$tmm_auth_status != -1 || $tmm_auth_ssl_cc_ldap_done == 0} {
                reject
            }
        }
    }
}

```
