Merge tag 'release_3_0_10' into tr-integ
[freeradius.git] / src / main / tls.c
index 80398a5..d86391f 100644 (file)
@@ -103,7 +103,7 @@ FR_NAME_NUMBER const fr_tls_status_table[] = {
 /* index we use to store cached session VPs
  * needs to be dynamic so we can supply a "free" function
  */
-static int fr_tls_ex_index_vps = -1;
+int fr_tls_ex_index_vps = -1;
 int fr_tls_ex_index_certs = -1;
 
 /* Session */
@@ -169,7 +169,7 @@ static unsigned int psk_server_callback(SSL *ssl, const char *identity,
                        return 0;
                }
 
-               vp = pairmake_packet("TLS-PSK-Identity", identity, T_OP_SET);
+               vp = pair_make_request("TLS-PSK-Identity", identity, T_OP_SET);
                if (!vp) return 0;
 
                hex_len = radius_xlat(buffer, sizeof(buffer), request, conf->psk_query,
@@ -313,7 +313,6 @@ tls_session_t *tls_new_client_session(TALLOC_CTX *ctx, fr_tls_server_conf_t *con
        return ssn;
 }
 
-
 /** Create a new TLS session
  *
  * Configures a new TLS session, configuring options, setting callbacks etc...
@@ -432,7 +431,7 @@ tls_session_t *tls_new_session(TALLOC_CTX *ctx, fr_tls_server_conf_t *conf, REQU
         *      just too much.
         */
        state->mtu = conf->fragment_size;
-       vp = pairfind(request->packet->vps, PW_FRAMED_MTU, 0, TAG_ANY);
+       vp = fr_pair_find_by_num(request->packet->vps, PW_FRAMED_MTU, 0, TAG_ANY);
        if (vp && (vp->vp_integer > 100) && (vp->vp_integer < state->mtu)) {
                state->mtu = vp->vp_integer;
        }
@@ -954,13 +953,13 @@ static CONF_PARSER cache_config[] = {
 
        { "max_entries", FR_CONF_OFFSET(PW_TYPE_INTEGER, fr_tls_server_conf_t, session_cache_size), "255" },
        { "persist_dir", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, session_cache_path), NULL },
-       { NULL, -1, 0, NULL, NULL }        /* end the list */
+       CONF_PARSER_TERMINATOR
 };
 
 static CONF_PARSER verify_config[] = {
        { "tmpdir", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, verify_tmp_dir), NULL },
        { "client", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, verify_client_cert_cmd), NULL },
-       { NULL, -1, 0, NULL, NULL }        /* end the list */
+       CONF_PARSER_TERMINATOR
 };
 
 #ifdef HAVE_OPENSSL_OCSP_H
@@ -971,7 +970,7 @@ static CONF_PARSER ocsp_config[] = {
        { "use_nonce", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, ocsp_use_nonce), "yes" },
        { "timeout", FR_CONF_OFFSET(PW_TYPE_INTEGER, fr_tls_server_conf_t, ocsp_timeout), "yes" },
        { "softfail", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, ocsp_softfail), "no" },
-       { NULL, -1, 0, NULL, NULL }        /* end the list */
+       CONF_PARSER_TERMINATOR
 };
 #endif
 
@@ -999,6 +998,9 @@ static CONF_PARSER tls_server_config[] = {
        { "fragment_size", FR_CONF_OFFSET(PW_TYPE_INTEGER, fr_tls_server_conf_t, fragment_size), "1024" },
        { "include_length", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, include_length), "yes" },
        { "check_crl", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, check_crl), "no" },
+#ifdef X509_V_FLAG_CRL_CHECK_ALL
+       { "check_all_crl", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, check_all_crl), "no" },
+#endif
        { "allow_expired_crl", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, allow_expired_crl), NULL },
        { "check_cert_cn", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, check_cert_cn), NULL },
        { "cipher_list", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, cipher_list), NULL },
@@ -1030,8 +1032,7 @@ static CONF_PARSER tls_server_config[] = {
 #ifdef HAVE_OPENSSL_OCSP_H
        { "ocsp", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) ocsp_config },
 #endif
-
-       { NULL, -1, 0, NULL, NULL }        /* end the list */
+       CONF_PARSER_TERMINATOR
 };
 
 
@@ -1073,8 +1074,7 @@ static CONF_PARSER tls_client_config[] = {
 #ifdef SSL_OP_NO_TLSv1_2
        { "disable_tlsv1_2", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, fr_tls_server_conf_t, disable_tlsv1_2), NULL },
 #endif
-
-       { NULL, -1, 0, NULL, NULL }        /* end the list */
+       CONF_PARSER_TERMINATOR
 };
 
 
@@ -1134,11 +1134,6 @@ static void cbtls_remove_session(SSL_CTX *ctx, SSL_SESSION *sess)
                return;
        }
 
-       if (!conf->session_cache_path) {
-               DEBUG(LOG_PREFIX ": Failed to find 'persist_dir' in TLS configuration.  Cannot remove any cached session.");
-               return;
-       }
-
        {
                int rv;
                char filename[256];
@@ -1174,12 +1169,7 @@ static int cbtls_new_session(SSL *ssl, SSL_SESSION *sess)
        conf = (fr_tls_server_conf_t *)SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_CONF);
        if (!conf) {
                RWDEBUG("Failed to find TLS configuration in session");
-               return NULL;
-       }
-
-       if (!conf->session_cache_path) {
-               RDEBUG("Failed to find 'persist_dir' in TLS configuration.  Session will not be cached.");
-               return NULL;
+               return 0;
        }
 
        size = sess->session_id_length;
@@ -1223,8 +1213,8 @@ static int cbtls_new_session(SSL *ssl, SSL_SESSION *sess)
                         conf->session_cache_path, FR_DIR_SEP, buffer);
                fd = open(filename, O_RDWR|O_CREAT|O_EXCL, 0600);
                if (fd < 0) {
-                       RWDEBUG("Session serialisation failed, failed opening session file %s: %s",
-                               filename, fr_syserror(errno));
+                       RERROR("Session serialisation failed, failed opening session file %s: %s",
+                             filename, fr_syserror(errno));
                        goto error;
                }
 
@@ -1280,11 +1270,6 @@ static SSL_SESSION *cbtls_get_session(SSL *ssl, unsigned char *data, int len, in
                return NULL;
        }
 
-       if (!conf->session_cache_path) {
-               RDEBUG("Failed to find 'persist_dir' in TLS configuration.  Session will not be cached.");
-               return NULL;
-       }
-
        talloc_ctx = SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_TALLOC);
 
        {
@@ -1350,7 +1335,7 @@ static SSL_SESSION *cbtls_get_session(SSL *ssl, unsigned char *data, int len, in
                }
 
                /* move the cached VPs into the session */
-               pairfilter(talloc_ctx, &vps, &pairlist->reply, 0, 0, TAG_ANY);
+               fr_pair_list_mcopy_by_num(talloc_ctx, &vps, &pairlist->reply, 0, 0, TAG_ANY);
 
                SSL_SESSION_set_ex_data(sess, fr_tls_ex_index_vps, vps);
                RWDEBUG("Successfully restored session %s", buffer);
@@ -1364,14 +1349,24 @@ err:
 }
 
 #ifdef HAVE_OPENSSL_OCSP_H
-/*
- * This function extracts the OCSP Responder URL
- * from an existing x509 certificate.
+
+/** Extract components of OCSP responser URL from a certificate
+ *
+ * @param[in] cert to extract URL from.
+ * @param[out] host_out Portion of the URL (must be freed with free()).
+ * @param[out] port_out Port portion of the URL (must be freed with free()).
+ * @param[out] path_out Path portion of the URL (must be freed with free()).
+ * @param[out] is_https Whether the responder should be contacted using https.
+ * @return
+ *     - 0 if no valid URL is contained in the certificate.
+ *     - 1 if a URL was found and parsed.
+ *     - -1 if at least one URL was found, but none could be parsed.
  */
-static int ocsp_parse_cert_url(X509 *cert, char **phost, char **pport,
-                              char **ppath, int *pssl)
+static int ocsp_parse_cert_url(X509 *cert, char **host_out, char **port_out,
+                              char **path_out, int *is_https)
 {
        int                     i;
+       bool                    found_uri = false;
 
        AUTHORITY_INFO_ACCESS   *aia;
        ACCESS_DESCRIPTION      *ad;
@@ -1380,15 +1375,14 @@ static int ocsp_parse_cert_url(X509 *cert, char **phost, char **pport,
 
        for (i = 0; i < sk_ACCESS_DESCRIPTION_num(aia); i++) {
                ad = sk_ACCESS_DESCRIPTION_value(aia, i);
-               if (OBJ_obj2nid(ad->method) == NID_ad_OCSP) {
-                       if (ad->location->type == GEN_URI) {
-                         if(OCSP_parse_url((char *) ad->location->d.ia5->data,
-                                                 phost, pport, ppath, pssl))
-                                       return 1;
-                       }
-               }
+               if (OBJ_obj2nid(ad->method) != NID_ad_OCSP) continue;
+               if (ad->location->type != GEN_URI) continue;
+               found_uri = true;
+
+               if (OCSP_parse_url((char *) ad->location->d.ia5->data, host_out,
+                                  port_out, path_out, is_https)) return 1;
        }
-       return 0;
+       return found_uri ? -1 : 0;
 }
 
 /*
@@ -1440,17 +1434,36 @@ static int ocsp_check(REQUEST *request, X509_STORE *store, X509 *issuer_cert, X5
        if (conf->ocsp_override_url) {
                char *url;
 
+       use_ocsp_url:
                memcpy(&url, &conf->ocsp_url, sizeof(url));
                /* Reading the libssl src, they do a strdup on the URL, so it could of been const *sigh* */
                OCSP_parse_url(url, &host, &port, &path, &use_ssl);
+               if (!host || !port || !path) {
+                       RWDEBUG("ocsp: Host or port or path missing from configured URL \"%s\".  Not doing OCSP", url);
+                       ocsp_ok = 2;
+                       goto ocsp_skip;
+               }
        } else {
-               ocsp_parse_cert_url(client_cert, &host, &port, &path, &use_ssl);
-       }
+               int ret;
 
-       if (!host || !port || !path) {
-               RWDEBUG("ocsp: Host / port / path missing.  Not doing OCSP");
-               ocsp_ok = 2;
-               goto ocsp_skip;
+               ret = ocsp_parse_cert_url(client_cert, &host, &port, &path, &use_ssl);
+               switch (ret) {
+               case -1:
+                       RWDEBUG("ocsp: Invalid URL in certificate.  Not doing OCSP");
+                       break;
+
+               case 0:
+                       if (conf->ocsp_url) {
+                               RWDEBUG("ocsp: No OCSP URL in certificate, falling back to configured URL");
+                               goto use_ocsp_url;
+                       }
+                       RWDEBUG("ocsp: No OCSP URL in certificate.  Not doing OCSP");
+                       ocsp_ok = 2;
+                       goto ocsp_skip;
+
+               case 1:
+                       break;
+               }
        }
 
        RDEBUG2("ocsp: Using responder URL \"http://%s:%s%s\"", host, port, path);
@@ -1772,7 +1785,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                        sprintf(p, "%02x", (unsigned int)sn->data[i]);
                        p += 2;
                }
-               vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_SERIAL][lookup], buf, T_OP_SET);
+               vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_SERIAL][lookup], buf, T_OP_SET);
                rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
        }
 
@@ -1786,7 +1799,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
            (asn_time->length < (int) sizeof(buf))) {
                memcpy(buf, (char*) asn_time->data, asn_time->length);
                buf[asn_time->length] = '\0';
-               vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_EXPIRATION][lookup], buf, T_OP_SET);
+               vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_EXPIRATION][lookup], buf, T_OP_SET);
                rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
        }
 
@@ -1798,7 +1811,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                          sizeof(subject));
        subject[sizeof(subject) - 1] = '\0';
        if (certs && identity && (lookup <= 1) && subject[0]) {
-               vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_SUBJECT][lookup], subject, T_OP_SET);
+               vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_SUBJECT][lookup], subject, T_OP_SET);
                rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
        }
 
@@ -1806,7 +1819,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                          sizeof(issuer));
        issuer[sizeof(issuer) - 1] = '\0';
        if (certs && identity && (lookup <= 1) && issuer[0]) {
-               vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_ISSUER][lookup], issuer, T_OP_SET);
+               vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_ISSUER][lookup], issuer, T_OP_SET);
                rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
        }
 
@@ -1817,7 +1830,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                                  NID_commonName, common_name, sizeof(common_name));
        common_name[sizeof(common_name) - 1] = '\0';
        if (certs && identity && (lookup <= 1) && common_name[0] && subject[0]) {
-               vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_CN][lookup], common_name, T_OP_SET);
+               vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_CN][lookup], common_name, T_OP_SET);
                rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
        }
 
@@ -1838,14 +1851,14 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                                switch (name->type) {
 #ifdef GEN_EMAIL
                                case GEN_EMAIL:
-                                       vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_SAN_EMAIL][lookup],
+                                       vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_SAN_EMAIL][lookup],
                                                      (char *) ASN1_STRING_data(name->d.rfc822Name), T_OP_SET);
                                        rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
                                        break;
 #endif /* GEN_EMAIL */
 #ifdef GEN_DNS
                                case GEN_DNS:
-                                       vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_SAN_DNS][lookup],
+                                       vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_SAN_DNS][lookup],
                                                      (char *) ASN1_STRING_data(name->d.dNSName), T_OP_SET);
                                        rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
                                        break;
@@ -1856,7 +1869,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                                        if (NID_ms_upn == OBJ_obj2nid(name->d.otherName->type_id)) {
                                            /* we've got a UPN - Must be ASN1-encoded UTF8 string */
                                            if (name->d.otherName->value->type == V_ASN1_UTF8STRING) {
-                                                   vp = pairmake(talloc_ctx, certs, cert_attr_names[FR_TLS_SAN_UPN][lookup],
+                                                   vp = fr_pair_make(talloc_ctx, certs, cert_attr_names[FR_TLS_SAN_UPN][lookup],
                                                                  (char *) ASN1_STRING_data(name->d.otherName->value->value.utf8string), T_OP_SET);
                                                    rdebug_pair(L_DBG_LVL_2, request, vp, NULL);
                                                break;
@@ -1936,7 +1949,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
 
                        value[len] = '\0';
 
-                       vp = pairmake(talloc_ctx, certs, attribute, value, T_OP_ADD);
+                       vp = fr_pair_make(talloc_ctx, certs, attribute, value, T_OP_ADD);
                        if (!vp) {
                                RDEBUG3("Skipping %s += '%s'.  Please check that both the "
                                        "attribute and value are defined in the dictionaries",
@@ -2054,7 +2067,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                        }
                        fclose(fp);
 
-                       if (!pairmake_packet("TLS-Client-Cert-Filename",
+                       if (!pair_make_request("TLS-Client-Cert-Filename",
                                             filename, T_OP_SET)) {
                                RDEBUG("Failed creating TLS-Client-Cert-Filename");
 
@@ -2119,6 +2132,10 @@ static X509_STORE *init_revocation_store(fr_tls_server_conf_t *conf)
        if (conf->check_crl)
                X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK);
 #endif
+#ifdef X509_V_FLAG_CRL_CHECK_ALL
+       if (conf->check_all_crl)
+               X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK_ALL);
+#endif
        return store;
 }
 #endif /* HAVE_OPENSSL_OCSP_H */
@@ -2172,7 +2189,7 @@ static void sess_free_vps(UNUSED void *parent, void *data_ptr,
 
        DEBUG2(LOG_PREFIX ": Freeing cached session VPs");
 
-       pairfree(&vp);
+       fr_pair_list_free(&vp);
 }
 
 static void sess_free_certs(UNUSED void *parent, void *data_ptr,
@@ -2184,7 +2201,7 @@ static void sess_free_certs(UNUSED void *parent, void *data_ptr,
 
        DEBUG2(LOG_PREFIX ": Freeing cached session Certificates");
 
-       pairfree(certs);
+       fr_pair_list_free(certs);
 }
 
 /** Add all the default ciphers and message digests reate our context.
@@ -2580,9 +2597,14 @@ post_ca:
         *      Callbacks, etc. for session resumption.
         */
        if (conf->session_cache_enable) {
-               SSL_CTX_sess_set_new_cb(ctx, cbtls_new_session);
-               SSL_CTX_sess_set_get_cb(ctx, cbtls_get_session);
-               SSL_CTX_sess_set_remove_cb(ctx, cbtls_remove_session);
+               /*
+                *      Cache sessions on disk if requested.
+                */
+               if (conf->session_cache_path) {
+                       SSL_CTX_sess_set_new_cb(ctx, cbtls_new_session);
+                       SSL_CTX_sess_set_get_cb(ctx, cbtls_get_session);
+                       SSL_CTX_sess_set_remove_cb(ctx, cbtls_remove_session);
+               }
 
                SSL_CTX_set_quiet_shutdown(ctx, 1);
                if (fr_tls_ex_index_vps < 0)
@@ -2601,6 +2623,11 @@ post_ca:
                        return NULL;
                }
                X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK);
+
+#ifdef X509_V_FLAG_CRL_CHECK_ALL
+               if (conf->check_all_crl)
+                       X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK_ALL);
+#endif
        }
 #endif
 
@@ -2865,7 +2892,7 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
         *      user.
         */
        if ((!ssn->allow_session_resumption) ||
-           (((vp = pairfind(request->config, PW_ALLOW_SESSION_RESUMPTION, 0, TAG_ANY)) != NULL) &&
+           (((vp = fr_pair_find_by_num(request->config, PW_ALLOW_SESSION_RESUMPTION, 0, TAG_ANY)) != NULL) &&
             (vp->vp_integer == 0))) {
                SSL_CTX_remove_session(ssn->ctx,
                                       ssn->ssl->session);
@@ -2894,20 +2921,20 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
 
                fr_bin2hex(buffer, ssn->ssl->session->session_id, size);
 
-               vp = paircopy_by_num(talloc_ctx, request->reply->vps, PW_USER_NAME, 0, TAG_ANY);
-               if (vp) pairadd(&vps, vp);
+               vp = fr_pair_list_copy_by_num(talloc_ctx, request->reply->vps, PW_USER_NAME, 0, TAG_ANY);
+               if (vp) fr_pair_add(&vps, vp);
 
-               vp = paircopy_by_num(talloc_ctx, request->packet->vps, PW_STRIPPED_USER_NAME, 0, TAG_ANY);
-               if (vp) pairadd(&vps, vp);
+               vp = fr_pair_list_copy_by_num(talloc_ctx, request->packet->vps, PW_STRIPPED_USER_NAME, 0, TAG_ANY);
+               if (vp) fr_pair_add(&vps, vp);
 
-               vp = paircopy_by_num(talloc_ctx, request->packet->vps, PW_STRIPPED_USER_DOMAIN, 0, TAG_ANY);
-               if (vp) pairadd(&vps, vp);
+               vp = fr_pair_list_copy_by_num(talloc_ctx, request->packet->vps, PW_STRIPPED_USER_DOMAIN, 0, TAG_ANY);
+               if (vp) fr_pair_add(&vps, vp);
 
-               vp = paircopy_by_num(talloc_ctx, request->reply->vps, PW_CHARGEABLE_USER_IDENTITY, 0, TAG_ANY);
-               if (vp) pairadd(&vps, vp);
+               vp = fr_pair_list_copy_by_num(talloc_ctx, request->reply->vps, PW_CHARGEABLE_USER_IDENTITY, 0, TAG_ANY);
+               if (vp) fr_pair_add(&vps, vp);
 
-               vp = paircopy_by_num(talloc_ctx, request->reply->vps, PW_CACHED_SESSION_POLICY, 0, TAG_ANY);
-               if (vp) pairadd(&vps, vp);
+               vp = fr_pair_list_copy_by_num(talloc_ctx, request->reply->vps, PW_CACHED_SESSION_POLICY, 0, TAG_ANY);
+               if (vp) fr_pair_add(&vps, vp);
 
                certs = (VALUE_PAIR **)SSL_get_ex_data(ssn->ssl, fr_tls_ex_index_certs);
 
@@ -2919,22 +2946,24 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
                         *      @todo: some go into reply, others into
                         *      request
                         */
-                       pairadd(&vps, paircopy(talloc_ctx, *certs));
+                       fr_pair_add(&vps, fr_pair_list_copy(talloc_ctx, *certs));
 
                        /*
                         *      Save the certs in the packet, so that we can see them.
                         */
-                       pairadd(&request->packet->vps, paircopy(request->packet, *certs));
+                       fr_pair_add(&request->packet->vps, fr_pair_list_copy(request->packet, *certs));
                }
 
                if (vps) {
                        SSL_SESSION_set_ex_data(ssn->ssl->session, fr_tls_ex_index_vps, vps);
+                       rdebug_pair_list(L_DBG_LVL_2, request, vps, "  caching ");
+
                        if (conf->session_cache_path) {
                                /* write the VPs to the cache file */
                                char filename[256], buf[1024];
                                FILE *vp_file;
 
-                               RDEBUG2("Saving session %s in the cache", buffer);
+                               RDEBUG2("Saving session %s in the disk cache", buffer);
 
                                snprintf(filename, sizeof(filename), "%s%c%s.vps", conf->session_cache_path,
                                         FR_DIR_SEP, buffer);
@@ -2972,7 +3001,7 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
                                        fclose(vp_file);
                                }
                        } else {
-                               RDEBUG("Failed to find 'persist_dir' in TLS configuration.  Session will not be cached.");
+                               RDEBUG("Failed to find 'persist_dir' in TLS configuration.  Session will not be cached on disk.");
                        }
                } else {
                        RDEBUG2("No information to cache: session caching will be disabled for session %s", buffer);
@@ -2984,7 +3013,6 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
         */
        } else {
                size_t size;
-               vp_cursor_t cursor;
                char buffer[2 * MAX_SESSION_SIZE + 1];
 
                size = ssn->ssl->session->session_id_length;
@@ -2992,40 +3020,10 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
 
                fr_bin2hex(buffer, ssn->ssl->session->session_id, size);
 
-               vps = SSL_SESSION_get_ex_data(ssn->ssl->session, fr_tls_ex_index_vps);
-               if (!vps) {
-                       RWDEBUG("No information in cached session %s", buffer);
-                       return -1;
-               }
-
-               RDEBUG("Adding cached attributes from session %s", buffer);
-
                /*
-                *      The cbtls_get_session() function doesn't have
-                *      access to sock->certs or handler->certs, which
-                *      is where the certificates normally live.  So
-                *      the certs are all in the VPS list here, and
-                *      have to be manually extracted.
+                *      The "restore VPs from OpenSSL cache" code is
+                *      now in eaptls_process()
                 */
-               RINDENT();
-               for (vp = fr_cursor_init(&cursor, &vps);
-                    vp;
-                    vp = fr_cursor_next(&cursor)) {
-                       /*
-                        *      TLS-* attrs get added back to
-                        *      the request list.
-                        */
-                       if ((vp->da->vendor == 0) &&
-                           (vp->da->attr >= PW_TLS_CERT_SERIAL) &&
-                           (vp->da->attr <= PW_TLS_CLIENT_CERT_SUBJECT_ALT_NAME_UPN)) {
-                               rdebug_pair(L_DBG_LVL_2, request, vp, "request:");
-                               pairadd(&request->packet->vps, paircopyvp(request->packet, vp));
-                       } else {
-                               rdebug_pair(L_DBG_LVL_2, request, vp, "reply:");
-                               pairadd(&request->reply->vps, paircopyvp(request->reply, vp));
-                       }
-               }
-               REXDENT();
 
                if (conf->session_cache_path) {
                        /* "touch" the cached session/vp file */
@@ -3042,7 +3040,7 @@ int tls_success(tls_session_t *ssn, REQUEST *request)
                /*
                 *      Mark the request as resumed.
                 */
-               pairmake_packet("EAP-Session-Resumed", "1", T_OP_SET);
+               pair_make_request("EAP-Session-Resumed", "1", T_OP_SET);
        }
 
        return 0;
@@ -3126,7 +3124,7 @@ fr_tls_status_t tls_application_data(tls_session_t *ssn, REQUEST *request)
         */
        certs = (VALUE_PAIR **)SSL_get_ex_data(ssn->ssl, fr_tls_ex_index_certs);
 
-       if (certs) pairadd(&request->packet->vps, paircopy(request->packet, *certs));
+       if (certs) fr_pair_add(&request->packet->vps, fr_pair_list_copy(request->packet, *certs));
 
        return FR_TLS_OK;
 }