LIBRESSL-SSL_GET_PEER_CERTIFICATE(3)
π SSL_GET_PEER_CERTIFICATE(3) π
ok so bestie, we're in the Library Functions Manual for libssl today and this one's a lil function that hands you the peer's certificate. it's giving "who are you and can I see your ID" energy πͺͺβ¨
πΈ NAME πΈ
SSL_get_peer_certificate β get the X509 certificate of the peer π
β¨ SYNOPSIS β¨
library βlibsslβ libcrypto
#include <openssl/ssl.h>
X509 *
SSL_get_peer_certificate(const SSL *ssl);
that's it. one arg, one return. we love a low-maintenance icon π
π¦ DESCRIPTION π¦
okay so SSL_get_peer_certificate() returns a pointer to the X509 certificate the peer presented. that's the whole vibe. and if the peer did not present a certificate? you get NULL back, bestie. empty hands. no cert. π
now here's the lore β due to the protocol definition, a TLS/SSL server will always send a certificate, if present. periodt. a client though? a client will only send a certificate when it's explicitly requested to do so by the server (peep SSL_CTX_set_verify(3) for that one π). and if an anonymous cipher is being used, no certificates are sent at all. zero. nada. π«₯
β οΈ huge one, don't skip: that a certificate is returned does not indicate anything about the verification state. like, at all. it's just "here's a cert", not "here's a cert I trust". use SSL_get_verify_result(3) to actually check the verification state. ngl this trips people up constantly π
and the reference count tea β β the reference count of the X509 object is incremented by one, so that it will not be destroyed when the session containing the peer certificate is freed. main character survival energy fr fr. but that means the X509 object must be explicitly freed using X509_free(3). it does not clean up after itself, bestie. you gotta do it. π
π RETURN VALUES π
the following return values can occur:
NULLβ no certificate was presented by the peer, or no connection was established. sad girl hours π₯²- Pointer to an
X509certificate β the return value points to the certificate presented by the peer. slay π π
π₯ SEE ALSO π₯
go read those, iykyk πβ¨
π HISTORY π
SSL_get_peer_certificate() appeared in SSLeay 0.4 or earlier and has been available since OpenBSD 2.4. ancient. iconic. still here. π
that's the whole page bestie, go free your X509 objects and verify your peers π
mwah π β this lil rewrite came to you from the Debian build, dated June 8, 2025, and it's the SSL_GET_PEER_CERTIFICATE(3) page. ππ¦β¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000, 2001, 2005 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms