Does cached SSL session hold previous X.509 certificate info?

228 Views Asked by At

When we re-use previously saved SSL_SESSION, does the reused SSL session have orignal X.509 peer certificate?

My code crashes very infrequently and investigation showed that the SSL session is reused and the some fields of peer cert(certinfo->key->pkey) are messed up.

  • 1st Handshake from CLT to SVR.

    SVR sends X.509 certificate to CLT and CLT stores the cert. We can get the cert using SSL_get_peer_certificate(). CLT saves the SSL_SESSION with SSL_get1_session().

  • 2nd Handshake from CLT to SVR.

    This time CLT offers saved SSL_SESSION with SSL_set_session() and abbreviated handshake occured. When CLT calls SSL_get_peer_certificate(), can CLT get the original X.509 cert?

It seems that coupling with SSL_SESSION and included peer X.509 cert is loose. Should we save X.509 peer cert with upping refcnt explicitly, in addition to calling SSL_get1_session just, to properly use SSL_get_peer_certificate() on reused SSL_SESSION?

I use LibreSSL and OpenSSL on Linux.

Any comments would be appreciated deeply.

1

There are 1 best solutions below

0
On

If you see openssl code you will find this comment, in declaration of SSL_SESSION, it says:

/* This is the cert for the other end.
 * On clients, it will be the same as sess_cert->peer_key->x509
 * (the latter is not enough as sess_cert is not retained
 * in the external representation of sessions, see ssl_asn1.c). */
X509 *peer;

I would assume it indicates for clients, peer certificate is not retained when converted to external representation ie when SSL_SESSION is serialised peer certificated will be lost