Merge tag 'release_3_0_14' into tr-integ
authorDan Breslau <dbreslau@painless-security.com>
Mon, 5 Jun 2017 20:58:36 +0000 (16:58 -0400)
committerDan Breslau <dbreslau@painless-security.com>
Mon, 5 Jun 2017 20:58:36 +0000 (16:58 -0400)
1  2 
debian/changelog
raddb/sites-available/abfab-tr-idp
raddb/sites-available/inner-tunnel
redhat/freeradius.spec-renamed
src/main/tls.c
suse/freeradius.spec-renamed

diff --combined debian/changelog
@@@ -1,33 -1,9 +1,39 @@@
+ freeradius (3.0.14+git) unstable; urgency=medium
+   * New upstream version.
+  -- Alan DeKok <aland@freeradius.org>  Tue, 07 Mar 2017 12:00:00 -0400
 +freeradius (3.0.13+moonshot3-6) unstable; urgency=medium
 +
 +  * Disabled session caching in EAP in response to CVE-2017-9148.
 +
 + -- Painless Security <build@painless-security.com>  Fri, 02 Jun 2017 15:29:00 -0400
 +
 +freeradius (3.0.13+moonshot3-5) unstable; urgency=medium
 +
 +  * Fixed deleted links when upgrading to 3.0.13 on debian/ubuntu
 +
 + -- Painless Security <build@painless-security.com>  Wed, 10 May 2017 21:26:00 -0400
 +
 +freeradius (3.0.13+moonshot3-4) unstable; urgency=medium
 +
 +  * Bumped version number
 +
 + -- Painless Security <build@painless-security.com>  Tue, 09 May 2017 15:00:00 -0400
 +
 +freeradius (3.0.13+moonshot3-3) unstable; urgency=medium
 +
 +  * Removed some leftover cruft from debian/freeradius-postgresql.postinst
 +
 + -- Painless Security <build@painless-security.com>  Mon, 08 May 2017 21:44:00 -0400
 +
 +freeradius (3.0.13+moonshot3-2) unstable; urgency=medium
 +
 +  * Standard freeradius 3.0.13 + Painless Security signing key.
 +
 + -- Painless Security <build@painless-security.com>  Fri, 05 May 2017 18:24:00 -0400
 +
  freeradius (3.0.13+git) unstable; urgency=medium
  
    * New upstream version.
@@@ -12,7 -12,7 +12,7 @@@
  
  server abfab-idp {
  authorize {
 -        psk_authorize
 +      psk_authorize
        abfab_client_check
        filter_username
        preprocess
@@@ -30,9 -30,9 +30,9 @@@
  #     cui
  
        suffix {
 -              updated = 1
 +              updated = 1
                noop = reject
 -        }
 +      }
        eap {
                ok = return
        }
@@@ -81,12 -81,6 +81,6 @@@ post-auth 
        -sql
  
        #
-       #  Instead of sending the query to the SQL server,
-       #  write it into a log file.
-       #
- #     sql_log
-       #
        #  Un-comment the following if you want to modify the user's object
        #  in LDAP after a successful login.
        #
        exec
        #  Remove reply message if the response contains an EAP-Message
        remove_reply_message_if_eap
 +
 +      # Uncomment to enable logging of certain Moonshot attributes. See
 +      # mods-available/moonshot_custom_linelog.
 +      # log_moonshot_authn_rp_proxy
 +
        #  Access-Reject packets are sent through the REJECT sub-section of the
        #  post-auth section.
        #
        #  'edir_account_policy_check = yes' in the ldap module configuration
        #
        Post-Auth-Type REJECT {
 +              # Uncomment to enable logging of certain Moonshot attributes. See
 +              # mods-available/moonshot_custom_linelog.
 +              # log_moonshot_authn_rp_proxy
 +
                # log failed authentications in SQL, too.
                -sql
                attr_filter.access_reject
                #  Remove reply message if the response contains an EAP-Message
                remove_reply_message_if_eap
        }
 +
 +      # Uncomment to enable logging of certain Moonshot attributes. See
 +      # mods-available/moonshot_custom_linelog.
 +      # log_moonshot_authn_rp_proxy
  }
  #
  #  When the server decides to proxy a request to a home server,
@@@ -302,12 -302,6 +302,6 @@@ post-auth 
        -sql
  
        #
-       #  Instead of sending the query to the SQL server,
-       #  write it into a log file.
-       #
- #     sql_log
-       #
        #  Un-comment the following if you have set
        #  'edir_account_policy_check = yes' in the ldap module sub-section of
        #  the 'modules' section.
  
        #
        #  Un-comment the following if you want to generate Moonshot (ABFAB) TargetedIds
-       #  IMPORTANT: This requires the UUID package to be installed!
+       #
+       #  IMPORTANT: This requires the UUID package to be installed, and a targeted_id_salt
+       #             to be configured.
+       #
+       #  This functionality also supports SQL backing. To use this functionality, enable
+       #  and configure the moonshot-targeted-ids SQL module in the mods-enabled directory.
+       #  Then remove the comments from the appropriate lines in each of the below
+       #  policies in the policy.d/moonshot-targeted-ids file.
        #
  #     moonshot_host_tid
  #     moonshot_realm_tid
                }
        }
  
 +      # Uncomment to enable logging of certain Moonshot attributes. See
 +      # mods-available/moonshot_custom_linelog.
 +      # log_moonshot_authn_idp
 +
        #
        #  Access-Reject packets are sent through the REJECT sub-section of the
        #  post-auth section.
        #  'edir_account_policy_check = yes' in the ldap module configuration
        #
        Post-Auth-Type REJECT {
 +              # Uncomment to enable logging of certain Moonshot attributes. See
 +              # mods-available/moonshot_custom_linelog.
 +              # log_moonshot_authn_idp
 +
                # log failed authentications in SQL, too.
                -sql
                attr_filter.access_reject
                        &Module-Failure-Message := &request:Module-Failure-Message
                }
        }
 +      # Uncomment to enable logging of certain Moonshot attributes. See
 +      # mods-available/moonshot_custom_linelog.
 +      # log_moonshot_authn_idp
  }
  
  #
@@@ -26,7 -26,7 +26,7 @@@
  
  Summary: High-performance and highly configurable free RADIUS server
  Name: freeradius
- Version: 3.0.13
+ Version: 3.0.14
  Release: 2%{?dist}
  License: GPLv2+ and LGPLv2+
  Group: System Environment/Daemons
@@@ -665,6 -665,8 +665,8 @@@ f
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/main/mysql/*
  %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/main/ndb
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/main/ndb/*
+ %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/moonshot-targeted-ids/mysql
+ %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/moonshot-targeted-ids/mysql/*
  # postgres
  %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/counter/postgresql
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/counter/postgresql/*
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/ippool/postgresql/*
  %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/main/postgresql
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/main/postgresql/*
+ %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/moonshot-targeted-ids/postgresql
+ %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/moonshot-targeted-ids/postgresql/*
  # sqlite
  %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/counter/sqlite
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/counter/sqlite/*
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/ippool/sqlite/*
  %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/main/sqlite
  %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/main/sqlite/*
+ %dir %attr(750,root,radiusd) /etc/raddb/mods-config/sql/moonshot-targeted-ids/sqlite
+ %attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-config/sql/moonshot-targeted-ids/sqlite/*
  # ruby
  %if %{?_with_rlm_ruby:1}%{!?_with_rlm_ruby:0}
  %dir %attr(750,root,radiusd) /etc/raddb/mods-config/ruby
diff --combined src/main/tls.c
@@@ -505,6 -505,7 +505,7 @@@ tls_session_t *tls_new_client_session(T
        talloc_set_destructor(ssn, _tls_session_free);
  
        ssn->ctx = conf->ctx;
+       ssn->mtu = conf->fragment_size;
  
        SSL_CTX_set_mode(ssn->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | SSL_MODE_AUTO_RETRY);
  
        SSL_set_ex_data(ssn->ssl, FR_TLS_EX_INDEX_SSN, (void *)ssn);
        SSL_set_fd(ssn->ssl, fd);
        ret = SSL_connect(ssn->ssl);
+       if (ret < 0) {
+               switch (SSL_get_error(ssn->ssl, ret)) {
+                       default:
+                               break;
+               case SSL_ERROR_WANT_READ:
+               case SSL_ERROR_WANT_WRITE:
+                       ssn->connected = false;
+                       return ssn;
+               }
+       }
        if (ret <= 0) {
                tls_error_io_log(NULL, ssn, ret, "Failed in " STRINGIFY(__FUNCTION__) " (SSL_connect)");
                talloc_free(ssn);
                return NULL;
        }
  
-       ssn->mtu = conf->fragment_size;
+       ssn->connected = true;
        return ssn;
  }
  
 -
  /** Create a new TLS session
   *
   * Configures a new TLS session, configuring options, setting callbacks etc...
@@@ -822,10 -838,10 +837,10 @@@ static void session_init(tls_session_t 
  
  static void session_close(tls_session_t *ssn)
  {
-       SSL_set_quiet_shutdown(ssn->ssl, 1);
-       SSL_shutdown(ssn->ssl);
        if (ssn->ssl) {
+               SSL_set_quiet_shutdown(ssn->ssl, 1);
+               SSL_shutdown(ssn->ssl);
                SSL_free(ssn->ssl);
                ssn->ssl = NULL;
        }
@@@ -1359,7 -1375,7 +1374,7 @@@ static int cbtls_new_session(SSL *ssl, 
                blob_len = i2d_SSL_SESSION(sess, NULL);
                if (blob_len < 1) {
                        /* something went wrong */
