SSL_GET_CERTIFICATE(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

✨ NAME ✨

okay so bestie, welcome to SSL_GET_CERTIFICATE(3ossl) β€” the manual page for SSL_get_certificate and SSL_get_privatekey, aka the little duo that lets you retrieve the TLS/SSL certificate and private key. no cap, this is the whole vibe. πŸ’…

🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

X509 *SSL_get_certificate(const SSL *s);
EVP_PKEY *SSL_get_privatekey(const SSL *s);

πŸ¦‹ DESCRIPTION πŸ¦‹

SSL_get_certificate() returns a pointer to an X509 object representing a certificate used as the local peer's identity. iconic. πŸ’–

Multiple certificates can be configured β€” for example, a server might have both RSA and ECDSA certificates. The certificate which is returned by SSL_get_certificate() is determined as follows:

  • If it is called before certificate selection has occurred, it returns the most recently added certificate, or NULL if no certificate has been added.
  • After certificate selection has occurred, it returns the certificate which was selected during the handshake, or NULL if no certificate was selected (for example, on a client where no client certificate is in use).
heads up bestie: 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. it's giving β€œtiming matters,” fr fr. 😭

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. lowkey iconic detective energy. πŸ”₯

SSL_get_privatekey() returns a pointer to the EVP_PKEY object corresponding to the certificate returned by SSL_get_certificate(), if any. matching set, slay. πŸŽ€

πŸŽ€ RETURN VALUES πŸŽ€

These functions return pointers to their respective objects, or NULL if no such object is available. Returned objects are owned by the SSL object and should not be freed by users of these functions.

so like, do not free them, bestie β€” they are not yours to free. the SSL object owns them. periodt. πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

check out these besties too: ssl(7) and SSL_CTX_set_tlsext_status_cb(3). iykyk. 🫢

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>.


mwah πŸ’‹ this has been OpenSSL 3.5.6, dated 2026-04-07 β€” SSL_GET_CERTIFICATE(3ossl), signing off! πŸ¦‹βœ¨

πŸ“¦ where this page comes from