How to get a certificate from SSL_CTX?

I used SSL_CTX_use_certificate( SSL_CTX *ctx, X509 *x )to store the certificate SSL_CTX *ctx.

It is stored in the object SSL_CTXinctx->cert->key->x509

Is there any API to return from SSL_CTX?

+4
source share
1 answer

X509 *SSL_get_peer_certificate(const SSL *ssl); SSL_get_peer_certificate () returns a pointer to the X509 certificate provided by the partner.

X509 *SSL_get_certificate(const SSL *ssl); The function returns an X.509 type pointer to a certificate loaded into the SSL structure.

The definition above is simple, as you mentioned in your answer

X509 *SSL_get_certificate(const SSL *s)
{
    if (s->cert != NULL)
        return(s->cert->key->x509);
    else
        return(NULL);
}

Below is a link for more information. https://www.openssl.org/docs/manmaster/ssl/ssl.html

+1
source

Source: https://habr.com/ru/post/1650920/