-                       RWDEBUG("Session serialisation failed, couldn't determine required buffer length");
+                       if (request) RWDEBUG("Session serialisation failed, couldn't determine required buffer length");
                        return 0;
                }
  
                p = sess_blob;
                rv = i2d_SSL_SESSION(sess, &p);
                if (rv != blob_len) {
-                       RWDEBUG("Session serialisation failed");
+                       if (request) RWDEBUG("Session serialisation failed");
                        goto error;
                }
  
                /* open output file */
                snprintf(filename, sizeof(filename), "%s%c%s.asn1",
                         conf->session_cache_path, FR_DIR_SEP, buffer);
-               fd = open(filename, O_RDWR|O_CREAT|O_EXCL, 0600);
+               fd = open(filename, O_RDWR|O_CREAT|O_EXCL, S_IWUSR);
                if (fd < 0) {
-                       RERROR("Session serialisation failed, failed opening session file %s: %s",
-                             filename, fr_syserror(errno));
+                       if (request) RERROR("Session serialisation failed, failed opening session file %s: %s",
+                                           filename, fr_syserror(errno));
                        goto error;
                }
  
                                fr_pair_value_strcpy(vp, filename);
                                fr_pair_add(&request->state, vp);
                        }
-                       (void) fchmod(fd, S_IWUSR);
                }
  
                todo = blob_len;
                while (todo > 0) {
                        rv = write(fd, p, todo);
                        if (rv < 1) {
-                               RWDEBUG("Failed writing session: %s", fr_syserror(errno));
+                               if (request) RWDEBUG("Failed writing session: %s", fr_syserror(errno));
                                close(fd);
                                goto error;
                        }
                        todo -= rv;
                }
                close(fd);
-               RWDEBUG("Wrote session %s to %s (%d bytes)", buffer, filename, blob_len);
+               if (request) RWDEBUG("Wrote session %s to %s (%d bytes)", buffer, filename, blob_len);
        }
  
  error:
        return 0;
  }
  
+ /** Convert OpenSSL's ASN1_TIME to an epoch time
+  *
+  * @param[out] out    Where to write the time_t.
+  * @param[in] asn1    The ASN1_TIME to convert.
+  * @return
+  *    - 0 success.
+  *    - -1 on failure.
+  */
+ static int ocsp_asn1time_to_epoch(time_t *out, char const *asn1)
+ {
+       struct          tm t;
+       char const      *p = asn1, *end = p + strlen(p);
+       memset(&t, 0, sizeof(t));
+       if ((end - p) <= 12) {
+               if ((end - p) < 2) {
+                       fr_strerror_printf("ASN1 date string too short, expected 2 additional bytes, got %zu bytes",
+                                          end - p);
+                       return -1;
+               }
+               t.tm_year = (*(p++) - '0') * 10;
+               t.tm_year += (*(p++) - '0');
+               if (t.tm_year < 70) t.tm_year += 100;
+       } else {
+               t.tm_year = (*(p++) - '0') * 1000;
+               t.tm_year += (*(p++) - '0') * 100;
+               t.tm_year += (*(p++) - '0') * 10;
+               t.tm_year += (*(p++) - '0');
+               t.tm_year -= 1900;
+       }
+       if ((end - p) < 10) {
+               fr_strerror_printf("ASN1 string too short, expected 10 additional bytes, got %zu bytes",
+                                  end - p);
+               return -1;
+       }
+       t.tm_mon = (*(p++) - '0') * 10;
+       t.tm_mon += (*(p++) - '0') - 1; // -1 since January is 0 not 1.
+       t.tm_mday = (*(p++) - '0') * 10;
+       t.tm_mday += (*(p++) - '0');
+       t.tm_hour = (*(p++) - '0') * 10;
+       t.tm_hour += (*(p++) - '0');
+       t.tm_min = (*(p++) - '0') * 10;
+       t.tm_min += (*(p++) - '0');
+       t.tm_sec = (*(p++) - '0') * 10;
+       t.tm_sec += (*(p++) - '0');
+       /* Apparently OpenSSL converts all timestamps to UTC? Maybe? */
+       *out = timegm(&t);
+       return 0;
+ }
  #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
  static SSL_SESSION *cbtls_get_session(SSL *ssl, unsigned char *data, int len, int *copy)
  #else
@@@ -1471,27 -1540,28 +1539,28 @@@ static SSL_SESSION *cbtls_get_session(S
  
                struct stat     st;
                VALUE_PAIR      *vps = NULL;
+               VALUE_PAIR      *vp;
  
                /* load the actual SSL session */
                snprintf(filename, sizeof(filename), "%s%c%s.asn1", conf->session_cache_path, FR_DIR_SEP, buffer);
                fd = open(filename, O_RDONLY);
                if (fd < 0) {
                        RWDEBUG("No persisted session file %s: %s", filename, fr_syserror(errno));
-                       goto err;
+                       goto error;
                }
  
                rv = fstat(fd, &st);
                if (rv < 0) {
                        RWDEBUG("Failed stating persisted session file %s: %s", filename, fr_syserror(errno));
                        close(fd);
-                       goto err;
+                       goto error;
                }
  
                sess_data = talloc_array(NULL, unsigned char, st.st_size);
                if (!sess_data) {
                        RWDEBUG("Failed allocating buffer for persisted session (%d bytes)", (int) st.st_size);
                        close(fd);
-                       goto err;
+                       goto error;
                }
  
                q = sess_data;
                        if (rv < 1) {
                                RWDEBUG("Failed reading persisted session: %s", fr_syserror(errno));
                                close(fd);
-                               goto err;
+                               goto error;
                        }
                        todo -= rv;
                        q += rv;
                sess = d2i_SSL_SESSION(NULL, o, st.st_size);
                if (!sess) {
                        RWDEBUG("Failed loading persisted session: %s", ERR_error_string(ERR_get_error(), NULL));
-                       goto err;
+                       goto error;
                }
  
                /* read in the cached VPs from the .vps file */
                if (rv < 0) {
                        /* not safe to un-persist a session w/o VPs */
                        RWDEBUG("Failed loading persisted VPs for session %s", buffer);
-                       goto err;
+                       SSL_SESSION_free(sess);
+                       goto error;
+               }
+               /*
+                *      Enforce client certificate expiration.
+                */
+               vp = fr_pair_find_by_num(pairlist->reply, PW_TLS_CLIENT_CERT_EXPIRATION, 0, TAG_ANY);
+               if (vp) {
+                       time_t expires;
+                       if (ocsp_asn1time_to_epoch(&expires, vp->vp_strvalue) < 0) {
+                               RDEBUG2("Failed getting certificate expiration, removing cache entry for session %s", buffer);
+                               SSL_SESSION_free(sess);
+                               goto error;
+                       }
+                       if (expires <= request->timestamp) {
+                               RDEBUG2("Certificate has expired, removing cache entry for session %s", buffer);
+                               SSL_SESSION_free(sess);
+                               goto error;
+                       }
+                       /*
+                        *      Account for Session-Timeout, if it's available.
+                        */
+                       vp = fr_pair_find_by_num(request->reply->vps, PW_SESSION_TIMEOUT, 0, TAG_ANY);
+                       if (vp) {
+                               if ((request->timestamp + vp->vp_integer) > expires) {
+                                       vp->vp_integer = expires - request->timestamp;
+                                       RWDEBUG2("Updating Session-Timeout to %u, due to impending certificate expiration",
+                                                vp->vp_integer);
+                               }
+                       }
                }
  
                /* move the cached VPs into the session */
                RWDEBUG("Successfully restored session %s", buffer);
                rdebug_pair_list(L_DBG_LVL_2, request, vps, "reply:");
        }
- err:
+ error:
        if (sess_data) talloc_free(sess_data);
        if (pairlist) pairlist_free(&pairlist);
  
@@@ -2059,7 -2162,7 +2161,7 @@@ int cbtls_verify(int ok, X509_STORE_CT
        /*
         *      Get the RFC822 Subject Alternative Name
         */
-       loc = X509_get_ext_by_NID(client_cert, NID_subject_alt_name, 0);
+       loc = X509_get_ext_by_NID(client_cert, NID_subject_alt_name, -1);
        if (certs && (lookup <= 1) && (loc >= 0)) {
                X509_EXTENSION *ext = NULL;
                GENERAL_NAMES *names = NULL;
        }
  
        if (lookup == 0) {
- #if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
                ext_list = X509_get0_extensions(client_cert);
  #else
                X509_CINF       *client_inf;
                                                true, true, EXEC_TIMEOUT) != 0) {
                                AUTH(LOG_PREFIX ": Certificate CN (%s) fails external verification!", common_name);
                                my_ok = 0;
-                       } else {
+                       } else  if (request) {
                                RDEBUG("Client certificate CN %s passed external validation", common_name);
                        }
  
@@@ -2435,6 -2539,38 +2538,38 @@@ static int set_ecdh_curve(SSL_CTX *ctx
  #endif
  #endif
  
+ /*
+  * DIE OPENSSL DIE DIE DIE
+  *
+  * What a palaver, just to free some data attached the
+  * session. We need to do this because the "remove" callback
+  * is called when refcount > 0 sometimes, if another thread
+  * is using the session
+  */
+ static void sess_free_vps(UNUSED void *parent, void *data_ptr,
+                                 UNUSED CRYPTO_EX_DATA *ad, UNUSED int idx,
+                                 UNUSED long argl, UNUSED void *argp)
+ {
+         VALUE_PAIR *vp = data_ptr;
+         if (!vp) return;
+         DEBUG2(LOG_PREFIX ": Freeing cached session VPs");
+         fr_pair_list_free(&vp);
+ }
+ static void sess_free_certs(UNUSED void *parent, void *data_ptr,
+                                 UNUSED CRYPTO_EX_DATA *ad, UNUSED int idx,
+                                 UNUSED long argl, UNUSED void *argp)
+ {
+         VALUE_PAIR **certs = data_ptr;
+         if (!certs) return;
+         DEBUG2(LOG_PREFIX ": Freeing cached session Certificates");
+         fr_pair_list_free(certs);
+ }
  /** Add all the default ciphers and message digests reate our context.
   *
   * This should be called exactly once from main, before reading the main config
@@@ -2450,7 -2586,7 +2585,7 @@@ void tls_global_init(void
        /*
         *      Initialize the index for the certificates.
         */
-       fr_tls_ex_index_certs = SSL_SESSION_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+       fr_tls_ex_index_certs = SSL_SESSION_get_ex_new_index(0, NULL, NULL, NULL, sess_free_certs);
  }
  
  #ifdef ENABLE_OPENSSL_VERSION_CHECK
@@@ -2867,7 -3003,7 +3002,7 @@@ post_ca
  
                SSL_CTX_set_quiet_shutdown(ctx, 1);
                if (fr_tls_ex_index_vps < 0)
-                       fr_tls_ex_index_vps = SSL_SESSION_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+                       fr_tls_ex_index_vps = SSL_SESSION_get_ex_new_index(0, NULL, NULL, NULL, sess_free_vps);
        }
  
        /*
                }
  
                /*
-                *      Cache it, and DON'T auto-clear it.
+                *      Cache it, DON'T auto-clear it, and disable the internal OpenSSL session cache.
                 */
