SSL_GET_PEER_CERT_CHAIN(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… SSL_GET_PEER_CERT_CHAIN(3) πŸ’…

okay so bestie, this one's from the Library Functions Manual and it's literally all about peeking at the certificate chain your peer sent you. no cap, it's giving "i just want to see what you brought to the party" energy. let's get into it πŸŽ€


✨ NAME ✨

SSL_get_peer_cert_chain β€” get the X509 certificate chain sent by the peer πŸ¦‹


🌸 SYNOPSIS 🌸

library β€œlibssl” libcrypto
#include <openssl/ssl.h>

STACK_OF(X509) *
SSL_get_peer_cert_chain(const SSL *ssl);

like, that's the whole vibe right there πŸ’–


πŸ’œ DESCRIPTION πŸ’œ

SSL_get_peer_cert_chain() hands you back a pointer to a STACK_OF(X509) of certificates β€” that's the certificate chain of the peer, periodt. πŸ”₯

okay but here's where it gets spicy, so pay attention bestie:

  • if you call it on the client side, the stack also contains the peer's certificate πŸ‘‘
  • if you call it on the server side, you gotta get the peer's certificate separately using SSL_get_peer_certificate(3) πŸ™ˆ
  • and if the peer didn't present a certificate at all? you get NULL. that's it. that's the whole thing. πŸ’€

ngl, the important detail here is that SSL_get_peer_cert_chain() returns the peer chain as sent by the peer: it only consists of certificates the peer has sent (in the order the peer has sent them), and it is not a verified chain. like, it's literally just what they handed over, not a glow-up-approved version ✨

and listen β€” if the session is resumed, peers do not send certificates, so a NULL pointer is returned. 😭 applications can call SSL_session_reused() to determine whether a session is resumed. iykyk 🧚

🚨 huge heads up bestie: the reference count of the STACK_OF(X509) object is not incremented. if the corresponding session is freed, the pointer must not be used any longer. like, do NOT keep using it after the session dips, fr fr πŸ’…

⭐ RETURN VALUES ⭐

the following return values can occur:

  • NULL β€” no certificate was presented by the peer, or no connection was established, or the certificate chain is no longer available when a session is reused. πŸ™ˆ
  • Pointer to a STACK_OF(X509) β€” the return value points to the certificate chain presented by the peer. slay πŸ‘‘

🌈 SEE ALSO 🌈

ssl(3), SSL_get_peer_certificate(3) 🫢


πŸŽ€ HISTORY πŸŽ€

SSL_get_peer_cert_chain() first appeared in SSLeay 0.8.0 and has been available since OpenBSD 2.4. iconic behavior honestly, it's been serving since forever πŸ‘‘


okay that's the whole page bestie, go forth and check those chains πŸ’–βœ¨πŸŒΈ

Deiban, June 8, 2025 β€” mwah, love u, bye! πŸ’…πŸ¦‹

πŸ“¦ where this page comes from