After connecting to the server you can get the certificate verification result via
SSL_get_verify_result()
see man page.
Afterwards you can get the associated session for a connection via SSL_get_session()
man page and remove it from the session cache via SSL_CTX_remove_session()
.
This will not cancel each connection which is using this session, but it will ensure that no new connection is reusing the old (invalidated and removed) session. To close the connection use SSL_shutdown()
.
Do not forget to add OCSP and CRL checks to your code.
If you really want to track used sessions, one way would be to include your own session handling callbacks see Documentation for Session handling and keep track of the SSL
objects which need to be terminated.
EDIT after comment:
this code should allow you to recheck the certificate anytime, and recheck the CRL-status.
X509_CRL *crl;
/* load crl */
FILE *fp = fopen(/*path to crl */, "r");
d2i_X509_CRL_fp(dp, &crl);
X509 *cert = SSL_get_peer_certificate(ssl); //ssl is your running connection
X509_STORE *store = SSL_CTX_get_cert_store(ctx);
/* add crls */
X509_STORE_add_crl(store, crl);
X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
X509_STORE_set1_param(store, param);
X509_STORE_CTX *csc = X509_STORE_CTX_new();
X509_STORE_CTX_set_verify_cb(csc, /* your verify callback here */);
X509_STORE_init(csc, store, cert, NULL);
int ret = X509_verify_cert(csc);