-               SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER | SSL_SESS_CACHE_NO_AUTO_CLEAR);
+               SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER | SSL_SESS_CACHE_NO_AUTO_CLEAR | SSL_SESS_CACHE_NO_INTERNAL);
  
                SSL_CTX_set_session_id_context(ctx,
                                               (unsigned char *) conf->session_context_id,
@@@ -2984,7 -3120,7 +3119,7 @@@ static int _tls_server_conf_free(fr_tls
        return 0;
  }
  
static fr_tls_server_conf_t *tls_server_conf_alloc(TALLOC_CTX *ctx)
+ fr_tls_server_conf_t *tls_server_conf_alloc(TALLOC_CTX *ctx)
  {
        fr_tls_server_conf_t *conf;
  
@@@ -3026,14 -3162,29 +3161,29 @@@ fr_tls_server_conf_t *tls_server_conf_p
         */
        if (conf->fragment_size < 100) conf->fragment_size = 100;
  
-       if (!conf->private_key_file) {
-               ERROR(LOG_PREFIX ": TLS Server requires a private key file");
-               goto error;
-       }
+       /*
+        *      Only check for certificate things if we don't have a
+        *      PSK query.
+        */
+       if (conf->psk_identity) {
+               if (conf->private_key_file) {
+                       WARN(LOG_PREFIX ": Ignoring private key file due to psk_identity being used");
+               }
  
-       if (!conf->certificate_file) {
-               ERROR(LOG_PREFIX ": TLS Server requires a certificate file");
-               goto error;
+               if (conf->certificate_file) {
+                       WARN(LOG_PREFIX ": Ignoring certificate file due to psk_identity being used");
+               }
+       } else {
+               if (!conf->private_key_file) {
+                       ERROR(LOG_PREFIX ": TLS Server requires a private key file");
+                       goto error;
+               }
+               if (!conf->certificate_file) {
+                       ERROR(LOG_PREFIX ": TLS Server requires a certificate file");
+                       goto error;
+               }
        }
  
        /*
@@@ -3138,6 -3289,7 +3288,7 @@@ fr_tls_server_conf_t *tls_client_conf_p
        return conf;
  }
  
  int tls_success(tls_session_t *ssn, REQUEST *request)
  {
        VALUE_PAIR *vp, *vps = NULL;
                         *      Save the certs in the packet, so that we can see them.
                         */
                        fr_pair_add(&request->packet->vps, fr_pair_list_copy(request->packet, *certs));
+                       vp = fr_pair_find_by_num(request->packet->vps, PW_TLS_CLIENT_CERT_EXPIRATION, 0, TAG_ANY);
+                       if (vp) {
+                               time_t expires;
+                               if (ocsp_asn1time_to_epoch(&expires, vp->vp_strvalue) < 0) {
+                                       RDEBUG2("Failed getting certificate expiration, removing cache entry for session %s", buffer);
+                                       SSL_CTX_remove_session(ssn->ctx, ssn->ssl_session);
+                                       return -1;
+                               }
+                               if (expires <= request->timestamp) {
+                                       RDEBUG2("Certificate has expired, removing cache entry for session %s", buffer);
+                                       SSL_CTX_remove_session(ssn->ctx, ssn->ssl_session);
+                                       return -1;
+                               }
+                               /*
+                                *      Account for Session-Timeout, if it's available.
+                                */
+                               vp = fr_pair_find_by_num(request->reply->vps, PW_SESSION_TIMEOUT, 0, TAG_ANY);
+                               if (vp) {
+                                       if ((request->timestamp + vp->vp_integer) > expires) {
+                                               vp->vp_integer = expires - request->timestamp;
+                                               RWDEBUG2("Updating Session-Timeout to %u, due to impending certificate expiration",
+                                                        vp->vp_integer);
+                                       }
+                               }
+                       }
                }
  
                if (vps) {
@@@ -1,5 -1,5 +1,5 @@@
  Name:         freeradius-server
- Version: 3.0.13
+ Version: 3.0.14
  Release:      0
  License:      GPLv2 ; LGPLv2.1
  Group:        Productivity/Networking/Radius/Servers