SSL_GET_CERTIFICATE(3ossl)
π SSL_GET_CERTIFICATE π
ok so bestie, this is the 3ossl page for SSL_get_certificate, SSL_get_privatekey β two lil functions that let you peek at the cert and key your TLS/SSL connection is literally using. no cap, super useful. let's get into it π
β¨ NAME β¨
SSL_get_certificate, SSL_get_privatekey β retrieve TLS/SSL certificate and private key π¦
πΈ SYNOPSIS πΈ
#include <openssl/ssl.h>
X509 *SSL_get_certificate(const SSL *s);
EVP_PKEY *SSL_get_privatekey(const SSL *s);
π DESCRIPTION π
π§ SSL_get_certificate()
So SSL_get_certificate() hands you back a pointer to an X509 object representing a certificate that's being used as the local peer's identity. like, your cert, the one you're showing off. main character energy fr π
Multiple certificates can be configured β for example, a server might have both RSA and ECDSA certificates. (iconic, honestly, having options.) The certificate which is returned by SSL_get_certificate() is determined as follows:
- π«Ά If it's called before certificate selection has occurred, it returns the most recently added certificate, or
NULLif no certificate has been added. - π«Ά After certificate selection has occurred, it returns the certificate which was selected during the handshake, or
NULLif no certificate was selected (for example, on a client where no client certificate is in use).
Certificate selection occurs during the handshake; therefore, the value returned by SSL_get_certificate() during any callback made during the handshake process will depend on whether that callback is made before or after certificate selection occurs. so like, timing matters, bestie β vibe check your callback position π
π the OCSP glow-up use case
A specific use for SSL_get_certificate() is inside a callback set via a call to SSL_CTX_set_tlsext_status_cb(3). This callback occurs after certificate selection, where it can be used to examine a server's chosen certificate β for example, for the purpose of identifying a certificate's OCSP responder URL so that an OCSP response can be obtained. literally so smart, obsessed π
π¦ SSL_get_privatekey()
SSL_get_privatekey() returns a pointer to the EVP_PKEY object corresponding to the certificate returned by SSL_get_certificate(), if any. the matching key to the cert, slay π
β RETURN VALUES β
These functions return pointers to their respective objects, or NULL if no such object is available. π
β οΈ Returned objects are owned by theSSLobject and should not be freed by users of these functions. do NOT free them, bestie, that's not your business, that's theSSLobject's business π
π₯ SEE ALSO π₯
π COPYRIGHT π
Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
ok that's the whole page, you ate that π
β¨ this was version 3.5.0, dated 2026-09-25 β mwah, go forth and read your certs responsibly, bestie ππ«Ά
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms