SSL_GET_CERTIFICATE(3ossl)
π SSL_GET_CERTIFICATE π
okay bestie, welcome to SSL_GET_CERTIFICATE(3ossl) β an OpenSSL manual page, but make it a group chat. we're gonna talk about SSL_get_certificate, SSL_get_privatekey, and how to get your hands on the TLS/SSL certificate and private key like the icon you are. no cap, this one's short and sweet. β¨
πΈ NAME πΈ
SSL_get_certificate, SSL_get_privatekey β retrieve TLS/SSL certificate and private key. yes, that's literally the whole job description and they ate. π
π¦ SYNOPSIS π¦
#include <openssl/ssl.h>
X509 *SSL_get_certificate(const SSL *s);
EVP_PKEY *SSL_get_privatekey(const SSL *s);
two functions, one header, zero drama. include <openssl/ssl.h> and you're in. π
π DESCRIPTION π
okay so first up: SSL_get_certificate() hands you back a pointer to an X509 object β that's the certificate being used as the local peer's identity. it's giving "this is me, this is who I am." πͺͺβ¨
here's the tea though: you can have multiple certificates configured at once. like, a server could be serving both an RSA certificate and an ECDSA certificate, because why choose one when you can slay both? π
so which one does SSL_get_certificate() actually return? it depends, bestie, and here's the breakdown:
- if you call it before certificate selection has occurred, it returns the most recently added certificate, or
NULLif no certificate has been added. (so like, the newest one in the lineup gets the spotlight. main character energy by default. π) - after certificate selection has occurred, it returns the certificate that was selected during the handshake, or
NULLif no certificate was selected β for example, on a client where no client certificate is in use. (no cert, no problem, you just getNULL. π)
now, certificate selection happens during the handshake. so if you're calling SSL_get_certificate() inside any callback that fires during the handshake process, what you get back totally depends on whether that callback is made before or after certificate selection occurs. timing is everything, fr fr. β°
and here's a specific little use case that's lowkey iconic: calling SSL_get_certificate() inside a callback set via a call to SSL_CTX_set_tlsext_status_cb(3). that callback happens after certificate selection, so you can use it to peek at a server's chosen certificate β for example, to identify a certificate's OCSP responder URL so that an OCSP response can be obtained. look at you, doing the whole OCSP thing. π
lastly, SSL_get_privatekey() returns a pointer to the EVP_PKEY object corresponding to the certificate returned by SSL_get_certificate() β if any. so it's the certificate's plus-one. π«Ά
π RETURN VALUES π
these functions return pointers to their respective objects, or NULL if no such object is available. simple as that.
β οΈ but listen: the returned objects are owned by theSSLobject, so you should not free them yourself. do not touch. do notfree(). hands off, bestie. that's not your property, that's theSSLobject's property. π«π
π§ SEE ALSO π§
go read those too, iykyk. πβ¨
π 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>.
and that's the whole page, bestie!! π you just read SSL_GET_CERTIFICATE(3ossl) from OpenSSL 3.5.9, dated 2026-09-29 β so if you ever need to cite it, that's the vibe check. now go forth and get those certificates. slay, periodt. πππ
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms